barry-jin commented on a change in pull request #19685:
URL: https://github.com/apache/incubator-mxnet/pull/19685#discussion_r562270227



##########
File path: src/api/_api_internal/_api_internal.cc
##########
@@ -58,15 +59,47 @@ MXNET_REGISTER_GLOBAL("_ADT")
     using namespace runtime;
     std::vector<ObjectRef> data;
     for (int i = 0; i < args.size(); ++i) {
-      if (args[i].type_code() != kNull) {
-        data.push_back(args[i].operator ObjectRef());
+      if (args[i].type_code() == kNDArrayHandle) {
+        mxnet::NDArray *array = args[i].operator mxnet::NDArray*();
+        ObjectRef input = NDArrayHandle(array);
+        data.push_back(input);
+      } else if (args[i].type_code() != kNull) {
+        ObjectRef input = String::CanConvertFrom(args[i]) ? args[i].operator 
String()
+                                                          : args[i].operator 
ObjectRef();
+        data.push_back(input);
       } else {
         data.emplace_back(nullptr);
       }
     }
     *ret = ADT(0, data.begin(), data.end());
 });
 
+MXNET_REGISTER_GLOBAL("_Map")
+.set_body([](runtime::MXNetArgs args, runtime::MXNetRetValue* ret) {
+    using namespace runtime;
+    CHECK_EQ(args.size() % 2, 0);
+    std::unordered_map<ObjectRef, ObjectRef, ObjectHash, ObjectEqual> data;
+    for (int i = 0; i < args.num_args; i += 2) {
+      ObjectRef k =
+          String::CanConvertFrom(args[i]) ? args[i].operator String()
+                                          : args[i].operator ObjectRef();
+      ObjectRef v;
+      if (args[i + 1].type_code() == kNDArrayHandle) {
+        mxnet::NDArray *array = args[i + 1].operator mxnet::NDArray*();
+        v = NDArrayHandle(array);
+      } else {
+        v = args[i + 1];
+      }
+      data.emplace(std::move(k), std::move(v));
+    }
+    *ret = Map<ObjectRef, ObjectRef>(data);
+});
+
+MXNET_REGISTER_GLOBAL("_echo")
+.set_body([](runtime::MXNetArgs args, runtime::MXNetRetValue* ret) {
+  *ret = args[0];
+});

Review comment:
       `echo` is used for making a copy of `MXNet.String` with shared object 
handle. Currently only used in testing. 




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to