Overload-NumPy Documentation#
numpy
offers powerful methods to allow arguments of numpy
functions (and
ufunc
objects) to define how a given function operates on them. The details
are specified in NEP13 and NEP18, but in summary: normally numpy
only works
on an ndarray
but with NEP13/NEP18 for a custom object, users can register
overrides for a numpy
function and then use that function on that object (a
quick example is outlined below). Plugging into the numpy
framework is
convenient both for developers – to let numpy
take care of the actual math –
and users – who get many things, not least of which is a familiar API. If all
this sounds great, that’s because it is. However, if you’ve read NEP13/NEP18
then you know that making the numpy
bridge to your custom object and
registering overrides is non-trivial. That’s where overload_numpy
comes in.
overload_numpy
offers convenient base classes for the numpy
bridge and
powerful methods to register overrides for functions, ufunc
objects, and even
ufunc
methods (e.g. .accumulate()
). The library is fully typed and
(almost) fully c
-transpiled for speed.
from dataclasses import dataclass
import numpy as np
@dataclass
class ArrayWrapper:
x: np.ndarray
... # lot's of non-trivial implementation details
aw = ArrayWrapper(np.arange(10))
np.add(aw, aw) # returns ArrayWrapper([0, 2, ...])
This package is being actively developed in a public repository on GitHub, and we are always looking for new contributors! No contribution is too small, so if you have any trouble with this code, find a typo, or have requests for new content (tutorials or features), open an issue on GitHub.
Contributors#
Main author: Nathaniel Starkman (@nstarman)
All contributors (alphabetical last name):
Nathaniel Starkman