learning-chip edited a comment on issue #8413:
URL: https://github.com/apache/tvm/issues/8413#issuecomment-875348151
I can indeed use `A.data`, `A.indices`, `A.indptr` as three separate nodes
and inputs. But then the purpose of `tvmsp.placeholder` becomes unclear,
because I can simply use three 1-D tensors to represent the CSR matrix, without
having a new CSR data type.
Here's a simple example:
```python
import numpy as np
from scipy.sparse import csr_matrix
import tvm
import tvm.contrib.sparse as tvmsp
indptr = np.array([0, 2, 3, 6])
indices = np.array([0, 2, 2, 0, 1, 2])
data = np.array([1, 2, 3, 4, 5, 6])
A_csr = csr_matrix((data, indices, indptr), shape=(3, 3)).astype('float32')
b = np.array([1, 2, 3]).reshape(-1, 1).astype('float32')
def generate_args(A_csr, b, dtype='float32'):
dev = tvm.device('llvm', 0)
nr = A_csr.shape[0]
# tvmsp.CSRNDArray here can be replaced by 3 independent tvm.nd.arrays
(data, indices, indptr)
A_csr_nd = tvmsp.CSRNDArray(
tuple(tvm.nd.array(x, device=dev) for x in
(A_csr.data.astype(dtype), A_csr.indices, A_csr.indptr)),
device=dev, shape=A_csr.shape
)
b_nd = tvm.nd.array(b.reshape(-1, 1).astype(np.float32), device=dev)
out_nd = tvm.nd.array(np.zeros((nr, 1), dtype=np.float32), device=dev)
return [nr, A_csr_nd.data, A_csr_nd.indices, A_csr_nd.indptr, b_nd],
out_nd
inputs, out = generate_args(A_csr, b)
csrmv(*inputs, out) # function csrmv is generated by build_csrmv() before
np.array_equal(out.numpy(), A_csr @ b) # same as SciPy result
```
--
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.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]