Skip to content

Commit

Permalink
ENH: ndimage: specify unsafe casting so the default in NumPy can be t…
Browse files Browse the repository at this point in the history
…ightened
  • Loading branch information
Mark Wiebe committed Jun 15, 2011
1 parent 04fb79d commit dffed56
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
6 changes: 5 additions & 1 deletion scipy/ndimage/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,11 @@ def generic_gradient_magnitude(input, derivative, output = None,
*extra_arguments, **extra_keywords)
numpy.multiply(tmp, tmp, tmp)
output += tmp
numpy.sqrt(output, output)
# This allows the sqrt to work with a different default casting
if numpy.version.short_version > '1.6.1':
numpy.sqrt(output, output, casting='unsafe')
else:
numpy.sqrt(output, output)
else:
output[...] = input[...]
return return_value
Expand Down
4 changes: 2 additions & 2 deletions scipy/ndimage/tests/test_ndimage.py
Original file line number Diff line number Diff line change
Expand Up @@ -669,7 +669,7 @@ def test_gaussian_gradient_magnitude01(self):
output = ndimage.gaussian_gradient_magnitude(array,
1.0)
expected = tmp1 * tmp1 + tmp2 * tmp2
numpy.sqrt(expected, expected)
expected = numpy.sqrt(expected).astype(type)
assert_array_almost_equal(expected, output)

def test_gaussian_gradient_magnitude02(self):
Expand All @@ -684,7 +684,7 @@ def test_gaussian_gradient_magnitude02(self):
ndimage.gaussian_gradient_magnitude(array, 1.0,
output)
expected = tmp1 * tmp1 + tmp2 * tmp2
numpy.sqrt(expected, expected)
expected = numpy.sqrt(expected).astype(type)
assert_array_almost_equal(expected, output)

def test_generic_gradient_magnitude01(self):
Expand Down

0 comments on commit dffed56

Please sign in to comment.