On Tue, Oct 31, 2017 at 3:15 PM, William Sheffler email@example.com wrote:
Thank you all kindly for your responses! Based on your encouragement, I will pursue an ndarray subclass / __array_ufunc__ implementation. I had been toying with np.set_numeric_ops, which is less than ideal (for example, np.ndarray.around segfaults if I use set_numeric_ops in any way).
A second question: very broadly speaking, how much 'pain' can I expect trying to use an np.ndarray subclass in the broader python scientific computing ecosystem, and is there general consensus that projects 'should' support ndarray subclasses?
That depends on what the ndarray subclass does, which methods it overrides, and what the function uses. My guess is that most general code uses np.asarray and then assume it behaves like an ndarray, the actual behavior will be what non ufuncs are doing with it, e.g. what does np.linalg.pinv(my_array) @ np.ones(len(my_array)) return.
We spent a *long time* sorting out the messy details of __array_ufunc__
, especially for handling interactions between different types, e.g., between numpy arrays, non-numpy array-like objects, builtin Python objects, objects that override arithmetic to act in non-numpy-like ways, and of course subclasses of all the above.
We hope that we have it right this time, but as we wrote in the NumPy
1.13 release notes "The API is provisional, we do not yet guarantee backward compatibility as modifications may be made pending feedback." That said, let's give it a try!
If any changes are necessary, I expect it would likely relate to how we
handle interactions between different types. That's where we spent the majority of the design effort, but debate is a poor substitute for experience. I would be very surprised if the basic cases (one argument or two arguments of the same type) need any changes.
NumPy-Discussion mailing list NumPy-Discussion@python.org https://mail.python.org/mailman/listinfo/numpy-discussion