[Numpy-discussion] heads up: gufuncs on empty arrays and NpyIter removal of empty axis

Sebastian Berg sebastian at sipsolutions.net
Sun Mar 26 09:53:51 EDT 2017

Hi all,

just a small heads up for gufunc hackers and low level iterator users.
We will probably very soon put in a commit into master that will allow
the removal of empty axis from NpyIter/nditer, effectively removing the

"ValueError: cannot remove a zero-sized axis from an iterator"

and allowing:

arr = np.zeros((100, 0))
it = np.nditer((arr,),
               flags=["zerosize_ok", "multi_index"])

As a follow up step, we also allow that gufuncs may be called with
empty inner loop sizes. In some cases that may mean that your gufuncs
may need special handling for lets say:

arr = np.zeros((100, 0))  # note the 0 dimension.

If this creates problems for you, please tell, so that we can slow down
or undo the change. As an example, we have a matrix_multiply gufunc for
testing purpose, which did not zero out the output for the case of
`matrix_multiply(np.ones((10, 0)), np.ones((0, 10)))`. So this could
turn code that errored out for weird reasons into wrong results in rare

- Sebastian
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 801 bytes
Desc: This is a digitally signed message part
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20170326/ecf8eb75/attachment.sig>

More information about the NumPy-Discussion mailing list