yzhliu 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_r183919376
########## File path: scala-package/macros/src/main/scala/org/apache/mxnet/SymbolMacro.scala ########## @@ -48,67 +49,28 @@ private[mxnet] object SymbolImplMacros { } val newSymbolFunctions = { - if (isContrib) symbolFunctions.filter(_._1.startsWith("_contrib_")) - else symbolFunctions.filter(!_._1.startsWith("_contrib_")) + if (isContrib) symbolFunctions.filter(_.name.startsWith("_contrib_")) + else symbolFunctions.filter(!_.name.startsWith("_contrib_")) } - val AST_TYPE_MAP_STRING_ANY = AppliedTypeTree(Ident(TypeName("Map")), - List(Ident(TypeName("String")), Ident(TypeName("Any")))) - val AST_TYPE_MAP_STRING_STRING = AppliedTypeTree(Ident(TypeName("Map")), - List(Ident(TypeName("String")), Ident(TypeName("String")))) - val AST_TYPE_SYMBOL_VARARG = AppliedTypeTree( - Select( - Select(Ident(termNames.ROOTPKG), TermName("scala")), - TypeName("<repeated>") - ), - List(Select(Select(Select( - Ident(TermName("org")), TermName("apache")), TermName("mxnet")), TypeName("Symbol"))) - ) - - val functionDefs = newSymbolFunctions map { case (funcName, funcProp) => - val functionScope = { - if (isContrib) Modifiers() - else { - if (funcName.startsWith("_")) Modifiers(Flag.PRIVATE) else Modifiers() - } - } - val newName = { - if (isContrib) funcName.substring(funcName.indexOf("_contrib_") + "_contrib_".length()) - else funcName - } + val functionDefs = newSymbolFunctions map { symbolfunction => + val funcName = symbolfunction.name + val tName = TermName(funcName) + q""" + def $tName(name : String = null, attr : Map[String, String] = null) + (args : org.apache.mxnet.Symbol*)(kwargs : Map[String, Any] = null) + : org.apache.mxnet.Symbol = { + createSymbolGeneral($funcName,name,attr,args,kwargs) + } + """ + } - // It will generate definition something like, - // def Concat(name: String = null, attr: Map[String, String] = null) - // (args: Symbol*)(kwargs: Map[String, Any] = null) - DefDef(functionScope, TermName(newName), List(), - List( - List( - ValDef(Modifiers(Flag.PARAM | Flag.DEFAULTPARAM), TermName("name"), - Ident(TypeName("String")), Literal(Constant(null))), - ValDef(Modifiers(Flag.PARAM | Flag.DEFAULTPARAM), TermName("attr"), - AST_TYPE_MAP_STRING_STRING, Literal(Constant(null))) - ), - List( - ValDef(Modifiers(), TermName("args"), AST_TYPE_SYMBOL_VARARG, EmptyTree) - ), - List( - ValDef(Modifiers(Flag.PARAM | Flag.DEFAULTPARAM), TermName("kwargs"), - AST_TYPE_MAP_STRING_ANY, Literal(Constant(null))) - ) - ), TypeTree(), - Apply( - Ident(TermName("createSymbolGeneral")), - List( - Literal(Constant(funcName)), - Ident(TermName("name")), - Ident(TermName("attr")), - Ident(TermName("args")), - Ident(TermName("kwargs")) - ) - ) - ) + val newFunctionDefs = newSymbolFunctions map { symbolfunction => Review comment: I know, but remove this for now. ---------------------------------------------------------------- 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: us...@infra.apache.org With regards, Apache Git Services