[SciPy-User] Why does generic_filter coerce input to float64?
Juan Nunez-Iglesias
jni.soma at gmail.com
Mon Jan 12 22:51:35 EST 2015
Hi Eric,
Thanks for the response!
Changing it would be a very bad thing and probably break a lot of code out there. However, a kwarg would be most useful to me! Would a PR to add this be welcome?
At scikit-image, we converged on "preserve_dtype" as a slightly easier-to-parse name for such a kwarg. Thoughts?
Juan.
On Tue, Jan 13, 2015 at 12:26 AM, Moore, Eric (NIH/NIDDK) [F]
<eric.moore2 at nih.gov> wrote:
>> From: Juan Nunez-Iglesias [mailto:jni.soma at gmail.com]
>> Sent: Sunday, January 11, 2015 6:21 PM
>> To: scipy-user at scipy.org
>> Subject: [SciPy-User] Why does generic_filter coerce input to float64?
>>
>> Hi all,
>>
>> I'm wondering, why does ndimage.generic_filter cast the input array as a float
>> before passing it to the user-supplied function? I have at least one application
>> that requires integer input. For small integers, this is not a problem (other
>> than resulting in at least two unnecessary casts), but for big ones this will
>> cause a loss of precision.
>>
>> I'd love to contribute a patch but unfortunately I couldn't find the place in
>> the C-code where this happens.
>>
>> Thanks!
>>
>> Juan.
>>
> The cast happens in the expansion of the CASE_FILTER_POINT macro[1], which is used
> just below that in NI_GenericFilter.
> This looks like a deliberate choice though, so I don't think that we can just change
> it. One option might be to add this as a keep_dtype argument, which would default
> to false.
> Eric
> 1. https://github.com/scipy/scipy/blob/master/scipy/ndimage/src/ni_filters.c#L869
> _______________________________________________
> SciPy-User mailing list
> SciPy-User at scipy.org
> http://mail.scipy.org/mailman/listinfo/scipy-user
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.scipy.org/pipermail/scipy-user/attachments/20150112/d3851ee1/attachment.html>
More information about the SciPy-User
mailing list