samskalicky 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_r386606449
##########
File path: include/mxnet/lib_api.h
##########
@@ -1111,18 +1171,63 @@ extern "C" {
// create a vector of tensors for inputs
std::vector<MXTensor> inputs(num_in);
+
+ MXStorageType type;
+ void *data = nullptr;
+ void *data2 = nullptr;
+ MXSparse sparse;
+ MXSparse sparse2;
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]});
+ // Dense representation.
+ if(!in_indices_shapes) {
+ type = kDefaultStorage;
+ data = indata[i];
+ }
+ // Sparse representation.
+ else {
+ // To do: remove if else.
+ if(!in_indptr_shapes) {
+ 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:
This is a really complicated initialization sequence for sparse:
```
MXSparse sparse;
sparse.set(indata[i], inshapes[i], indims[i], in_indices[i],
in_indices_shapes[i]);
data = (void*)(&sparse);
inputs[i].setTensor(data, (MXDType)intypes[i], inshapes[i], indims[i],
inIDs[i], {indev_type[i], indev_id[i]}, type);
```
Can we move it into the MXTensor struct to simplify where sparse structs get
created/managed?
Also, this implementation will constantly overwrite the one `MXSparse
sparse` object on the stack for every input MXTensor. So all MXTensors will be
pointing at the same sparse object. It will be easier to manage this with
MXSparse as part of MXTensor.
----------------------------------------------------------------
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