From 46c95f4303d1ef890d532b50641b37d482d6421b Mon Sep 17 00:00:00 2001 From: Qing Date: Tue, 9 Apr 2019 15:08:33 -0700 Subject: [PATCH 1/4] 1st phase scala/java warning killers --- .../main/scala/org/apache/mxnet/Image.scala | 8 ++ .../main/scala/org/apache/mxnet/NDArray.scala | 5 ++ .../org/apache/mxnet/javaapi/Image.scala | 25 ++++++ .../scala/org/apache/mxnet/init/Base.scala | 27 ++++++- .../scala/org/apache/mxnet/init/LibInfo.scala | 30 ++++++++ .../org/apache/mxnet/APIDocGenerator.scala | 69 ++++++++++++++++- .../org/apache/mxnet/GeneratorBase.scala | 77 ++++++++++++++----- .../scala/org/apache/mxnet/NDArrayMacro.scala | 61 ++++++++++++--- .../scala/org/apache/mxnet/SymbolMacro.scala | 58 ++++++++++++-- .../mxnet/javaapi/JavaNDArrayMacro.scala | 15 +++- .../apache/mxnet/utils/CToScalaUtils.scala | 12 ++- .../mxnet/utils/OperatorBuildUtils.scala | 32 -------- 12 files changed, 343 insertions(+), 76 deletions(-) delete mode 100644 scala-package/macros/src/main/scala/org/apache/mxnet/utils/OperatorBuildUtils.scala diff --git a/scala-package/core/src/main/scala/org/apache/mxnet/Image.scala b/scala-package/core/src/main/scala/org/apache/mxnet/Image.scala index 52e26efb41f1..b54ecc05818e 100644 --- a/scala-package/core/src/main/scala/org/apache/mxnet/Image.scala +++ b/scala-package/core/src/main/scala/org/apache/mxnet/Image.scala @@ -38,6 +38,7 @@ object Image { * @param flag Convert decoded image to grayscale (0) or color (1). * @param to_rgb Whether to convert decoded image * to mxnet's default RGB format (instead of opencv's default BGR). + * @param out NDArray to store the output * @return NDArray in HWC format with DType [[DType.UInt8]] */ def imDecode(buf: Array[Byte], flag: Int, @@ -57,6 +58,10 @@ object Image { /** * Same imageDecode with InputStream * @param inputStream the inputStream of the image + * @param flag Convert decoded image to grayscale (0) or color (1). + * @param to_rgb Whether to convert decoded image + * to mxnet's default RGB format (instead of opencv's default BGR). + * @param out NDArray to store the output * @return NDArray in HWC format with DType [[DType.UInt8]] */ def imDecode(inputStream: InputStream, flag: Int = 1, @@ -79,6 +84,7 @@ object Image { * @param flag Convert decoded image to grayscale (0) or color (1). * @param to_rgb Whether to convert decoded image to mxnet's default RGB format * (instead of opencv's default BGR). + * @param out NDArray to store the output * @return org.apache.mxnet.NDArray in HWC format with DType [[DType.UInt8]] */ def imRead(filename: String, flag: Option[Int] = None, @@ -99,6 +105,7 @@ object Image { * @param w Width of resized image. * @param h Height of resized image. * @param interp Interpolation method (default=cv2.INTER_LINEAR). + * @param out NDArray to store the output * @return org.apache.mxnet.NDArray */ def imResize(src: org.apache.mxnet.NDArray, w: Int, h: Int, @@ -124,6 +131,7 @@ object Image { * @param typeOf Filling type (default=cv2.BORDER_CONSTANT). * @param value (Deprecated! Use ``values`` instead.) Fill with single value. * @param values Fill with value(RGB[A] or gray), up to 4 channels. + * @param out NDArray to store the output * @return org.apache.mxnet.NDArray */ def copyMakeBorder(src: org.apache.mxnet.NDArray, top: Int, bot: Int, diff --git a/scala-package/core/src/main/scala/org/apache/mxnet/NDArray.scala b/scala-package/core/src/main/scala/org/apache/mxnet/NDArray.scala index 849f4566f528..3764f5a4a040 100644 --- a/scala-package/core/src/main/scala/org/apache/mxnet/NDArray.scala +++ b/scala-package/core/src/main/scala/org/apache/mxnet/NDArray.scala @@ -36,6 +36,11 @@ import scala.util.Try */ @AddNDArrayFunctions(false) object NDArray extends NDArrayBase { + /** + * method to convert NDArrayFunctionReturn to NDArray + * @param ret the returned NDArray list + * @return NDArray result + */ implicit def getFirstResult(ret: NDArrayFuncReturn): NDArray = ret(0) private val logger = LoggerFactory.getLogger(classOf[NDArray]) diff --git a/scala-package/core/src/main/scala/org/apache/mxnet/javaapi/Image.scala b/scala-package/core/src/main/scala/org/apache/mxnet/javaapi/Image.scala index f72223d1e4da..57a485083f20 100644 --- a/scala-package/core/src/main/scala/org/apache/mxnet/javaapi/Image.scala +++ b/scala-package/core/src/main/scala/org/apache/mxnet/javaapi/Image.scala @@ -36,6 +36,12 @@ object Image { org.apache.mxnet.Image.imDecode(buf, flag, toRGB, None) } + /** + * Decode image with OpenCV. + * Note: return image in RGB by default, instead of OpenCV's default BGR. + * @param buf Buffer containing binary encoded image + * @return NDArray in HWC format with DType [[DType.UInt8]] + */ def imDecode(buf: Array[Byte]): NDArray = { imDecode(buf, 1, true) } @@ -52,6 +58,12 @@ object Image { org.apache.mxnet.Image.imDecode(inputStream, flag, toRGB, None) } + /** + * Same imageDecode with InputStream + * + * @param inputStream the inputStream of the image + * @return NDArray in HWC format with DType [[DType.UInt8]] + */ def imDecode(inputStream: InputStream): NDArray = { imDecode(inputStream, 1, true) } @@ -69,6 +81,12 @@ object Image { org.apache.mxnet.Image.imRead(filename, Some(flag), Some(toRGB), None) } + /** + * Read and decode image with OpenCV. + * Note: return image in RGB by default, instead of OpenCV's default BGR. + * @param filename Name of the image file to be loaded. + * @return org.apache.mxnet.NDArray in HWC format with DType [[DType.UInt8]] + */ def imRead(filename: String): NDArray = { imRead(filename, 1, true) } @@ -86,6 +104,13 @@ object Image { org.apache.mxnet.Image.imResize(src, w, h, interpVal, None) } + /** + * Resize image with OpenCV. + * @param src source image in NDArray + * @param w Width of resized image. + * @param h Height of resized image. + * @return org.apache.mxnet.NDArray + */ def imResize(src: NDArray, w: Int, h: Int): NDArray = { imResize(src, w, h, null) } diff --git a/scala-package/init/src/main/scala/org/apache/mxnet/init/Base.scala b/scala-package/init/src/main/scala/org/apache/mxnet/init/Base.scala index b5a6286af1b6..3630e074b3f3 100644 --- a/scala-package/init/src/main/scala/org/apache/mxnet/init/Base.scala +++ b/scala-package/init/src/main/scala/org/apache/mxnet/init/Base.scala @@ -29,17 +29,41 @@ object Base { class RefFloat(val value: Float = 0) class RefString(val value: String = null) + /** + * This C Pointer Address point to the + * actual memory piece created in MXNet Engine + */ type CPtrAddress = Long + /** + * NDArrayHandle is the C pointer to + * the NDArray + */ type NDArrayHandle = CPtrAddress + /** + * FunctionHandle is the C pointer to + * the ids of the operators + */ type FunctionHandle = CPtrAddress + /** + * KVStorHandle is the C pointer to + * the KVStore + */ type KVStoreHandle = CPtrAddress + /** + * ExecutorHandle is the C pointer to + * the Executor + */ type ExecutorHandle = CPtrAddress + /** + * SymbolHandle is the C pointer to + * the Symbol + */ type SymbolHandle = CPtrAddress @throws(classOf[UnsatisfiedLinkError]) private def tryLoadInitLibrary(): Unit = { - var userDir : File = new File(System.getProperty("user.dir")) + val userDir : File = new File(System.getProperty("user.dir")) var nativeDir : File = new File(userDir, "init-native") if (!nativeDir.exists()) { nativeDir = new File(userDir.getParent, "init-native") @@ -50,7 +74,6 @@ object Base { val baseDir = nativeDir.getAbsolutePath val os = System.getProperty("os.name") - // ref: http://lopica.sourceforge.net/os.html if (os.startsWith("Linux")) { System.load(s"$baseDir/target/libmxnet-init-scala.so") } else if (os.startsWith("Mac")) { diff --git a/scala-package/init/src/main/scala/org/apache/mxnet/init/LibInfo.scala b/scala-package/init/src/main/scala/org/apache/mxnet/init/LibInfo.scala index 7bd0c701f872..9c5735d3bbe5 100644 --- a/scala-package/init/src/main/scala/org/apache/mxnet/init/LibInfo.scala +++ b/scala-package/init/src/main/scala/org/apache/mxnet/init/LibInfo.scala @@ -22,7 +22,25 @@ import org.apache.mxnet.init.Base._ import scala.collection.mutable.ListBuffer class LibInfo { + /** + * Get the list of the symbol ids + * @param symbolList pass in an empty ListBuffer and obtain a list of operator ids + * @return callback result + */ @native def mxSymbolListAtomicSymbolCreators(symbolList: ListBuffer[SymbolHandle]): Int + + /** + * Get the detailed information of an operator + * @param handle The id of the operator + * @param name name of the operator + * @param desc description of the operator + * @param numArgs number of arguments + * @param argNames argument names + * @param argTypes argument types + * @param argDescs argument descriptions + * @param keyVarNumArgs Kwargs number + * @return callback result + */ @native def mxSymbolGetAtomicSymbolInfo(handle: SymbolHandle, name: RefString, desc: RefString, @@ -31,6 +49,18 @@ class LibInfo { argTypes: ListBuffer[String], argDescs: ListBuffer[String], keyVarNumArgs: RefString): Int + /** + * Get the name list of all operators + * @param names names of all operators + * @return callback result + */ @native def mxListAllOpNames(names: ListBuffer[String]): Int + + /** + * get operator id from its name + * @param opName Operator name + * @param opHandle Operator id + * @return callback result + */ @native def nnGetOpHandle(opName: String, opHandle: RefLong): Int } diff --git a/scala-package/macros/src/main/scala/org/apache/mxnet/APIDocGenerator.scala b/scala-package/macros/src/main/scala/org/apache/mxnet/APIDocGenerator.scala index ede16f73d2a1..36c0b47433fa 100644 --- a/scala-package/macros/src/main/scala/org/apache/mxnet/APIDocGenerator.scala +++ b/scala-package/macros/src/main/scala/org/apache/mxnet/APIDocGenerator.scala @@ -23,12 +23,16 @@ import java.security.MessageDigest import scala.collection.mutable.ListBuffer /** - * This object will generate the Scala documentation of the new Scala API - * Two file namely: SymbolAPIBase.scala and NDArrayAPIBase.scala + * This object will generate the Scala documentation of the Scala/Java APIs * The code will be executed during Macros stage and file live in Core stage */ private[mxnet] object APIDocGenerator extends GeneratorBase with RandomHelpers { + /** + * main method used to generate code and write to files + * a hash check placed at the end to verify changes + * @param args input args + */ def main(args: Array[String]): Unit = { val FILE_PATH = args(0) val hashCollector = ListBuffer[String]() @@ -42,6 +46,12 @@ private[mxnet] object APIDocGenerator extends GeneratorBase with RandomHelpers { val finalHash = hashCollector.mkString("\n") } + /** + * generate MD5 result from an input string + * encoded in UTF-8 + * @param input the input string + * @return a MD5 value from the string + */ def MD5Generator(input: String): String = { val md = MessageDigest.getInstance("MD5") md.update(input.getBytes("UTF-8")) @@ -49,6 +59,12 @@ private[mxnet] object APIDocGenerator extends GeneratorBase with RandomHelpers { org.apache.commons.codec.binary.Base64.encodeBase64URLSafeString(digest) } + /** + * Type-safe class body generation for NDArray/Symbol + * @param FILE_PATH file path write the file to + * @param isSymbol check if write the Symbol API, NDArray otherwise + * @return MD5 String + */ def typeSafeClassGen(FILE_PATH: String, isSymbol: Boolean): String = { val generated = typeSafeFunctionsToGenerate(isSymbol, isContrib = false) .map { func => @@ -65,6 +81,12 @@ private[mxnet] object APIDocGenerator extends GeneratorBase with RandomHelpers { generated) } + /** + * Generate the Random classes for Symbol/NDArray + * @param FILE_PATH file path write the file to + * @param isSymbol check if write the Symbol API, NDArray otherwise + * @return MD5 String + */ def typeSafeRandomClassGen(FILE_PATH: String, isSymbol: Boolean): String = { val generated = typeSafeRandomFunctionsToGenerate(isSymbol) .map { func => @@ -83,6 +105,12 @@ private[mxnet] object APIDocGenerator extends GeneratorBase with RandomHelpers { generated) } + /** + * Non Type-safe interface of Scala Symbol/NDArray + * @param FILE_PATH file path write the file to + * @param isSymbol check if write the Symbol API, NDArray otherwise + * @return MD5 String + */ def nonTypeSafeClassGen(FILE_PATH: String, isSymbol: Boolean): String = { val absFuncs = functionsToGenerate(isSymbol, isContrib = false) .map { func => @@ -112,7 +140,12 @@ private[mxnet] object APIDocGenerator extends GeneratorBase with RandomHelpers { absFuncs) } - def javaClassGen(filePath : String) : String = { + /** + * Type-safe interface of Java NDArray + * @param FILE_PATH file path write the file to + * @return MD5 String + */ + def javaClassGen(FILE_PATH : String) : String = { val notGenerated = Set("Custom") val absClassFunctions = functionsToGenerate(false, false, true) val absFuncs = absClassFunctions.filterNot(ele => notGenerated.contains(ele.name)) @@ -133,13 +166,19 @@ private[mxnet] object APIDocGenerator extends GeneratorBase with RandomHelpers { val packageName = "NDArrayBase" val packageDef = "package org.apache.mxnet.javaapi" writeFile( - filePath + "javaapi/", + FILE_PATH + "javaapi/", packageDef, packageName, "import org.apache.mxnet.annotation.Experimental", absFuncs) } + /** + * Generate Scala docs from the function description + * @param func the Function case class + * @param withParam whether to generate param field + * @return a formatted string for the function description + */ def generateAPIDocFromBackend(func: Func, withParam: Boolean = true): String = { def fixDesc(desc: String): String = { var curDesc = desc @@ -173,6 +212,14 @@ private[mxnet] object APIDocGenerator extends GeneratorBase with RandomHelpers { } } + /** + * generate the function interface + * e.g: def softmax(data: NDArray, name ...): NDArrayFunctionReturn + * @param func the Function case class + * @param isSymbol check if generate Symbol function, NDArray otherwise + * @param typeParameter type param specifically used in Random Module + * @return formatted string for the function + */ def generateAPISignature(func: Func, isSymbol: Boolean, typeParameter: String = ""): String = { val argDef = ListBuffer[String]() @@ -192,6 +239,11 @@ private[mxnet] object APIDocGenerator extends GeneratorBase with RandomHelpers { |def ${func.name}$typeParameter (${argDef.mkString(", ")}): $returnType""".stripMargin } + /** + * Generate Java function interface + * @param func the Function case class + * @return a formatted string for the function + */ def generateJavaAPISignature(func : Func) : String = { val useParamObject = func.listOfArgs.count(arg => arg.isOptional) >= 2 var argDef = ListBuffer[String]() @@ -250,6 +302,15 @@ private[mxnet] object APIDocGenerator extends GeneratorBase with RandomHelpers { } } + /** + * Write the formatted string to file + * @param FILE_PATH location of the file writes to + * @param packageDef package definition + * @param className class name + * @param imports packages need to import + * @param absFuncs all formatted functions + * @return a MD5 string + */ def writeFile(FILE_PATH: String, packageDef: String, className: String, imports: String, absFuncs: Seq[String]): String = { diff --git a/scala-package/macros/src/main/scala/org/apache/mxnet/GeneratorBase.scala b/scala-package/macros/src/main/scala/org/apache/mxnet/GeneratorBase.scala index b2033f529c65..5742c044521c 100644 --- a/scala-package/macros/src/main/scala/org/apache/mxnet/GeneratorBase.scala +++ b/scala-package/macros/src/main/scala/org/apache/mxnet/GeneratorBase.scala @@ -17,16 +17,20 @@ package org.apache.mxnet -import org.apache.mxnet.init.Base.{RefInt, RefLong, RefString, _LIB} -import org.apache.mxnet.utils.{CToScalaUtils, OperatorBuildUtils} +import org.apache.mxnet.init.Base.{CPtrAddress, RefInt, RefLong, RefString, _LIB} +import org.apache.mxnet.utils.CToScalaUtils import scala.collection.mutable.ListBuffer import scala.reflect.macros.blackbox private[mxnet] abstract class GeneratorBase { - type Handle = Long case class Arg(argName: String, argType: String, argDesc: String, isOptional: Boolean) { + /** + * filter the arg name with the Scala keyword + * var and type + * @return argname that works in Scala + */ def safeArgName: String = argName match { case "var" => "vari" case "type" => "typeOf" @@ -36,6 +40,14 @@ private[mxnet] abstract class GeneratorBase { case class Func(name: String, desc: String, listOfArgs: List[Arg], returnType: String) + /** + * Non Type-safe function generation method + * this method will filter all "_" functions + * @param isSymbol check if generate the Symbol method + * @param isContrib check if generate the contrib method + * @param isJava check if generate Corresponding Java method + * @return List of functions + */ def functionsToGenerate(isSymbol: Boolean, isContrib: Boolean, isJava: Boolean = false): List[Func] = { val l = getBackEndFunctions(isSymbol, isJava) @@ -46,7 +58,12 @@ private[mxnet] abstract class GeneratorBase { } } - // filter the operators to generate in the type-safe Symbol.api and NDArray.api + /** + * filter the operators to generate in the type-safe Symbol.api and NDArray.api + * @param isSymbol check if generate the Symbol method + * @param isContrib check if generate the contrib method + * @return List of functions + */ protected def typeSafeFunctionsToGenerate(isSymbol: Boolean, isContrib: Boolean): List[Func] = { // Operators that should not be generated val notGenerated = Set("Custom") @@ -60,6 +77,12 @@ private[mxnet] abstract class GeneratorBase { res.filterNot(ele => notGenerated.contains(ele.name)) } + /** + * Extract and format the functions obtained from C API + * @param isSymbol check if generate for Symbol + * @param isJava check if extracting in Java format + * @return List of functions + */ protected def getBackEndFunctions(isSymbol: Boolean, isJava: Boolean = false): List[Func] = { val opNames = ListBuffer.empty[String] _LIB.mxListAllOpNames(opNames) @@ -70,7 +93,7 @@ private[mxnet] abstract class GeneratorBase { }).toList } - private def makeAtomicFunction(handle: Handle, aliasName: String, + private def makeAtomicFunction(handle: CPtrAddress, aliasName: String, isSymbol: Boolean, isJava: Boolean): Func = { val name = new RefString val desc = new RefString @@ -82,14 +105,11 @@ private[mxnet] abstract class GeneratorBase { _LIB.mxSymbolGetAtomicSymbolInfo( handle, name, desc, numArgs, argNames, argTypes, argDescs, keyVarNumArgs) - val paramStr = OperatorBuildUtils.ctypes2docstring(argNames, argTypes, argDescs) val extraDoc: String = if (keyVarNumArgs.value != null && keyVarNumArgs.value.length > 0) { s"This function support variable length of positional input (${keyVarNumArgs.value})." } else { "" } - val realName = if (aliasName == name.value) "" else s"(a.k.a., ${name.value})" - val docStr = s"$aliasName $realName\n${desc.value}\n\n$paramStr\n$extraDoc\n" val argList = argNames zip argTypes zip argDescs map { case ((argName, argType), argDesc) => val family = if (isJava) "org.apache.mxnet.javaapi.NDArray" @@ -109,10 +129,10 @@ private[mxnet] abstract class GeneratorBase { /** * Generate class structure for all function APIs * - * @param c + * @param c Context used for generation * @param funcDef DefDef type of function definitions - * @param annottees - * @return + * @param annottees annottees used to define Class or Module + * @return Expr used for code generation */ protected def structGeneration(c: blackbox.Context) (funcDef: List[c.universe.DefDef], annottees: c.Expr[Any]*) @@ -145,7 +165,11 @@ private[mxnet] abstract class GeneratorBase { result } - // build function argument definition, with optionality, and safe names + /** + * build function argument definition, with optionality, and safe names + * @param func functions + * @return List of string representing the functions interface + */ protected def typedFunctionCommonArgDef(func: Func): List[String] = { func.listOfArgs.map(arg => if (arg.isOptional) { @@ -167,14 +191,23 @@ private[mxnet] abstract class GeneratorBase { private[mxnet] trait RandomHelpers { self: GeneratorBase => - // a generic type spec used in Symbol.random and NDArray.random modules +/** + * a generic type spec used in Symbol.random and NDArray.random modules + * @param isSymbol check if generate for Symbol + * @param fullPackageSpec check if leave the full name of the classTag + * @return a formatted string for random Symbol/NDArray + */ protected def randomGenericTypeSpec(isSymbol: Boolean, fullPackageSpec: Boolean): String = { val classTag = if (fullPackageSpec) "scala.reflect.ClassTag" else "ClassTag" if (isSymbol) s"[T: SymbolOrScalar : $classTag]" else s"[T: NDArrayOrScalar : $classTag]" } - // filter the operators to generate in the type-safe Symbol.random and NDArray.random +/** + * filter the operators to generate in the type-safe Symbol.random and NDArray.random + * @param isSymbol check if generate Symbol functions + * @return List of functions + */ protected def typeSafeRandomFunctionsToGenerate(isSymbol: Boolean): List[Func] = { getBackEndFunctions(isSymbol) .filter(f => f.name.startsWith("_sample_") || f.name.startsWith("_random_")) @@ -206,16 +239,24 @@ private[mxnet] trait RandomHelpers { ) } - // hacks to manage the fact that random_normal and sample_normal have - // non-consistent parameter naming in the back-end - // this first one, merge loc/scale and mu/sigma + /** + * hacks to manage the fact that random_normal and sample_normal have + * non-consistent parameter naming in the back-end + * this first one, merge loc/scale and mu/sigma + * @param arg argument need to modify + * @return Arg case class with clean arg names + */ protected def hackNormalFunc(arg: Arg): Arg = { if (arg.argName == "loc") arg.copy(argName = "mu") else if (arg.argName == "scale") arg.copy(argName = "sigma") else arg } - // this second one reverts this merge prior to back-end call + /** + * this second one reverts this merge prior to back-end call + * @param func function case class + * @return a string contains the implementation of random args + */ protected def unhackNormalFunc(func: Func): String = { if (func.name.equals("normal")) { s"""if(target.equals("random_normal")) { diff --git a/scala-package/macros/src/main/scala/org/apache/mxnet/NDArrayMacro.scala b/scala-package/macros/src/main/scala/org/apache/mxnet/NDArrayMacro.scala index f5b8bce11cf5..8ac71fb91d71 100644 --- a/scala-package/macros/src/main/scala/org/apache/mxnet/NDArrayMacro.scala +++ b/scala-package/macros/src/main/scala/org/apache/mxnet/NDArrayMacro.scala @@ -22,16 +22,30 @@ import scala.language.experimental.macros import scala.reflect.macros.blackbox private[mxnet] class AddNDArrayFunctions(isContrib: Boolean) extends StaticAnnotation { - private[mxnet] def macroTransform(annottees: Any*): Any = macro NDArrayMacro.addDefs +/** + * generate non-typesafe method for NDArray operations + * @param annottees annottees used to define Class or Module + * @return generated code for injection + */ + private[mxnet] def macroTransform(annottees: Any*) = macro NDArrayMacro.addDefs } private[mxnet] class AddNDArrayAPIs(isContrib: Boolean) extends StaticAnnotation { - private[mxnet] def macroTransform(annottees: Any*): Any = - macro TypedNDArrayAPIMacro.typeSafeAPIDefs +/** + * generate typesafe method for NDArray operations + * @param annottees annottees used to define Class or Module + * @return generated code for injection + */ + private[mxnet] def macroTransform(annottees: Any*) = macro TypedNDArrayAPIMacro.typeSafeAPIDefs } private[mxnet] class AddNDArrayRandomAPIs(isContrib: Boolean) extends StaticAnnotation { - private[mxnet] def macroTransform(annottees: Any*): Any = +/** + * generate typesafe method for Random Symbol + * @param annottees annottees used to define Class or Module + * @return generated code for injection + */ + private[mxnet] def macroTransform(annottees: Any*) = macro TypedNDArrayRandomAPIMacro.typeSafeAPIDefs } @@ -39,8 +53,13 @@ private[mxnet] class AddNDArrayRandomAPIs(isContrib: Boolean) extends StaticAnno * For non-typed NDArray API */ private[mxnet] object NDArrayMacro extends GeneratorBase { - - def addDefs(c: blackbox.Context)(annottees: c.Expr[Any]*): c.Expr[Nothing] = { + /** + * methods that check the isContrib and call code generation + * @param c Context used for code gen + * @param annottees annottees used to define Class or Module + * @return generated code for injection + */ + def addDefs(c: blackbox.Context)(annottees: c.Expr[Any]*): c.Expr[Any] = { import c.universe._ val isContrib: Boolean = c.prefix.tree match { case q"new AddNDArrayFunctions($b)" => c.eval[Boolean](c.Expr(b)) @@ -82,8 +101,13 @@ private[mxnet] object NDArrayMacro extends GeneratorBase { * NDArray.api code generation */ private[mxnet] object TypedNDArrayAPIMacro extends GeneratorBase { - - def typeSafeAPIDefs(c: blackbox.Context)(annottees: c.Expr[Any]*): c.Expr[Nothing] = { + /** + * methods that check the isContrib and call code generation + * @param c Context used for code gen + * @param annottees annottees used to define Class or Module + * @return generated code for injection + */ + def typeSafeAPIDefs(c: blackbox.Context)(annottees: c.Expr[Any]*): c.Expr[Any] = { import c.universe._ val isContrib: Boolean = c.prefix.tree match { case q"new AddNDArrayAPIs($b)" => c.eval[Boolean](c.Expr(b)) @@ -95,6 +119,12 @@ private[mxnet] object TypedNDArrayAPIMacro extends GeneratorBase { structGeneration(c)(functionDefs, annottees: _*) } + /** + * methods that construct the code and build the syntax tree + * @param c Context used for code gen + * @param function case class that store all information of the single function + * @return generated syntax tree + */ protected def buildTypedFunction(c: blackbox.Context) (function: Func): c.universe.DefDef = { import c.universe._ @@ -148,8 +178,13 @@ private[mxnet] object TypedNDArrayAPIMacro extends GeneratorBase { */ private[mxnet] object TypedNDArrayRandomAPIMacro extends GeneratorBase with RandomHelpers { - - def typeSafeAPIDefs(c: blackbox.Context)(annottees: c.Expr[Any]*): c.Expr[Nothing] = { + /** + * methods that check the isContrib and call code generation + * @param c Context used for code gen + * @param annottees annottees used to define Class or Module + * @return generated code for injection + */ + def typeSafeAPIDefs(c: blackbox.Context)(annottees: c.Expr[Any]*): c.Expr[Any] = { // Note: no contrib managed in this module val functionDefs = typeSafeRandomFunctionsToGenerate(isSymbol = false) @@ -158,6 +193,12 @@ private[mxnet] object TypedNDArrayRandomAPIMacro extends GeneratorBase structGeneration(c)(functionDefs, annottees: _*) } + /** + * methods that construct the code and build the syntax tree + * @param c Context used for code gen + * @param function case class that store all information of the single function + * @return generated syntax tree + */ protected def buildTypedFunction(c: blackbox.Context) (function: Func): c.universe.DefDef = { import c.universe._ diff --git a/scala-package/macros/src/main/scala/org/apache/mxnet/SymbolMacro.scala b/scala-package/macros/src/main/scala/org/apache/mxnet/SymbolMacro.scala index 06b567c3d2d4..99c0bbc99bb5 100644 --- a/scala-package/macros/src/main/scala/org/apache/mxnet/SymbolMacro.scala +++ b/scala-package/macros/src/main/scala/org/apache/mxnet/SymbolMacro.scala @@ -23,16 +23,30 @@ import scala.language.experimental.macros import scala.reflect.macros.blackbox private[mxnet] class AddSymbolFunctions(isContrib: Boolean) extends StaticAnnotation { - private[mxnet] def macroTransform(annottees: Any*): Any = macro SymbolMacro.addDefs +/** + * generate non-typesafe method for Symbol operations + * @param annottees annottees used to define Class or Module + * @return generated code for injection + */ + private[mxnet] def macroTransform(annottees: Any*) = macro SymbolMacro.addDefs } private[mxnet] class AddSymbolAPIs(isContrib: Boolean) extends StaticAnnotation { - private[mxnet] def macroTransform(annottees: Any*): Any = - macro TypedSymbolAPIMacro.typeSafeAPIDefs +/** + * generate typesafe method for Symbol + * @param annottees annottees used to define Class or Module + * @return generated code for injection + */ + private[mxnet] def macroTransform(annottees: Any*) = macro TypedSymbolAPIMacro.typeSafeAPIDefs } private[mxnet] class AddSymbolRandomAPIs(isContrib: Boolean) extends StaticAnnotation { - private[mxnet] def macroTransform(annottees: Any*): Any = +/** + * generate typesafe method for Random Symbol + * @param annottees annottees used to define Class or Module + * @return generated code for injection + */ + private[mxnet] def macroTransform(annottees: Any*) = macro TypedSymbolRandomAPIMacro.typeSafeAPIDefs } @@ -41,7 +55,13 @@ private[mxnet] class AddSymbolRandomAPIs(isContrib: Boolean) extends StaticAnnot */ private[mxnet] object SymbolMacro extends GeneratorBase { - def addDefs(c: blackbox.Context)(annottees: c.Expr[Any]*): c.Expr[Nothing] = { + /** + * methods that check the isContrib and call code generation + * @param c Context used for code gen + * @param annottees annottees used to define Class or Module + * @return generated code for injection + */ + def addDefs(c: blackbox.Context)(annottees: c.Expr[Any]*): c.Expr[Any] = { import c.universe._ val isContrib: Boolean = c.prefix.tree match { case q"new AddSymbolFunctions($b)" => c.eval[Boolean](c.Expr(b)) @@ -77,7 +97,13 @@ private[mxnet] object SymbolMacro extends GeneratorBase { */ private[mxnet] object TypedSymbolAPIMacro extends GeneratorBase { - def typeSafeAPIDefs(c: blackbox.Context)(annottees: c.Expr[Any]*): c.Expr[Nothing] = { + /** + * methods that check the isContrib and call code generation + * @param c Context used for code gen + * @param annottees annottees used to define Class or Module + * @return generated code for injection + */ + def typeSafeAPIDefs(c: blackbox.Context)(annottees: c.Expr[Any]*): c.Expr[Any] = { import c.universe._ val isContrib: Boolean = c.prefix.tree match { case q"new AddSymbolAPIs($b)" => c.eval[Boolean](c.Expr(b)) @@ -89,6 +115,12 @@ private[mxnet] object TypedSymbolAPIMacro extends GeneratorBase { structGeneration(c)(functionDefs, annottees: _*) } + /** + * methods that construct the code and build the syntax tree + * @param c Context used for code gen + * @param function case class that store all information of the single function + * @return generated syntax tree + */ protected def buildTypedFunction(c: blackbox.Context) (function: Func): c.universe.DefDef = { import c.universe._ @@ -141,13 +173,25 @@ private[mxnet] object TypedSymbolAPIMacro extends GeneratorBase { private[mxnet] object TypedSymbolRandomAPIMacro extends GeneratorBase with RandomHelpers { - def typeSafeAPIDefs(c: blackbox.Context)(annottees: c.Expr[Any]*): c.Expr[Nothing] = { + /** + * methods that check the isContrib and call code generation + * @param c Context used for code gen + * @param annottees annottees used to define Class or Module + * @return generated code for injection + */ + def typeSafeAPIDefs(c: blackbox.Context)(annottees: c.Expr[Any]*): c.Expr[Any] = { val functionDefs = typeSafeRandomFunctionsToGenerate(isSymbol = true) .map(f => buildTypedFunction(c)(f)) structGeneration(c)(functionDefs, annottees: _*) } + /** + * methods that construct the code and build the syntax tree + * @param c Context used for code gen + * @param function case class that store all information of the single function + * @return generated syntax tree + */ protected def buildTypedFunction(c: blackbox.Context) (function: Func): c.universe.DefDef = { import c.universe._ diff --git a/scala-package/macros/src/main/scala/org/apache/mxnet/javaapi/JavaNDArrayMacro.scala b/scala-package/macros/src/main/scala/org/apache/mxnet/javaapi/JavaNDArrayMacro.scala index 9bf0818c14a4..6ac7b58e1cfc 100644 --- a/scala-package/macros/src/main/scala/org/apache/mxnet/javaapi/JavaNDArrayMacro.scala +++ b/scala-package/macros/src/main/scala/org/apache/mxnet/javaapi/JavaNDArrayMacro.scala @@ -25,12 +25,23 @@ import scala.language.experimental.macros import scala.reflect.macros.blackbox private[mxnet] class AddJNDArrayAPIs(isContrib: Boolean) extends StaticAnnotation { - private[mxnet] def macroTransform(annottees: Any*): Any = macro JavaNDArrayMacro.typeSafeAPIDefs +/** + * generate typesafe method for Java NDArray operations + * @param annottees annottees used to define Class or Module + * @return generated code for injection + */ + private[mxnet] def macroTransform(annottees: Any*) = macro JavaNDArrayMacro.typeSafeAPIDefs } private[mxnet] object JavaNDArrayMacro extends GeneratorBase { - def typeSafeAPIDefs(c: blackbox.Context)(annottees: c.Expr[Any]*): c.Expr[Nothing] = { + /** + * methods that call code generation + * @param c Context used for code gen + * @param annottees annottees used to define Class or Module + * @return generated code for injection + */ + def typeSafeAPIDefs(c: blackbox.Context)(annottees: c.Expr[Any]*) : c.Expr[Any] = { typeSafeAPIImpl(c)(annottees: _*) } diff --git a/scala-package/macros/src/main/scala/org/apache/mxnet/utils/CToScalaUtils.scala b/scala-package/macros/src/main/scala/org/apache/mxnet/utils/CToScalaUtils.scala index 12d797f9b100..d82dd6aca005 100644 --- a/scala-package/macros/src/main/scala/org/apache/mxnet/utils/CToScalaUtils.scala +++ b/scala-package/macros/src/main/scala/org/apache/mxnet/utils/CToScalaUtils.scala @@ -31,7 +31,15 @@ private[mxnet] object CToScalaUtils { "double" -> "Double", "bool" -> "Boolean") - // Convert C++ Types to Scala Types + /** + * Convert C++ Types to Scala Types + * @param in input raw string that contains C type docs + * @param argType arg type that used for error messaging + * @param argName arg name used for error messaging + * @param returnType the type that NDArray/Symbol should be + * @param isJava check if generating for Java + * @return String that contains right Scala/Java types + */ def typeConversion(in : String, argType : String = "", argName : String, returnType : String, isJava : Boolean) : String = { val header = returnType.split("\\.").dropRight(1) @@ -64,6 +72,8 @@ private[mxnet] object CToScalaUtils { * optional, what is it Scala type and possibly pass in a default value * @param argName The name of the argument * @param argType Raw arguement Type description + * @param returnType return type of the function (Symbol/NDArray) + * @param isJava check if Java args should be generated * @return (Scala_Type, isOptional) */ def argumentCleaner(argName: String, argType : String, diff --git a/scala-package/macros/src/main/scala/org/apache/mxnet/utils/OperatorBuildUtils.scala b/scala-package/macros/src/main/scala/org/apache/mxnet/utils/OperatorBuildUtils.scala deleted file mode 100644 index 383c68c0fb10..000000000000 --- a/scala-package/macros/src/main/scala/org/apache/mxnet/utils/OperatorBuildUtils.scala +++ /dev/null @@ -1,32 +0,0 @@ -/* - * 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.utils - -private[mxnet] object OperatorBuildUtils { - // Convert ctypes returned doc string information into parameters docstring. - def ctypes2docstring(argNames: Seq[String], - argTypes: Seq[String], - argDescs: Seq[String]): String = { - val params = - (argNames zip argTypes zip argDescs) map { case ((argName, argType), argDesc) => - val desc = if (argDesc.isEmpty) "" else s"\n$argDesc" - s"$argName : $argType$desc" - } - s"Parameters\n----------\n${params.mkString("\n")}\n" - } -} From 029227234f7f68550991dd4015cb18c5a34805d2 Mon Sep 17 00:00:00 2001 From: Qing Date: Thu, 11 Apr 2019 17:02:48 -0700 Subject: [PATCH 2/4] add more comments --- .../src/main/scala/org/apache/mxnet/APIDocGenerator.scala | 4 ++++ .../src/main/scala/org/apache/mxnet/GeneratorBase.scala | 4 ++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/scala-package/macros/src/main/scala/org/apache/mxnet/APIDocGenerator.scala b/scala-package/macros/src/main/scala/org/apache/mxnet/APIDocGenerator.scala index 36c0b47433fa..4530c2a21bee 100644 --- a/scala-package/macros/src/main/scala/org/apache/mxnet/APIDocGenerator.scala +++ b/scala-package/macros/src/main/scala/org/apache/mxnet/APIDocGenerator.scala @@ -107,6 +107,10 @@ private[mxnet] object APIDocGenerator extends GeneratorBase with RandomHelpers { /** * Non Type-safe interface of Scala Symbol/NDArray + * It includes class definition : e.g class SymbolBase + * and function definitions : e.g def softmax(...)(...)(...) : NDArray + * Users can directly use the api by calling NDArray. + * It support both positional input or Map input * @param FILE_PATH file path write the file to * @param isSymbol check if write the Symbol API, NDArray otherwise * @return MD5 String diff --git a/scala-package/macros/src/main/scala/org/apache/mxnet/GeneratorBase.scala b/scala-package/macros/src/main/scala/org/apache/mxnet/GeneratorBase.scala index 5742c044521c..35e3cbe6a32e 100644 --- a/scala-package/macros/src/main/scala/org/apache/mxnet/GeneratorBase.scala +++ b/scala-package/macros/src/main/scala/org/apache/mxnet/GeneratorBase.scala @@ -27,8 +27,8 @@ private[mxnet] abstract class GeneratorBase { case class Arg(argName: String, argType: String, argDesc: String, isOptional: Boolean) { /** - * filter the arg name with the Scala keyword - * var and type + * filter the arg name with the Scala keyword that are not allow to use as arg name + * such as var and type listed in here. This is due to the diff between C and Scala * @return argname that works in Scala */ def safeArgName: String = argName match { From 387edcc39747bb54428fbf1d8d9fe4c850515cb9 Mon Sep 17 00:00:00 2001 From: Qing Date: Wed, 17 Apr 2019 15:21:41 -0700 Subject: [PATCH 3/4] Capitialize all starting words of comments --- .../scala/org/apache/mxnet/init/Base.scala | 2 +- .../org/apache/mxnet/APIDocGenerator.scala | 60 +++++++++---------- .../org/apache/mxnet/GeneratorBase.scala | 48 +++++++-------- .../scala/org/apache/mxnet/NDArrayMacro.scala | 42 ++++++------- .../scala/org/apache/mxnet/SymbolMacro.scala | 48 +++++++-------- .../mxnet/javaapi/JavaNDArrayMacro.scala | 12 ++-- .../apache/mxnet/utils/CToScalaUtils.scala | 14 ++--- 7 files changed, 113 insertions(+), 113 deletions(-) diff --git a/scala-package/init/src/main/scala/org/apache/mxnet/init/Base.scala b/scala-package/init/src/main/scala/org/apache/mxnet/init/Base.scala index 3630e074b3f3..e3fa28fb2a59 100644 --- a/scala-package/init/src/main/scala/org/apache/mxnet/init/Base.scala +++ b/scala-package/init/src/main/scala/org/apache/mxnet/init/Base.scala @@ -46,7 +46,7 @@ object Base { */ type FunctionHandle = CPtrAddress /** - * KVStorHandle is the C pointer to + * KVStoreHandle is the C pointer to * the KVStore */ type KVStoreHandle = CPtrAddress diff --git a/scala-package/macros/src/main/scala/org/apache/mxnet/APIDocGenerator.scala b/scala-package/macros/src/main/scala/org/apache/mxnet/APIDocGenerator.scala index 4530c2a21bee..a5102d6624ef 100644 --- a/scala-package/macros/src/main/scala/org/apache/mxnet/APIDocGenerator.scala +++ b/scala-package/macros/src/main/scala/org/apache/mxnet/APIDocGenerator.scala @@ -29,9 +29,9 @@ import scala.collection.mutable.ListBuffer private[mxnet] object APIDocGenerator extends GeneratorBase with RandomHelpers { /** - * main method used to generate code and write to files - * a hash check placed at the end to verify changes - * @param args input args + * Main method used to generate code and write to files + * A hash check placed at the end to verify changes + * @param args Input args */ def main(args: Array[String]): Unit = { val FILE_PATH = args(0) @@ -47,10 +47,10 @@ private[mxnet] object APIDocGenerator extends GeneratorBase with RandomHelpers { } /** - * generate MD5 result from an input string - * encoded in UTF-8 - * @param input the input string - * @return a MD5 value from the string + * Generate MD5 result from an input string + * Encoded in UTF-8 + * @param input The input string + * @return A MD5 value from the string */ def MD5Generator(input: String): String = { val md = MessageDigest.getInstance("MD5") @@ -61,8 +61,8 @@ private[mxnet] object APIDocGenerator extends GeneratorBase with RandomHelpers { /** * Type-safe class body generation for NDArray/Symbol - * @param FILE_PATH file path write the file to - * @param isSymbol check if write the Symbol API, NDArray otherwise + * @param FILE_PATH File path write the file to + * @param isSymbol Check if write the Symbol API, NDArray otherwise * @return MD5 String */ def typeSafeClassGen(FILE_PATH: String, isSymbol: Boolean): String = { @@ -83,8 +83,8 @@ private[mxnet] object APIDocGenerator extends GeneratorBase with RandomHelpers { /** * Generate the Random classes for Symbol/NDArray - * @param FILE_PATH file path write the file to - * @param isSymbol check if write the Symbol API, NDArray otherwise + * @param FILE_PATH File path write the file to + * @param isSymbol Check if write the Symbol API, NDArray otherwise * @return MD5 String */ def typeSafeRandomClassGen(FILE_PATH: String, isSymbol: Boolean): String = { @@ -111,8 +111,8 @@ private[mxnet] object APIDocGenerator extends GeneratorBase with RandomHelpers { * and function definitions : e.g def softmax(...)(...)(...) : NDArray * Users can directly use the api by calling NDArray. * It support both positional input or Map input - * @param FILE_PATH file path write the file to - * @param isSymbol check if write the Symbol API, NDArray otherwise + * @param FILE_PATH File path write the file to + * @param isSymbol Check if write the Symbol API, NDArray otherwise * @return MD5 String */ def nonTypeSafeClassGen(FILE_PATH: String, isSymbol: Boolean): String = { @@ -146,7 +146,7 @@ private[mxnet] object APIDocGenerator extends GeneratorBase with RandomHelpers { /** * Type-safe interface of Java NDArray - * @param FILE_PATH file path write the file to + * @param FILE_PATH File path write the file to * @return MD5 String */ def javaClassGen(FILE_PATH : String) : String = { @@ -179,9 +179,9 @@ private[mxnet] object APIDocGenerator extends GeneratorBase with RandomHelpers { /** * Generate Scala docs from the function description - * @param func the Function case class - * @param withParam whether to generate param field - * @return a formatted string for the function description + * @param func The function case class + * @param withParam Whether to generate param field + * @return A formatted string for the function description */ def generateAPIDocFromBackend(func: Func, withParam: Boolean = true): String = { def fixDesc(desc: String): String = { @@ -217,12 +217,12 @@ private[mxnet] object APIDocGenerator extends GeneratorBase with RandomHelpers { } /** - * generate the function interface + * Generate the function interface * e.g: def softmax(data: NDArray, name ...): NDArrayFunctionReturn - * @param func the Function case class - * @param isSymbol check if generate Symbol function, NDArray otherwise - * @param typeParameter type param specifically used in Random Module - * @return formatted string for the function + * @param func The function case class + * @param isSymbol Check if generate Symbol function, NDArray otherwise + * @param typeParameter Type param specifically used in Random Module + * @return Formatted string for the function */ def generateAPISignature(func: Func, isSymbol: Boolean, typeParameter: String = ""): String = { val argDef = ListBuffer[String]() @@ -245,8 +245,8 @@ private[mxnet] object APIDocGenerator extends GeneratorBase with RandomHelpers { /** * Generate Java function interface - * @param func the Function case class - * @return a formatted string for the function + * @param func The function case class + * @return A formatted string for the function */ def generateJavaAPISignature(func : Func) : String = { val useParamObject = func.listOfArgs.count(arg => arg.isOptional) >= 2 @@ -308,12 +308,12 @@ private[mxnet] object APIDocGenerator extends GeneratorBase with RandomHelpers { /** * Write the formatted string to file - * @param FILE_PATH location of the file writes to - * @param packageDef package definition - * @param className class name - * @param imports packages need to import - * @param absFuncs all formatted functions - * @return a MD5 string + * @param FILE_PATH Location of the file writes to + * @param packageDef Package definition + * @param className Class name + * @param imports Packages need to import + * @param absFuncs All formatted functions + * @return A MD5 string */ def writeFile(FILE_PATH: String, packageDef: String, className: String, imports: String, absFuncs: Seq[String]): String = { diff --git a/scala-package/macros/src/main/scala/org/apache/mxnet/GeneratorBase.scala b/scala-package/macros/src/main/scala/org/apache/mxnet/GeneratorBase.scala index 35e3cbe6a32e..e3fdeabd54e9 100644 --- a/scala-package/macros/src/main/scala/org/apache/mxnet/GeneratorBase.scala +++ b/scala-package/macros/src/main/scala/org/apache/mxnet/GeneratorBase.scala @@ -27,7 +27,7 @@ private[mxnet] abstract class GeneratorBase { case class Arg(argName: String, argType: String, argDesc: String, isOptional: Boolean) { /** - * filter the arg name with the Scala keyword that are not allow to use as arg name + * Filter the arg name with the Scala keyword that are not allow to use as arg name, * such as var and type listed in here. This is due to the diff between C and Scala * @return argname that works in Scala */ @@ -42,10 +42,10 @@ private[mxnet] abstract class GeneratorBase { /** * Non Type-safe function generation method - * this method will filter all "_" functions - * @param isSymbol check if generate the Symbol method - * @param isContrib check if generate the contrib method - * @param isJava check if generate Corresponding Java method + * This method will filter all "_" functions + * @param isSymbol Check if generate the Symbol method + * @param isContrib Check if generate the contrib method + * @param isJava Check if generate Corresponding Java method * @return List of functions */ def functionsToGenerate(isSymbol: Boolean, isContrib: Boolean, @@ -59,9 +59,9 @@ private[mxnet] abstract class GeneratorBase { } /** - * filter the operators to generate in the type-safe Symbol.api and NDArray.api - * @param isSymbol check if generate the Symbol method - * @param isContrib check if generate the contrib method + * Filter the operators to generate in the type-safe Symbol.api and NDArray.api + * @param isSymbol Check if generate the Symbol method + * @param isContrib Check if generate the contrib method * @return List of functions */ protected def typeSafeFunctionsToGenerate(isSymbol: Boolean, isContrib: Boolean): List[Func] = { @@ -79,8 +79,8 @@ private[mxnet] abstract class GeneratorBase { /** * Extract and format the functions obtained from C API - * @param isSymbol check if generate for Symbol - * @param isJava check if extracting in Java format + * @param isSymbol Check if generate for Symbol + * @param isJava Check if extracting in Java format * @return List of functions */ protected def getBackEndFunctions(isSymbol: Boolean, isJava: Boolean = false): List[Func] = { @@ -131,7 +131,7 @@ private[mxnet] abstract class GeneratorBase { * * @param c Context used for generation * @param funcDef DefDef type of function definitions - * @param annottees annottees used to define Class or Module + * @param annottees Annottees used to define Class or Module * @return Expr used for code generation */ protected def structGeneration(c: blackbox.Context) @@ -166,8 +166,8 @@ private[mxnet] abstract class GeneratorBase { } /** - * build function argument definition, with optionality, and safe names - * @param func functions + * Build function argument definition, with optionality, and safe names + * @param func Functions * @return List of string representing the functions interface */ protected def typedFunctionCommonArgDef(func: Func): List[String] = { @@ -192,10 +192,10 @@ private[mxnet] trait RandomHelpers { self: GeneratorBase => /** - * a generic type spec used in Symbol.random and NDArray.random modules - * @param isSymbol check if generate for Symbol - * @param fullPackageSpec check if leave the full name of the classTag - * @return a formatted string for random Symbol/NDArray + * A generic type spec used in Symbol.random and NDArray.random modules + * @param isSymbol Check if generate for Symbol + * @param fullPackageSpec Check if leave the full name of the classTag + * @return A formatted string for random Symbol/NDArray */ protected def randomGenericTypeSpec(isSymbol: Boolean, fullPackageSpec: Boolean): String = { val classTag = if (fullPackageSpec) "scala.reflect.ClassTag" else "ClassTag" @@ -204,8 +204,8 @@ private[mxnet] trait RandomHelpers { } /** - * filter the operators to generate in the type-safe Symbol.random and NDArray.random - * @param isSymbol check if generate Symbol functions + * Filter the operators to generate in the type-safe Symbol.random and NDArray.random + * @param isSymbol Check if generate Symbol functions * @return List of functions */ protected def typeSafeRandomFunctionsToGenerate(isSymbol: Boolean): List[Func] = { @@ -240,10 +240,10 @@ private[mxnet] trait RandomHelpers { } /** - * hacks to manage the fact that random_normal and sample_normal have + * Hacks to manage the fact that random_normal and sample_normal have * non-consistent parameter naming in the back-end * this first one, merge loc/scale and mu/sigma - * @param arg argument need to modify + * @param arg Argument need to modify * @return Arg case class with clean arg names */ protected def hackNormalFunc(arg: Arg): Arg = { @@ -253,9 +253,9 @@ private[mxnet] trait RandomHelpers { } /** - * this second one reverts this merge prior to back-end call - * @param func function case class - * @return a string contains the implementation of random args + * This second one reverts this merge prior to back-end call + * @param func Function case class + * @return A string contains the implementation of random args */ protected def unhackNormalFunc(func: Func): String = { if (func.name.equals("normal")) { diff --git a/scala-package/macros/src/main/scala/org/apache/mxnet/NDArrayMacro.scala b/scala-package/macros/src/main/scala/org/apache/mxnet/NDArrayMacro.scala index 8ac71fb91d71..7bee2187e026 100644 --- a/scala-package/macros/src/main/scala/org/apache/mxnet/NDArrayMacro.scala +++ b/scala-package/macros/src/main/scala/org/apache/mxnet/NDArrayMacro.scala @@ -23,27 +23,27 @@ import scala.reflect.macros.blackbox private[mxnet] class AddNDArrayFunctions(isContrib: Boolean) extends StaticAnnotation { /** - * generate non-typesafe method for NDArray operations - * @param annottees annottees used to define Class or Module - * @return generated code for injection + * Generate non-typesafe method for NDArray operations + * @param annottees Annottees used to define Class or Module + * @return Generated code for injection */ private[mxnet] def macroTransform(annottees: Any*) = macro NDArrayMacro.addDefs } private[mxnet] class AddNDArrayAPIs(isContrib: Boolean) extends StaticAnnotation { /** - * generate typesafe method for NDArray operations - * @param annottees annottees used to define Class or Module - * @return generated code for injection + * Generate typesafe method for NDArray operations + * @param annottees Annottees used to define Class or Module + * @return Generated code for injection */ private[mxnet] def macroTransform(annottees: Any*) = macro TypedNDArrayAPIMacro.typeSafeAPIDefs } private[mxnet] class AddNDArrayRandomAPIs(isContrib: Boolean) extends StaticAnnotation { /** - * generate typesafe method for Random Symbol - * @param annottees annottees used to define Class or Module - * @return generated code for injection + * Generate typesafe method for Random Symbol + * @param annottees Annottees used to define Class or Module + * @return Generated code for injection */ private[mxnet] def macroTransform(annottees: Any*) = macro TypedNDArrayRandomAPIMacro.typeSafeAPIDefs @@ -54,10 +54,10 @@ private[mxnet] class AddNDArrayRandomAPIs(isContrib: Boolean) extends StaticAnno */ private[mxnet] object NDArrayMacro extends GeneratorBase { /** - * methods that check the isContrib and call code generation + * Methods that check the isContrib and call code generation * @param c Context used for code gen - * @param annottees annottees used to define Class or Module - * @return generated code for injection + * @param annottees Annottees used to define Class or Module + * @return Generated code for injection */ def addDefs(c: blackbox.Context)(annottees: c.Expr[Any]*): c.Expr[Any] = { import c.universe._ @@ -102,10 +102,10 @@ private[mxnet] object NDArrayMacro extends GeneratorBase { */ private[mxnet] object TypedNDArrayAPIMacro extends GeneratorBase { /** - * methods that check the isContrib and call code generation + * Methods that check the isContrib and call code generation * @param c Context used for code gen - * @param annottees annottees used to define Class or Module - * @return generated code for injection + * @param annottees Annottees used to define Class or Module + * @return Generated code for injection */ def typeSafeAPIDefs(c: blackbox.Context)(annottees: c.Expr[Any]*): c.Expr[Any] = { import c.universe._ @@ -120,10 +120,10 @@ private[mxnet] object TypedNDArrayAPIMacro extends GeneratorBase { } /** - * methods that construct the code and build the syntax tree + * Methods that construct the code and build the syntax tree * @param c Context used for code gen - * @param function case class that store all information of the single function - * @return generated syntax tree + * @param function Case class that store all information of the single function + * @return Generated syntax tree */ protected def buildTypedFunction(c: blackbox.Context) (function: Func): c.universe.DefDef = { @@ -194,10 +194,10 @@ private[mxnet] object TypedNDArrayRandomAPIMacro extends GeneratorBase } /** - * methods that construct the code and build the syntax tree + * Methods that construct the code and build the syntax tree * @param c Context used for code gen - * @param function case class that store all information of the single function - * @return generated syntax tree + * @param function Case class that store all information of the single function + * @return Generated syntax tree */ protected def buildTypedFunction(c: blackbox.Context) (function: Func): c.universe.DefDef = { diff --git a/scala-package/macros/src/main/scala/org/apache/mxnet/SymbolMacro.scala b/scala-package/macros/src/main/scala/org/apache/mxnet/SymbolMacro.scala index 99c0bbc99bb5..77d8a1facdd1 100644 --- a/scala-package/macros/src/main/scala/org/apache/mxnet/SymbolMacro.scala +++ b/scala-package/macros/src/main/scala/org/apache/mxnet/SymbolMacro.scala @@ -24,27 +24,27 @@ import scala.reflect.macros.blackbox private[mxnet] class AddSymbolFunctions(isContrib: Boolean) extends StaticAnnotation { /** - * generate non-typesafe method for Symbol operations - * @param annottees annottees used to define Class or Module - * @return generated code for injection + * Generate non-typesafe method for Symbol operations + * @param annottees Annottees used to define Class or Module + * @return Generated code for injection */ private[mxnet] def macroTransform(annottees: Any*) = macro SymbolMacro.addDefs } private[mxnet] class AddSymbolAPIs(isContrib: Boolean) extends StaticAnnotation { /** - * generate typesafe method for Symbol - * @param annottees annottees used to define Class or Module - * @return generated code for injection + * Generate typesafe method for Symbol + * @param annottees Annottees used to define Class or Module + * @return Generated code for injection */ private[mxnet] def macroTransform(annottees: Any*) = macro TypedSymbolAPIMacro.typeSafeAPIDefs } private[mxnet] class AddSymbolRandomAPIs(isContrib: Boolean) extends StaticAnnotation { /** - * generate typesafe method for Random Symbol - * @param annottees annottees used to define Class or Module - * @return generated code for injection + * Generate typesafe method for Random Symbol + * @param annottees Annottees used to define Class or Module + * @return Generated code for injection */ private[mxnet] def macroTransform(annottees: Any*) = macro TypedSymbolRandomAPIMacro.typeSafeAPIDefs @@ -56,10 +56,10 @@ private[mxnet] class AddSymbolRandomAPIs(isContrib: Boolean) extends StaticAnnot private[mxnet] object SymbolMacro extends GeneratorBase { /** - * methods that check the isContrib and call code generation + * Methods that check the isContrib and call code generation * @param c Context used for code gen - * @param annottees annottees used to define Class or Module - * @return generated code for injection + * @param annottees Annottees used to define Class or Module + * @return Generated code for injection */ def addDefs(c: blackbox.Context)(annottees: c.Expr[Any]*): c.Expr[Any] = { import c.universe._ @@ -98,10 +98,10 @@ private[mxnet] object SymbolMacro extends GeneratorBase { private[mxnet] object TypedSymbolAPIMacro extends GeneratorBase { /** - * methods that check the isContrib and call code generation + * Methods that check the isContrib and call code generation * @param c Context used for code gen - * @param annottees annottees used to define Class or Module - * @return generated code for injection + * @param annottees Annottees used to define Class or Module + * @return Generated code for injection */ def typeSafeAPIDefs(c: blackbox.Context)(annottees: c.Expr[Any]*): c.Expr[Any] = { import c.universe._ @@ -116,10 +116,10 @@ private[mxnet] object TypedSymbolAPIMacro extends GeneratorBase { } /** - * methods that construct the code and build the syntax tree + * Methods that construct the code and build the syntax tree * @param c Context used for code gen - * @param function case class that store all information of the single function - * @return generated syntax tree + * @param function Case class that store all information of the single function + * @return Generated syntax tree */ protected def buildTypedFunction(c: blackbox.Context) (function: Func): c.universe.DefDef = { @@ -174,10 +174,10 @@ private[mxnet] object TypedSymbolRandomAPIMacro extends GeneratorBase with RandomHelpers { /** - * methods that check the isContrib and call code generation + * Methods that check the isContrib and call code generation * @param c Context used for code gen - * @param annottees annottees used to define Class or Module - * @return generated code for injection + * @param annottees Annottees used to define Class or Module + * @return Generated code for injection */ def typeSafeAPIDefs(c: blackbox.Context)(annottees: c.Expr[Any]*): c.Expr[Any] = { val functionDefs = typeSafeRandomFunctionsToGenerate(isSymbol = true) @@ -187,10 +187,10 @@ private[mxnet] object TypedSymbolRandomAPIMacro extends GeneratorBase } /** - * methods that construct the code and build the syntax tree + * Methods that construct the code and build the syntax tree * @param c Context used for code gen - * @param function case class that store all information of the single function - * @return generated syntax tree + * @param function Case class that store all information of the single function + * @return Generated syntax tree */ protected def buildTypedFunction(c: blackbox.Context) (function: Func): c.universe.DefDef = { diff --git a/scala-package/macros/src/main/scala/org/apache/mxnet/javaapi/JavaNDArrayMacro.scala b/scala-package/macros/src/main/scala/org/apache/mxnet/javaapi/JavaNDArrayMacro.scala index 6ac7b58e1cfc..29206247296d 100644 --- a/scala-package/macros/src/main/scala/org/apache/mxnet/javaapi/JavaNDArrayMacro.scala +++ b/scala-package/macros/src/main/scala/org/apache/mxnet/javaapi/JavaNDArrayMacro.scala @@ -26,9 +26,9 @@ import scala.reflect.macros.blackbox private[mxnet] class AddJNDArrayAPIs(isContrib: Boolean) extends StaticAnnotation { /** - * generate typesafe method for Java NDArray operations - * @param annottees annottees used to define Class or Module - * @return generated code for injection + * Generate typesafe method for Java NDArray operations + * @param annottees Annottees used to define Class or Module + * @return Generated code for injection */ private[mxnet] def macroTransform(annottees: Any*) = macro JavaNDArrayMacro.typeSafeAPIDefs } @@ -36,10 +36,10 @@ private[mxnet] class AddJNDArrayAPIs(isContrib: Boolean) extends StaticAnnotatio private[mxnet] object JavaNDArrayMacro extends GeneratorBase { /** - * methods that call code generation + * Methods that call code generation * @param c Context used for code gen - * @param annottees annottees used to define Class or Module - * @return generated code for injection + * @param annottees Annottees used to define Class or Module + * @return Generated code for injection */ def typeSafeAPIDefs(c: blackbox.Context)(annottees: c.Expr[Any]*) : c.Expr[Any] = { typeSafeAPIImpl(c)(annottees: _*) diff --git a/scala-package/macros/src/main/scala/org/apache/mxnet/utils/CToScalaUtils.scala b/scala-package/macros/src/main/scala/org/apache/mxnet/utils/CToScalaUtils.scala index d82dd6aca005..c984d07143ef 100644 --- a/scala-package/macros/src/main/scala/org/apache/mxnet/utils/CToScalaUtils.scala +++ b/scala-package/macros/src/main/scala/org/apache/mxnet/utils/CToScalaUtils.scala @@ -33,11 +33,11 @@ private[mxnet] object CToScalaUtils { /** * Convert C++ Types to Scala Types - * @param in input raw string that contains C type docs - * @param argType arg type that used for error messaging - * @param argName arg name used for error messaging - * @param returnType the type that NDArray/Symbol should be - * @param isJava check if generating for Java + * @param in Input raw string that contains C type docs + * @param argType Arg type that used for error messaging + * @param argName Arg name used for error messaging + * @param returnType The type that NDArray/Symbol should be + * @param isJava Check if generating for Java * @return String that contains right Scala/Java types */ def typeConversion(in : String, argType : String = "", argName : String, @@ -72,8 +72,8 @@ private[mxnet] object CToScalaUtils { * optional, what is it Scala type and possibly pass in a default value * @param argName The name of the argument * @param argType Raw arguement Type description - * @param returnType return type of the function (Symbol/NDArray) - * @param isJava check if Java args should be generated + * @param returnType Return type of the function (Symbol/NDArray) + * @param isJava Check if Java args should be generated * @return (Scala_Type, isOptional) */ def argumentCleaner(argName: String, argType : String, From 085649f17e87e5b3f908f6a9fbe5a9cacaeb2bbf Mon Sep 17 00:00:00 2001 From: Qing Date: Thu, 18 Apr 2019 14:58:51 -0700 Subject: [PATCH 4/4] amend the rest of them --- .../scala/org/apache/mxnet/init/LibInfo.scala | 30 +++++++++---------- .../scala/org/apache/mxnet/NDArrayMacro.scala | 6 ++-- .../scala/org/apache/mxnet/SymbolMacro.scala | 6 ++-- 3 files changed, 21 insertions(+), 21 deletions(-) diff --git a/scala-package/init/src/main/scala/org/apache/mxnet/init/LibInfo.scala b/scala-package/init/src/main/scala/org/apache/mxnet/init/LibInfo.scala index 9c5735d3bbe5..c813d449f652 100644 --- a/scala-package/init/src/main/scala/org/apache/mxnet/init/LibInfo.scala +++ b/scala-package/init/src/main/scala/org/apache/mxnet/init/LibInfo.scala @@ -24,22 +24,22 @@ import scala.collection.mutable.ListBuffer class LibInfo { /** * Get the list of the symbol ids - * @param symbolList pass in an empty ListBuffer and obtain a list of operator ids - * @return callback result + * @param symbolList Pass in an empty ListBuffer and obtain a list of operator IDs + * @return Callback result */ @native def mxSymbolListAtomicSymbolCreators(symbolList: ListBuffer[SymbolHandle]): Int /** * Get the detailed information of an operator - * @param handle The id of the operator - * @param name name of the operator - * @param desc description of the operator - * @param numArgs number of arguments - * @param argNames argument names - * @param argTypes argument types - * @param argDescs argument descriptions + * @param handle The ID of the operator + * @param name Name of the operator + * @param desc Description of the operator + * @param numArgs Number of arguments + * @param argNames Argument names + * @param argTypes Argument types + * @param argDescs Argument descriptions * @param keyVarNumArgs Kwargs number - * @return callback result + * @return Callback result */ @native def mxSymbolGetAtomicSymbolInfo(handle: SymbolHandle, name: RefString, @@ -51,16 +51,16 @@ class LibInfo { keyVarNumArgs: RefString): Int /** * Get the name list of all operators - * @param names names of all operators - * @return callback result + * @param names Names of all operator + * @return Callback result */ @native def mxListAllOpNames(names: ListBuffer[String]): Int /** - * get operator id from its name + * Get operator ID from its name * @param opName Operator name - * @param opHandle Operator id - * @return callback result + * @param opHandle Operator ID + * @return Callback result */ @native def nnGetOpHandle(opName: String, opHandle: RefLong): Int } diff --git a/scala-package/macros/src/main/scala/org/apache/mxnet/NDArrayMacro.scala b/scala-package/macros/src/main/scala/org/apache/mxnet/NDArrayMacro.scala index 7bee2187e026..c9c10f50c01f 100644 --- a/scala-package/macros/src/main/scala/org/apache/mxnet/NDArrayMacro.scala +++ b/scala-package/macros/src/main/scala/org/apache/mxnet/NDArrayMacro.scala @@ -54,7 +54,7 @@ private[mxnet] class AddNDArrayRandomAPIs(isContrib: Boolean) extends StaticAnno */ private[mxnet] object NDArrayMacro extends GeneratorBase { /** - * Methods that check the isContrib and call code generation + * Methods that check the ``isContrib`` and call code generation * @param c Context used for code gen * @param annottees Annottees used to define Class or Module * @return Generated code for injection @@ -102,7 +102,7 @@ private[mxnet] object NDArrayMacro extends GeneratorBase { */ private[mxnet] object TypedNDArrayAPIMacro extends GeneratorBase { /** - * Methods that check the isContrib and call code generation + * Methods that check the ``isContrib`` and call code generation * @param c Context used for code gen * @param annottees Annottees used to define Class or Module * @return Generated code for injection @@ -179,7 +179,7 @@ private[mxnet] object TypedNDArrayAPIMacro extends GeneratorBase { private[mxnet] object TypedNDArrayRandomAPIMacro extends GeneratorBase with RandomHelpers { /** - * methods that check the isContrib and call code generation + * methods that check the ``isContrib`` and call code generation * @param c Context used for code gen * @param annottees annottees used to define Class or Module * @return generated code for injection diff --git a/scala-package/macros/src/main/scala/org/apache/mxnet/SymbolMacro.scala b/scala-package/macros/src/main/scala/org/apache/mxnet/SymbolMacro.scala index 77d8a1facdd1..1a0405cfd63d 100644 --- a/scala-package/macros/src/main/scala/org/apache/mxnet/SymbolMacro.scala +++ b/scala-package/macros/src/main/scala/org/apache/mxnet/SymbolMacro.scala @@ -56,7 +56,7 @@ private[mxnet] class AddSymbolRandomAPIs(isContrib: Boolean) extends StaticAnnot private[mxnet] object SymbolMacro extends GeneratorBase { /** - * Methods that check the isContrib and call code generation + * Methods that check the ``isContrib`` and call code generation * @param c Context used for code gen * @param annottees Annottees used to define Class or Module * @return Generated code for injection @@ -98,7 +98,7 @@ private[mxnet] object SymbolMacro extends GeneratorBase { private[mxnet] object TypedSymbolAPIMacro extends GeneratorBase { /** - * Methods that check the isContrib and call code generation + * Methods that check the ``isContrib`` and call code generation * @param c Context used for code gen * @param annottees Annottees used to define Class or Module * @return Generated code for injection @@ -174,7 +174,7 @@ private[mxnet] object TypedSymbolRandomAPIMacro extends GeneratorBase with RandomHelpers { /** - * Methods that check the isContrib and call code generation + * Methods that check the ``isContrib`` and call code generation * @param c Context used for code gen * @param annottees Annottees used to define Class or Module * @return Generated code for injection