You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mxnet.apache.org by GitBox <gi...@apache.org> on 2018/10/17 23:38:37 UTC

[GitHub] piyushghai commented on a change in pull request #12835: [MXNET-984] Java NDArray Documentation Generation

piyushghai commented on a change in pull request #12835: [MXNET-984] Java NDArray Documentation Generation
URL: https://github.com/apache/incubator-mxnet/pull/12835#discussion_r226128447
 
 

 ##########
 File path: scala-package/macros/src/main/scala/org/apache/mxnet/javaapi/APIDocGenerator.scala
 ##########
 @@ -0,0 +1,159 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.mxnet.javaapi
+
+import java.io._
+import java.security.MessageDigest
+
+import org.apache.mxnet.init.Base._
+import org.apache.mxnet.utils.CToScalaUtils
+
+import scala.collection.mutable.{ArrayBuffer, ListBuffer}
+
+/**
+  * This object will generate the Java documentation of the new Java API
+  * One file namely: NDArrayBase.scala
+  * The code will be executed during Macros stage and file live in Core stage
+  */
+private[mxnet] object APIDocGenerator{
+  case class absClassArg(argName : String, argType : String, argDesc : String, isOptional : Boolean)
+  case class absClassFunction(name : String, desc : String,
+                           listOfArgs: List[absClassArg], returnType : String)
+
+
+  def MD5Generator(input : String) : String = {
+    val md = MessageDigest.getInstance("MD5")
+    md.update(input.getBytes("UTF-8"))
+    val digest = md.digest()
+    org.apache.commons.codec.binary.Base64.encodeBase64URLSafeString(digest)
+  }
+
+  def absClassGen(FILE_PATH : String) : String = {
+    // scalastyle:off
+    // Defines Operators that should not generated
+    val notGenerated = Set("Custom")
+    val absClassFunctions = getSymbolNDArrayMethods()
+    // TODO: Add Filter to the same location in case of refactor
+    val absFuncs = absClassFunctions.filterNot(_.name.startsWith("_"))
+      .filterNot(ele => notGenerated.contains(ele.name))
+      .map(absClassFunction => {
+      val scalaDoc = generateAPIDocFromBackend(absClassFunction)
+      val defBody = generateAPISignature(absClassFunction)
+      s"$scalaDoc\n$defBody"
+    })
+    val packageName = "NDArrayBase"
+    val apacheLicence = "/*\n* Licensed to the Apache Software Foundation (ASF) under one or more\n* contributor license agreements.  See the NOTICE file distributed with\n* this work for additional information regarding copyright ownership.\n* The ASF licenses this file to You under the Apache License, Version 2.0\n* (the \"License\"); you may not use this file except in compliance with\n* the License.  You may obtain a copy of the License at\n*\n*    http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n"
+    val scalaStyle = "// scalastyle:off"
+    val packageDef = "package org.apache.mxnet.javaapi"
+    val imports = "import org.apache.mxnet.annotation.Experimental"
+    val absClassDef = s"abstract class $packageName"
+    val finalStr = s"$apacheLicence\n$scalaStyle\n$packageDef\n$imports\n$absClassDef {\n${absFuncs.mkString("\n")}\n}"
+    val pw = new PrintWriter(new File(FILE_PATH + s"$packageName.scala"))
 
 Review comment:
   Should the extension be .scala ? Or .java ? 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services