Use safe_as_int to check provided output shape

This commit is contained in:
Stefan van der Walt
2014-05-08 19:28:29 +02:00
parent b68b14f025
commit a9dcdc3713
4 changed files with 11 additions and 5 deletions
@@ -3,7 +3,7 @@ import numpy as np
__all__ = ['_safe_as_int']
def _safe_as_int(val, atol=1e-7):
def safe_as_int(val, atol=1e-3):
"""
Attempt to safely cast values to integer format.
+3 -1
View File
@@ -5,8 +5,10 @@ import sys
import six
from ._warnings import all_warnings
from ._safe_as_int import safe_as_int
__all__ = ['deprecated', 'get_bound_method_class', 'all_warnings']
__all__ = ['deprecated', 'get_bound_method_class', 'all_warnings',
'safe_as_int']
class skimage_deprecation(Warning):
+2 -2
View File
@@ -4,7 +4,7 @@ import warnings
import numpy as np
from scipy import ndimage, spatial
from skimage._shared.utils import get_bound_method_class
from skimage._shared.utils import get_bound_method_class, safe_as_int
from skimage.util import img_as_float
from ._warps_cy import _warp_fast
@@ -1078,7 +1078,7 @@ def warp(image, inverse_map=None, map_args={}, output_shape=None, order=1,
if output_shape is None:
output_shape = ishape
else:
output_shape = np.array(output_shape, dtype=int)
output_shape = safe_as_int(output_shape)
out = None
+5 -1
View File
@@ -250,7 +250,11 @@ def test_inverse():
def test_slow_warp_nonint_oshape():
image = np.random.random((5, 5))
warp(image, lambda xy: xy, output_shape=(13.1, 19.5))
assert_raises(ValueError, warp, image, lambda xy: xy,
output_shape=(13.1, 19.5))
warp(image, lambda xy: xy, output_shape=(13.0001, 19.9999))
if __name__ == "__main__":