[GitHub] Roshrini commented on a change in pull request #10546: [MXNET-319] Add Autocomplete Macros in Scala

2018-04-13 Thread GitBox
Roshrini commented on a change in pull request #10546: [MXNET-319] Add 
Autocomplete Macros in Scala
URL: https://github.com/apache/incubator-mxnet/pull/10546#discussion_r181501563
 
 

 ##
 File path: 
scala-package/macros/src/main/scala/org/apache/mxnet/SymbolBaseMacro.scala
 ##
 @@ -0,0 +1,224 @@
+/*
+ * 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
+
+import scala.collection.mutable.{HashMap, ListBuffer}
+import org.apache.mxnet.init.Base._
+
+
+private[mxnet] object SymbolDocMacros {
+
+  case class SymbolFunction(handle: SymbolHandle, paramStr: String)
+
+  def addDefs() : Unit = {
+val baseDir = System.getProperty("user.dir")
+val targetPath = baseDir + 
"/core/src/main/scala/org/apache/mxnet/SymbolBase.scala"
+SEImpl(targetPath)
+  }
+
+  def SEImpl(FILE_PATH : String) : Unit = {
+var symbolFunctions: List[SymbolFunction] = initSymbolModule()
+import java.io._
+val pw = new PrintWriter(new File(FILE_PATH))
+// scalastyle:off
+pw.write("/*\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\npackage 
org.apache.mxnet\n")
+// scalastyle:on
+pw.write(s"\ntrait SymbolBase {\n\n")
+pw.write(s"  // scalastyle:off\n")
+symbolFunctions = symbolFunctions.distinct
+for (ele <- symbolFunctions) {
+  val temp = ele.paramStr + "\n\n"
+  pw.write(temp)
+}
+pw.write(s"\n\n}")
+pw.close()
+  }
+
+
+  /*
+Code copies from the SymbolMacros Class
+   */
+  private def initSymbolModule(): List[SymbolFunction] = {
+var opNames = ListBuffer.empty[String]
+_LIB.mxListAllOpNames(opNames)
+opNames = opNames.distinct
+val result : ListBuffer[SymbolFunction] = ListBuffer[SymbolFunction]()
+opNames.foreach(opName => {
+  val opHandle = new RefLong
+  // printf(opName)
+  _LIB.nnGetOpHandle(opName, opHandle)
+  makeAtomicSymbolFunction(opHandle.value, opName, result)
+})
+
+result.toList
+  }
+
+  private def makeAtomicSymbolFunction(handle: SymbolHandle,
+   aliasName: String, result : 
ListBuffer[SymbolFunction])
+  : Unit = {
+val name = new RefString
+val desc = new RefString
+val keyVarNumArgs = new RefString
+val returnType = new RefString
+val numArgs = new RefInt
+val argNames = ListBuffer.empty[String]
+val argTypes = ListBuffer.empty[String]
+val argDescs = ListBuffer.empty[String]
+
+_LIB.mxSymbolGetAtomicSymbolInfo(
+  handle, name, desc, numArgs, argNames, argTypes, argDescs, 
keyVarNumArgs, returnType)
+
+if (name.value.charAt(0) == '_') {
+  // Internal function
+} else {
+  val paramStr =
+traitgen(name.value, desc.value, argNames, argTypes, argDescs, 
returnType.value)
+  val extraDoc: String = if (keyVarNumArgs.value != null && 
keyVarNumArgs.value.length > 0) {
+s"This function support variable length of positional input 
(${keyVarNumArgs.value})."
+  } else {
+""
+  }
+  result +=  SymbolFunction(handle, paramStr)
+}
+  }
+
+
+  def traitgen(functionName : String,
+   functionDesc : String,
+   argNames : Seq[String],
+   argTypes : Seq[String],
+   argDescs : Seq[String],
+   returnType : String) : String = {
+val desc = functionDesc.split("\n") map { currStr =>
+  s"  * $currStr"
+}
+val params =
+  (argNames zip argTypes zip argDescs) 

[GitHub] Roshrini commented on a change in pull request #10546: [MXNET-319] Add Autocomplete Macros in Scala

2018-04-13 Thread GitBox
Roshrini commented on a change in pull request #10546: [MXNET-319] Add 
Autocomplete Macros in Scala
URL: https://github.com/apache/incubator-mxnet/pull/10546#discussion_r181501517
 
 

 ##
 File path: 
scala-package/macros/src/main/scala/org/apache/mxnet/SymbolBaseMacro.scala
 ##
 @@ -0,0 +1,224 @@
+/*
+ * 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
+
+import scala.collection.mutable.{HashMap, ListBuffer}
+import org.apache.mxnet.init.Base._
+
+
 
 Review comment:
   Add comments explaining the functionality of this macro


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


[GitHub] Roshrini commented on a change in pull request #10546: [MXNET-319] Add Autocomplete Macros in Scala

2018-04-13 Thread GitBox
Roshrini commented on a change in pull request #10546: [MXNET-319] Add 
Autocomplete Macros in Scala
URL: https://github.com/apache/incubator-mxnet/pull/10546#discussion_r181501607
 
 

 ##
 File path: 
scala-package/macros/src/main/scala/org/apache/mxnet/SymbolBaseMacro.scala
 ##
 @@ -0,0 +1,224 @@
+/*
+ * 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
+
+import scala.collection.mutable.{HashMap, ListBuffer}
+import org.apache.mxnet.init.Base._
+
+
+private[mxnet] object SymbolDocMacros {
+
+  case class SymbolFunction(handle: SymbolHandle, paramStr: String)
+
+  def addDefs() : Unit = {
+val baseDir = System.getProperty("user.dir")
+val targetPath = baseDir + 
"/core/src/main/scala/org/apache/mxnet/SymbolBase.scala"
+SEImpl(targetPath)
+  }
+
+  def SEImpl(FILE_PATH : String) : Unit = {
+var symbolFunctions: List[SymbolFunction] = initSymbolModule()
+import java.io._
+val pw = new PrintWriter(new File(FILE_PATH))
+// scalastyle:off
+pw.write("/*\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\npackage 
org.apache.mxnet\n")
+// scalastyle:on
+pw.write(s"\ntrait SymbolBase {\n\n")
+pw.write(s"  // scalastyle:off\n")
+symbolFunctions = symbolFunctions.distinct
+for (ele <- symbolFunctions) {
+  val temp = ele.paramStr + "\n\n"
+  pw.write(temp)
+}
+pw.write(s"\n\n}")
+pw.close()
+  }
+
+
+  /*
+Code copies from the SymbolMacros Class
+   */
+  private def initSymbolModule(): List[SymbolFunction] = {
+var opNames = ListBuffer.empty[String]
+_LIB.mxListAllOpNames(opNames)
+opNames = opNames.distinct
+val result : ListBuffer[SymbolFunction] = ListBuffer[SymbolFunction]()
+opNames.foreach(opName => {
+  val opHandle = new RefLong
+  // printf(opName)
+  _LIB.nnGetOpHandle(opName, opHandle)
+  makeAtomicSymbolFunction(opHandle.value, opName, result)
+})
+
+result.toList
+  }
+
+  private def makeAtomicSymbolFunction(handle: SymbolHandle,
+   aliasName: String, result : 
ListBuffer[SymbolFunction])
+  : Unit = {
+val name = new RefString
+val desc = new RefString
+val keyVarNumArgs = new RefString
+val returnType = new RefString
+val numArgs = new RefInt
+val argNames = ListBuffer.empty[String]
+val argTypes = ListBuffer.empty[String]
+val argDescs = ListBuffer.empty[String]
+
+_LIB.mxSymbolGetAtomicSymbolInfo(
+  handle, name, desc, numArgs, argNames, argTypes, argDescs, 
keyVarNumArgs, returnType)
+
+if (name.value.charAt(0) == '_') {
+  // Internal function
+} else {
+  val paramStr =
+traitgen(name.value, desc.value, argNames, argTypes, argDescs, 
returnType.value)
+  val extraDoc: String = if (keyVarNumArgs.value != null && 
keyVarNumArgs.value.length > 0) {
+s"This function support variable length of positional input 
(${keyVarNumArgs.value})."
+  } else {
+""
+  }
+  result +=  SymbolFunction(handle, paramStr)
+}
+  }
+
+
+  def traitgen(functionName : String,
+   functionDesc : String,
+   argNames : Seq[String],
+   argTypes : Seq[String],
+   argDescs : Seq[String],
+   returnType : String) : String = {
+val desc = functionDesc.split("\n") map { currStr =>
+  s"  * $currStr"
+}
+val params =
+  (argNames zip argTypes zip argDescs)