Add __array_function__ to dispatch NumPy funcs to dask-awkward#520
Add __array_function__ to dispatch NumPy funcs to dask-awkward#520supercoder-dev wants to merge 1 commit intodask-contrib:mainfrom
Conversation
martindurant
left a comment
There was a problem hiding this comment.
Could use tests.
However: isn't the purpose of array_function to return a numpy view on the data rather than (as with ufuncs) to apply the numpy idea to producing an array of our own type? Maybe I misunderstand.
| if func.__name__ in supported_funcs: | ||
| return supported_funcs[func.__name__](*args, **kwargs) | ||
| else: | ||
| return NotImplemented |
There was a problem hiding this comment.
| return NotImplemented | |
| return NotImplemented(str(func)) |
| import dask_awkward as dak | ||
|
|
||
| # List of supported functions | ||
| supported_funcs = { |
There was a problem hiding this comment.
Mildly prefer this as a global constant rather than in the function
|
I'd be a bit careful with this kind of dispatch. The numpy functions can have subtly different behaviors from their awkward counterparts. This mapping isn't very well defined for the arbitrary numpy functions (but is for ufuncs). It would almost be better to suggest converting to |
Add NumPy function dispatching to dask-awkward
This PR adds an array_function method to the Array class, allowing NumPy functions to be automatically redirected to their dask-awkward counterparts. It covers 38 common functions, making it easier to use NumPy-style operations with dask-awkward arrays.