-
-
Notifications
You must be signed in to change notification settings - Fork 983
Closed
Description
The Numpy __array_ufunc__ protocol allows projects to use many of the Numpy functions to drive their own data structures. Here is a small example with dask.array.
In [1]: import dask.array as da
In [2]: x = da.arange(100, chunks=(10,))
In [3]: x
Out[3]: dask.array<arange, shape=(100,), dtype=int64, chunksize=(10,)>
In [4]: import numpy as np
In [5]: np.exp(x) # note that this returns a dask array
Out[5]: dask.array<exp, shape=(100,), dtype=float64, chunksize=(10,)>
In [6]: np.sum(np.exp(x))
Out[6]: dask.array<sum-aggregate, shape=(), dtype=float64, chunksize=()>
In [7]: _.compute()
Out[7]: 1.5644215618731406e+43This provides a protocol for downstream projects to write code that works independently of the choice of ndarray data structures, at least for a subset of the NumPy API. The Numpy core team seems dedicated to increasing this subset in the near future.
It would be useful for CuPy to also implement this protocol to improve interoperation with the rest of the ecosystem.
ericmjlericmjlericmjl and hameerabbasiericmjl and mitmul
Metadata
Metadata
Assignees
Labels
No labels