lanking520 commented on a change in pull request #12489: [WIP][MXNET-918] 
Symbol Random api
URL: https://github.com/apache/incubator-mxnet/pull/12489#discussion_r217877252
 
 

 ##########
 File path: 
scala-package/macros/src/main/scala/org/apache/mxnet/APIDocGenerator.scala
 ##########
 @@ -52,36 +54,45 @@ private[mxnet] object APIDocGenerator{
     org.apache.commons.codec.binary.Base64.encodeBase64URLSafeString(digest)
   }
 
+  def absRndClassGen(FILE_PATH : String, isSymbol : Boolean) : String = {
+    typeSafeClassGen(
+      getSymbolNDArrayMethods(isSymbol)
+        .filter(f => f.name.startsWith("_random") || 
f.name.startsWith("_sample")),
+      FILE_PATH,
+      if (isSymbol) "SymbolRandomAPIBase" else "NDArrayRandomAPIBase",
+      isSymbol
+    )
+  }
+
   def absClassGen(FILE_PATH : String, isSymbol : Boolean) : String = {
-    // scalastyle:off
-    val absClassFunctions = getSymbolNDArrayMethods(isSymbol)
-    // Defines Operators that should not generated
     val notGenerated = Set("Custom")
-    // TODO: Add Filter to the same location in case of refactor
-    val absFuncs = absClassFunctions.filterNot(_.name.startsWith("_"))
-      .filterNot(ele => notGenerated.contains(ele.name))
+    typeSafeClassGen(
+      getSymbolNDArrayMethods(isSymbol)
+        .filterNot(_.name.startsWith("_"))
+        .filterNot(ele => notGenerated.contains(ele.name)),
+      FILE_PATH,
+      if (isSymbol) "SymbolAPIBase" else "NDArrayAPIBase",
+      isSymbol
+    )
+  }
+
+  def typeSafeClassGen(absClassFunctions: Seq[absClassFunction], FILE_PATH: 
String,
+                       packageName: String, isSymbol: Boolean): String = {
+    val absFuncs = absClassFunctions
       .map(absClassFunction => {
-      val scalaDoc = generateAPIDocFromBackend(absClassFunction)
-      val defBody = generateAPISignature(absClassFunction, isSymbol)
-      s"$scalaDoc\n$defBody"
-    })
-    val packageName = if (isSymbol) "SymbolAPIBase" else "NDArrayAPIBase"
-    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"
-    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"))
-    pw.write(finalStr)
-    pw.close()
-    MD5Generator(finalStr)
+        val scalaDoc = generateAPIDocFromBackend(absClassFunction)
+        val defBody = generateAPISignature(absClassFunction, isSymbol)
+        s"$scalaDoc\n$defBody"
+      })
+    writeFile(FILE_PATH, packageName, absFuncs)
   }
 
   def nonTypeSafeClassGen(FILE_PATH : String, isSymbol : Boolean) : String = {
     // scalastyle:off
     val absClassFunctions = getSymbolNDArrayMethods(isSymbol)
-    val absFuncs = absClassFunctions.map(absClassFunction => {
+    val absFuncs = absClassFunctions
+      .filterNot(_.name.startsWith("_"))
 
 Review comment:
   Good catch!

----------------------------------------------------------------
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:
[email protected]


With regards,
Apache Git Services

Reply via email to