[SciPy-Dev] Change the return of ndimage functions

Stefan van der Walt stefanv at berkeley.edu
Fri Feb 23 01:13:33 EST 2018


On 22 February 2018 5:38:24 PM Ralf Gommers <ralf.gommers at gmail.com> wrote:

> On Thu, Feb 22, 2018 at 12:36 PM, Jaime Fernández del Río <
> jaime.frio at gmail.com> wrote:
>
>> 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?
>>
>
> Makes sense to me, no objections.

Same here.

Best regards
Stéfan
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/scipy-dev/attachments/20180222/223cacea/attachment.html>


More information about the SciPy-Dev mailing list