samskalicky commented on a change in pull request #17569: Adding sparse support 
to MXTensor for custom operators
URL: https://github.com/apache/incubator-mxnet/pull/17569#discussion_r392533713
 
 

 ##########
 File path: src/c_api/c_api.cc
 ##########
 @@ -572,12 +645,30 @@ int MXLoadLib(const char *path) {
                                 DispatchMode* dispatch_mode,
                                 std::vector<int>* in_stypes,
                                 std::vector<int>* out_stypes) {
-      // TODO(ziyimu): remove this dense enforce check after supporting sparse 
tensor
-      CHECK(mxnet::common::ContainsOnlyStorage(*in_stypes, 
mxnet::kDefaultStorage))
-      << "Error input tensors are not dense for custom operator '" << name_str 
<< "'";
-      // set outputs as dense
-      return op::storage_type_assign(out_stypes, mxnet::kDefaultStorage,
-                                     dispatch_mode, DispatchMode::kFComputeEx);
+      // convert attributes to vector of char*
+      std::vector<const char*> attr_keys, attr_vals;
+      for (auto kv : attrs.dict) {
+        attr_keys.push_back(kv.first.c_str());
+        attr_vals.push_back(kv.second.c_str());
+      }
+      // copy input types from in_stype
+      std::vector<int> instypes(*in_stypes);
+
+      // output types will be populated by inferType function
+      std::vector<int> outstypes(out_stypes->size());
+
+      CHECK(callInferSType(stype_fp, attr_keys.data(), attr_vals.data(), 
attr_keys.size(),
 
 Review comment:
   No, but infering storage types should be optional. It is a niche use case, 
most custom ops will just use dense. people only need to implement this 
function when they want to support sparse. Its an unnecessary requirement for 
dense operator writers to implement this. 
   
   Currently, built-in operators do not have to implement infer storage types. 
heres one example that doesnt:
   
https://github.com/apache/incubator-mxnet/blob/c5989fa590c8e4d511853c4f33e66231dbe0fb5f/src/operator/tensor/diag_op.cc#L88-L100

----------------------------------------------------------------
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]


With regards,
Apache Git Services

Reply via email to