[SciPy-Dev] Change the return of ndimage functions

Jaime Fernández del Río jaime.frio at gmail.com
Thu Feb 22 15:36:24 EST 2018


Hi,

For some odd reason, several ndimage functions only return the output array
if it has been allocated by the function itself, not if you have passed a
preallocated array to the function, e.g.:

ndimage.correlate1d([1, 2, 3], [1, 1, 1])  # returns [4, 6, 8]

out = np.empty(3)
ndimage.correlate1d([1, 2, 3], [1, 1, 1], output=out)  # returns None (but
writes [4, 6, 8] to out)


I find this to be an annoying, unintuitive behaviour, that differs from
what e.g. numpy ufuncs do, and that often requires special handling, see
e.g. the review comments in #8455 <https://github.com/scipy/scipy/pull/8455>.
It is furthermore not consistently implemented, as several functions do
return the output array always.
I have submitted #8461 <https://github.com/scipy/scipy/pull/8461> changing
this behaviour so that the output array is always returned, regardless if
it was given by the user or allocated by the function. It probably says
more about the poor coverage of the tests than anything else, but the
change did not make any of the current tests fail.

I doubt this change will be problematic to any user, but it is indeed a
change to a longstanding, documented behavior, so it probably deserves more
discussion than would happen in the PR alone. Any objections anyone?

Jaime

-- 
(\__/)
( O.o)
( > <) Este es Conejo. Copia a Conejo en tu firma y ayúdale en sus planes
de dominación mundial.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/scipy-dev/attachments/20180222/2e263269/attachment.html>


More information about the SciPy-Dev mailing list