-
Notifications
You must be signed in to change notification settings - Fork 31
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
Bh107 wishlist #616
Comments
I am planning to contribute an implementation leveraging import os
os.environ['NUMPY_EXPERIMENTAL_ARRAY_FUNCTION'] = '1'
import numpy as np
class MyArray:
def __init__(self, array):
self.array = array
def __array_function__(self, func, types, args, kwargs):
cls = self.__class__
args = (a.array if isinstance(a, cls) else a for a in args)
return cls(func(*args, **kwargs))
def __array_ufunc__(self, ufunc, method, *inputs, **kwargs):
cls = self.__class__
inputs = (a.array if isinstance(a, cls) else a for a in inputs)
return cls(getattr(ufunc, method)(*inputs, **kwargs))
def __repr__(self):
if np.isscalar(self.array):
return repr(self.array)
return self.__class__.__name__ + repr(self.array)[5:] Then, you can use it as >>> a = MyArray(np.random.rand(10))
>>> np.divide(a, np.ones(10))
MyArray([0.22199372, 0.14071593, 0.45037375, 0.2900408 , 0.28482036,
0.1315491 , 0.65760868, 0.29693582, 0.780299 , 0.57618724])
>>> np.add.accumulate(a)
MyArray([0.22199372, 0.36270965, 0.8130834 , 1.1031242 , 1.38794456,
1.51949366, 2.17710234, 2.47403816, 3.25433716, 3.8305244 ])
>>> np.argsort(a)
MyArray([5, 1, 0, 4, 3, 7, 2, 9, 6, 8])
>>> np.allclose(a, np.ones(100))
False That way, we would get sane default implementations for virtually all NumPy functions without |
That would be great! |
This is a growing list of what I am personally missing from the new
bh107
interface.I will probably add some of these in a PR, but it is unlikely that I'll find the time to do them all.
Showstoppers
(critical features I would need to adopt bh107 in Veros)
Cumulative functions are missing, e.g.
add.accumulate
/cumsum
Element-wise comparisons are missing:
Boolean masking is missing:
Creating empty axes with
newaxis
/None
doesn't work:Missing ufuncs:
mean
,std
Quality of Life
__repr__
onBhArray
np.array(bh_array)
bh_array.sum()
sum
instead ofadd.reduce
,abs
instead ofabsolute
The text was updated successfully, but these errors were encountered: