Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ndimage.convolve should take weights' and cval's dtypes into account when determining the output dtype #10527

Open
anntzer opened this issue Jul 26, 2019 · 0 comments

Comments

@anntzer
Copy link
Contributor

anntzer commented Jul 26, 2019

If ndimage.convolve is passed input as integer array and weights or cval (with mode="constant") as floating point, the output buffer should be floating point, not integer.

Reproducing code example:

below the examples are with integer weights and floating point cval, but the issue is also present with just floating point weights.

In [8]: scipy.ndimage.convolve([1, 2, 3, 2, 1], [1, 1, 1], mode="constant", cval=0.1)                               
Out[8]: array([3, 6, 7, 6, 3])

In [9]: scipy.ndimage.convolve([1., 2., 3., 2., 1.], [1, 1, 1], mode="constant", cval=0.1)                          
Out[9]: array([3.1, 6. , 7. , 6. , 3.1])

and more spectacularly:

In [10]: scipy.ndimage.convolve([1, 2, 3, 2, 1], [1, 1, 1], mode="constant", cval=np.nan)                           
Out[10]: 
array([-9223372036854775808,                    6,                    7,
                          6, -9223372036854775808])

In [11]: scipy.ndimage.convolve([1., 2., 3., 2., 1.], [1, 1, 1], mode="constant", cval=np.nan)                      
Out[11]: array([nan,  6.,  7.,  6., nan])

Scipy/Numpy/Python version information:

1.3.0 1.17.0rc1 sys.version_info(major=3, minor=7, micro=3, releaselevel='final', serial=0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants