guanxinq commented on a change in pull request #17569: [WIP] Adding sparse
support to MXTensor for custom operators
URL: https://github.com/apache/incubator-mxnet/pull/17569#discussion_r380410282
##########
File path: include/mxnet/lib_api.h
##########
@@ -1111,16 +1166,63 @@ extern "C" {
// create a vector of tensors for inputs
std::vector<MXTensor> inputs(num_in);
+
for (int i = 0; i < num_in; i++) {
- inputs[i].setTensor(indata[i], (MXDType)intypes[i], inshapes[i],
indims[i],
- inIDs[i], {indev_type[i], indev_id[i]});
+ MXStorageType type;
+ void *data = nullptr;
+ MXSparse sparse;
+ // Dense representation.
+ if(in_indices_shapes[i] == 0) {
+ type = kDefaultStorage;
+ data = indata[i];
+ }
+ // Sparse representation.
+ else {
+ // To do: remove if else.
+ if(in_indptr_shapes[i] == 0) {
+ type = kRowSparseStorage;
+ sparse.set(indata[i], inshapes[i], indims[i], in_indices[i],
in_indices_shapes[i]);
+ }
+ else {
+ type = kCSRStorage;
+ sparse.set(indata[i], inshapes[i], indims[i], in_indices[i],
+ in_indices_shapes[i], in_indptr[i], in_indptr_shapes[i]);
+ }
+ data = (void*)(&sparse);
+ }
Review comment:
I could create a function for this part and therefore there will be no
duplicate code. The advantage of this implementation is that we do not need to
modify setTensor(). If we move it to setTensor(), we have to modify the
interface to pass in all the extra data required by sparse.
----------------------------------------------------------------
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