lanking520 commented on a change in pull request #10660: [MXNET-357][WIP] New
Scala API Design
URL: https://github.com/apache/incubator-mxnet/pull/10660#discussion_r183911000
##########
File path:
scala-package/macros/src/main/scala/org/apache/mxnet/SymbolMacro.scala
##########
@@ -136,20 +98,67 @@ private[mxnet] object SymbolImplMacros {
result
}
+ // Convert C++ Types to Scala Types
+ private def typeConversion(in : String, argType : String = "") : String = {
+ in match {
+ case "Shape(tuple)" | "ShapeorNone" => "Shape"
+ case "Symbol" | "NDArray" | "NDArray-or-Symbol" => "Symbol"
+ case "Symbol[]" | "NDArray[]" | "NDArray-or-Symbol[]" |
"SymbolorSymbol[]" => "Array[Symbol]"
+ case "float" | "real_t" => "MXFloat"
+ case "int" | "intorNone" | "int(non-negative)" => "Int"
+ case "long" | "long(non-negative)" => "Long"
+ case "double" => "Double"
+ case "string" => "String"
+ case "boolean" => "Boolean"
+ case "tupleof<float>" => "Any"
+ case default => throw new IllegalArgumentException(
+ s"Invalid type for args: $default, $argType")
+ }
+ }
+
+ private def argumentCleaner(argType : String) : (String, Boolean) = {
+ val spaceRemoved = argType.replaceAll("\\s+", "")
+ var commaRemoved : Array[String] = new Array[String](0)
+ // Deal with the case e.g: stype : {'csr', 'default', 'row_sparse'}
+ if (spaceRemoved.charAt(0)== '{') {
+ val endIdx = spaceRemoved.indexOf('}')
+ commaRemoved = spaceRemoved.substring(endIdx + 1).split(",")
+ // commaRemoved(0) = spaceRemoved.substring(0, endIdx+1)
+ commaRemoved(0) = "string"
+ } else {
+ commaRemoved = spaceRemoved.split(",")
+ }
+ // Optional Field
+ if (commaRemoved.length >= 3) {
+ (typeConversion(commaRemoved(0), argType), true)
+ // TODO: Qing: do we set default value on our side?
+ // optionalField = " = " + conversion(typeConv,
commaRemoved(2).split("=")(1))
+ } else if (commaRemoved.length == 2 || commaRemoved.length == 1) {
+ val tempType = typeConversion(commaRemoved(0), argType)
+ val tempOptional = tempType.equals("Symbol")
+ (tempType, tempOptional)
+ } else {
+ throw new IllegalArgumentException(
+ s"Unrecognized arg field: $argType, ${commaRemoved.length}")
+ }
+
+ }
+
+
// List and add all the atomic symbol functions to current module.
- private def initSymbolModule(): Map[String, SymbolFunction] = {
+ private def initSymbolModule(): List[SymbolFunction] = {
val opNames = ListBuffer.empty[String]
_LIB.mxListAllOpNames(opNames)
- opNames.map(opName => {
+ opNames.filter(!_.startsWith("_")).map(opName => {
Review comment:
The reason for filter _ is to remove the internal function to be compiled.
The Documentation for Internal function has not been updated for a long time.
----------------------------------------------------------------
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