-
-
Notifications
You must be signed in to change notification settings - Fork 130
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Enh: Accept "duck arrays" for tensordot
#833
Comments
Unfortunately; it actually uses Numba under the hood (which only accepts NumPy arrays) to do the actual computation, doing this with Dask (or even NumPy without Numba) would be excruciatingly slow. However, we do support NumPy arrays inside the >>> import numpy as np; import sparse
>>> sp_arr = sparse.zeros((5, 5), dtype=sparse.float32)
>>> np_arr = np.zeros((5, 5), dtype=np.float32)
>>> sp_arr @ np_arr
array([[0., 0., 0., 0., 0.],
[0., 0., 0., 0., 0.],
[0., 0., 0., 0., 0.],
[0., 0., 0., 0., 0.],
[0., 0., 0., 0., 0.]], dtype=float32)
>>> np_arr @ sp_arr
array([[0., 0., 0., 0., 0.],
[0., 0., 0., 0., 0.],
[0., 0., 0., 0., 0.],
[0., 0., 0., 0., 0.],
[0., 0., 0., 0., 0.]], dtype=float32) I'd be happy to hear an alternative solution that would help XArray/this use-case but supporting duck arrays in |
Thanks, I suspected it might not be so simple. I think Dask is using The linked xarray issue has some workarounds to get Dask to initiate the multiplication, rather than sparse, so I will go back and ask if any of those could be incorporated into xarray. |
if the variant that works is implemented by |
That we can do -- can you open an issue for that? |
sorry, looks like that already happens (I think)? See sparse/sparse/numba_backend/_coo/core.py Lines 958 to 972 in 2bca00c
I'll have to look into why that is not triggered. Edit: maybe because the error is |
|
Right -- I just pushed a fix/release for |
yeah, forwarding to Tensordot can be dispatched through various |
Please describe the purpose of the new feature or describe the problem to solve.
Sparse's
tensordot
only allows multiplication between sparse arrays and either scipy sparse arrays or numpy ndarrays.It would be useful if other array-like objects were allowed.
For instance, in
xarray
, thedot
function can only multiply a sparseDataArray
and a daskDataArray
if the einsum/tensordot function from dask is used: pydata/xarray#9934Suggest a solution if possible.
The code for multiplying a
COO
matrix and anp.ndarray
in_dot
seems like it mostly relies on being able to infer the dtype, index, and create empty ndarrays, so it seems plausible that other array-like objects could be used here.I haven't tried to implement this though.
If you have tried alternatives, please describe them below.
No response
Additional information that may help us understand your needs.
Please see this issue for further discussion in the context of xarray: pydata/xarray#9934
The text was updated successfully, but these errors were encountered: