Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Allow strict casting #38

Closed
wants to merge 2 commits into from

3 participants

Mark Wiebe Charles Harris Ralf Gommers
Mark Wiebe

This fixes a bug in netcdf, and tweaks ndimage so that it will work with a tighter default casting policy in NumPy. The errors are discussed here:

http://mail.scipy.org/pipermail/numpy-discussion/2011-June/056632.html

Mark Wiebe added some commits
Mark Wiebe BUG: netcdf: was treating the NumPy typecode as if it were a NumPy kind
Typecodes are always one character, and kinds are added with a size.
'd' is the same as 'f8', for example. The code was producing 'd8',
which is invalid.
04fb79d
Mark Wiebe ENH: ndimage: specify unsafe casting so the default in NumPy can be t…
…ightened
dffed56
Charles Harris
Collaborator

Looks OK to me.

Ralf Gommers
Owner

Tested with 1.6.1rc2 and 2.0.0-latest and committed. Thanks Mark.

Ralf Gommers rgommers closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jun 15, 2011
  1. BUG: netcdf: was treating the NumPy typecode as if it were a NumPy kind

    Mark Wiebe authored
    Typecodes are always one character, and kinds are added with a size.
    'd' is the same as 'f8', for example. The code was producing 'd8',
    which is invalid.
This page is out of date. Refresh to see the latest.
14 scipy/io/netcdf.py
View
@@ -454,11 +454,7 @@ def _write_values(self, values):
if isinstance(sample, class_): break
typecode, size = TYPEMAP[nc_type]
- if typecode is 'c':
- dtype_ = '>c'
- else:
- dtype_ = '>%s' % typecode
- if size > 1: dtype_ += str(size)
+ dtype_ = '>%s' % typecode
values = asarray(values, dtype=dtype_)
@@ -627,11 +623,7 @@ def _read_var(self):
begin = [self._unpack_int, self._unpack_int64][self.version_byte-1]()
typecode, size = TYPEMAP[nc_type]
- if typecode is 'c':
- dtype_ = '>c'
- else:
- dtype_ = '>%s' % typecode
- if size > 1: dtype_ += str(size)
+ dtype_ = '>%s' % typecode
return name, dimensions, shape, attributes, typecode, size, dtype_, begin, vsize
@@ -646,7 +638,7 @@ def _read_values(self):
self.fp.read(-count % 4) # read padding
if typecode is not 'c':
- values = fromstring(values, dtype='>%s%d' % (typecode, size))
+ values = fromstring(values, dtype='>%s' % typecode)
if values.shape == (1,): values = values[0]
else:
values = values.rstrip(asbytes('\x00'))
6 scipy/ndimage/filters.py
View
@@ -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
4 scipy/ndimage/tests/test_ndimage.py
View
@@ -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):
@@ -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):
Something went wrong with that request. Please try again.