[SciPy-User] Why does generic_filter coerce input to float64?

Moore, Eric (NIH/NIDDK) [F] eric.moore2 at nih.gov
Mon Jan 12 08:25:50 EST 2015


> 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





More information about the SciPy-User mailing list