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.
From: Juan Nunez-Iglesias [mailto:jni.soma@gmail.com] Sent: Sunday, January 11, 2015 6:21 PM To: scipy-user@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#L8...
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@nih.gov> wrote:
From: Juan Nunez-Iglesias [mailto:jni.soma@gmail.com] Sent: Sunday, January 11, 2015 6:21 PM To: scipy-user@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#L8... _______________________________________________ SciPy-User mailing list SciPy-User@scipy.org http://mail.scipy.org/mailman/listinfo/scipy-user
From: Juan Nunez-Iglesias [mailto:jni.soma@gmail.com] Sent: Monday, January 12, 2015 10:52 PM To: SciPy Users List Subject: Re: [SciPy-User] Why does generic_filter coerce input to float64?
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.
Yes, I think so.
participants (2)
-
Juan Nunez-Iglesias
-
Moore, Eric (NIH/NIDDK) [F]