Written with Stephan Hoyer after discussion with Stefan Van der Walt, Charles Harris, Matti Picus, and Jaime Frio
mrocklin
changed the title
Add first draft of NEP 0016: array function protocol
NEP: Array function protocol
Closed
| .. code:: python | ||
|
|
||
| def broadcast_to(array, shape, subok=False): | ||
| success, value = do_array_function_dance( |
| 2. Are all arguments of a type that we know how to handle? | ||
|
|
||
| If these conditions hold, ``__array_function__`` should return | ||
| implementation for ``func(*args, **kwargs)``. Otherwise, it should |
| ``__array_function__`` attribute on those inputs, and call those | ||
| methods appropriately until one succeeds. | ||
|
|
||
| This is one additional function of moderate complexity. |
| .. code:: python | ||
|
|
||
| def broadcast_to(array, shape, subok=False): | ||
| success, value = do_array_function_dance( |
| (Autograd, Tangent), higher order array factorizations (TensorLy), etc. | ||
| that add additional functionality on top of the Numpy API. | ||
|
|
||
| We would like to be able to use these libraries together, for example we |
Closed
| ``__array_function__``. | ||
|
|
||
| This protocol is intended to be a catch-all for NumPy functionality that | ||
| is not covered by existing protocols, like reductions (like ``np.sum``) |
| would only include these as keyword arguments when they have changed | ||
| from default values. This is similar to `what NumPy already has | ||
| done <https://github.com/numpy/numpy/blob/v1.14.2/numpy/core/fromnumeric.py#L1865-L1867>`__, | ||
| e.g., for the optional ``keepdims`` argument in ``sum``: |
| .. code:: python | ||
|
|
||
| def broadcast_to(array, shape, subok=False): | ||
| success, value = do_array_function_dance( |
Closed
mhvk
mentioned this pull request
Closed
okuta
mentioned this pull request
Closed
Open