pydata / sparse

Sparse multi-dimensional arrays for the PyData ecosystem
https://sparse.pydata.org
BSD 3-Clause "New" or "Revised" License
581 stars 123 forks source link

Add `matmul` example #701

Closed mtsokol closed 1 month ago

mtsokol commented 1 month ago

Hi @hameerabbasi,

This is the last example from your list that I wanted to add (for solve we dispatch to scipy.sparse):

matmul = lambda x, y: np.sum(x[:, None, :] * y.transpose((1, 0))[None, None, :], axis=2)
spmv = lambda x, y: np.sum(x * y[:, None], axis=1)
tensordot  # various axes
sddmm = lambda s, x, y: s.astype(bool) * (x @ y)
mttkrp = lambda b, c, d: sum(b[:, None, :, :] * d.transpose((1, 0))[None, :, None, :] * c.transpose((1, 0))[None, :, :, None], axis=(2, 3))
solve