mrocklin · GitHub

@mrocklin

Written with Stephan Hoyer after discussion with Stefan Van der Walt,
Charles Harris, Matti Picus, and Jaime Frio

@mrocklin mrocklin changed the title Add first draft of NEP 0016: array function protocol NEP: Array function protocol

May 29, 2018

@mrocklin

shoyer

@shoyer

mattip

mattip

eric-wieser


.. code-block:: python

def __array_function__(self, func, types, *args, **kwargs)

Closed

hameerabbasi

eric-wieser

.. code:: python

def broadcast_to(array, shape, subok=False):
success, value = do_array_function_dance(

hameerabbasi

@shoyer

hameerabbasi

@shoyer

hameerabbasi

@shoyer

mhvk

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

@mrocklin

@mrocklin

@mattip

mhvk

``__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``:

mhvk

.. code:: python

def broadcast_to(array, shape, subok=False):
success, value = do_array_function_dance(

Closed

@mhvk mhvk mentioned this pull request

Sep 19, 2018

Closed

@okuta okuta mentioned this pull request

Nov 13, 2018

Closed

Open

Read the original on github.com ↗