Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

BUG: ndimage: Do not attempt to zoom to infinity (closes #1419).

  • Loading branch information...
commit 9b5db2cf33924724bb85d2fa391b4e69d931a6b0 1 parent a47f815
@stefanv stefanv authored
View
9 scipy/ndimage/interpolation.py
@@ -511,7 +511,14 @@ def zoom(input, zoom, output=None, order=3, mode='constant', cval=0.0,
filtered = input
zoom = _ni_support._normalize_sequence(zoom, input.ndim)
output_shape = tuple([int(ii * jj) for ii, jj in zip(input.shape, zoom)])
- zoom = (numpy.array(input.shape)-1)/(numpy.array(output_shape,float)-1)
+
+ zoom_div = numpy.array(output_shape, float) - 1
+ zoom = (numpy.array(input.shape) - 1) / zoom_div
+
+ # Zooming to infinity is unpredictable, so just choose
+ # zoom factor 1 instead
+ zoom[numpy.isinf(zoom)] = 1
+
output, return_value = _ni_support._get_output(output, input,
shape=output_shape)
zoom = numpy.asarray(zoom, dtype = numpy.float64)
View
10 scipy/ndimage/tests/test_ndimage.py
@@ -2125,6 +2125,16 @@ def test_zoom_affine01(self):
(6, 8), order=order)
assert_array_almost_equal(out[::2, ::2], data)
+ def test_zoom_infinity(self):
+ """Ticket #1419"""
+ err = numpy.seterr(divide='ignore')
+
+ try:
+ dim = 8
+ ndimage.zoom(numpy.zeros((dim, dim)), 1./dim, mode='nearest')
+ finally:
+ numpy.seterr(**err)
+
def test_rotate01(self):
"rotate 1"
data = numpy.array([[0, 0, 0, 0],
Please sign in to comment.
Something went wrong with that request. Please try again.