afnumpy icon indicating copy to clipboard operation
afnumpy copied to clipboard

sparse array support

Open smarkesini opened this issue 5 years ago • 3 comments

Hello again, this is a feature request: It would be awesome to get some kind of sparse array support, most importantly spmv and spmm with a dense matrix, I realize this is a scipy function, but such basic linear algebra functionality would be nice, something along the lines of S=csr_matrix((data, (row_ind, col_ind)), [shape=(M, N)]) vol=qtS #SpMV where qt is a 1d vector or dense matrix with dimension (,M)

Cheers, Stefano

smarkesini avatar Sep 15 '19 21:09 smarkesini

This is more complicated but I'll see what can be done.

FilipeMaia avatar Sep 18 '19 14:09 FilipeMaia

a84760ac21f67d86f7d257bd87eb870e183ada22 add very very basic sparse matrix functionality. It can do something like the following:

import afnumpy.sparse as afsparse
import numpy as np
row = np.array([0, 0, 1, 2, 2, 2])
col = np.array([0, 2, 2, 0, 1, 2])
data = np.array([1, 2, 3, 4, 5, 6], dtype=np.float32)
A = afsparse.csr_matrix((data, (row, col)), shape=(3, 3))
v = np.ones((3),dtype=np.float32)
print(A*v)

Out[]: array([ 3.,  3., 15.], dtype=float32)

FilipeMaia avatar Sep 18 '19 17:09 FilipeMaia

Awesome, thank you!

smarkesini avatar Sep 23 '19 20:09 smarkesini