It depends, I’d say you’re already taking on a big chunk of work, so perhaps design your wrapping of numpy
such that it can be added to later? I have not seen too much interest in pytorch/cupy/jax + units, so I’m not sure if that extra generality will pay off from the start.
If you’re going to be writing functions that are in the Array API in your library (as your funp.add
example indicates), then you may as well adhere to the function definitions in the array API standard rather than anything else. And at that point, “being an array API implementor” is a matter of adding the __array_namespace__
method.
That said, you will probably want to implement more than is in the standard. There’s no reason that’s not okay, you can add anything you need.
It’s not easy to figure out what your implementation will look like, so it’s hard to say what the “blessed way” is. Not that there even is such a thing perhaps; there’s multiple options with different trade-offs. Interoperability with NumPy — NumPy v2.0.dev0 Manual captures quite a few.
Inheriting from numpy.ndarray
is possible, but a little fragile and perhaps the least appealing of all the options.