Author: Matti Picus <[email protected]>
Branch:
Changeset: r62562:b9c5e3df5a82
Date: 2013-03-20 13:11 -0700
http://bitbucket.org/pypy/pypy/changeset/b9c5e3df5a82/
Log: cleanups and small fixes of str-dtypes-improvement
diff --git a/pypy/module/micronumpy/arrayimpl/scalar.py
b/pypy/module/micronumpy/arrayimpl/scalar.py
--- a/pypy/module/micronumpy/arrayimpl/scalar.py
+++ b/pypy/module/micronumpy/arrayimpl/scalar.py
@@ -77,12 +77,9 @@
"(%s) into shape ()" % (
','.join([str(x) for x in w_arr.get_shape()],))))
if self.dtype.is_complex_type():
- #imag = dtype.itemtype.unbox(self.value.convert_imag_to(dtype))
- #val = dtype.itemtype.unbox(w_arr.get_scalar_value().
- # convert_to(dtype))
- #self.value = self.dtype.box_complex(val, imag)
- self.value =
self.dtype.itemtype.composite(w_arr.get_scalar_value().convert_to(dtype),
- self.value.convert_imag_to(dtype))
+ self.value = self.dtype.itemtype.composite(
+ w_arr.get_scalar_value().convert_to(dtype),
+ self.value.convert_imag_to(dtype))
else:
self.value = w_arr.get_scalar_value()
@@ -108,13 +105,9 @@
"could not broadcast input array from shape " +
"(%s) into shape ()" % (
','.join([str(x) for x in w_arr.get_shape()],))))
- #real = dtype.itemtype.unbox(self.value.convert_real_to(dtype))
- #val = dtype.itemtype.unbox(w_arr.get_scalar_value().
- # convert_to(dtype))
- #self.value = self.dtype.box_complex(real, val)
self.value = self.dtype.itemtype.composite(
self.value.convert_real_to(dtype),
- w_arr.get_scalar_value(),
+ w_arr.get_scalar_value().convert_to(dtype),
)
def descr_getitem(self, space, _, w_idx):
diff --git a/pypy/module/micronumpy/test/test_complex.py
b/pypy/module/micronumpy/test/test_complex.py
--- a/pypy/module/micronumpy/test/test_complex.py
+++ b/pypy/module/micronumpy/test/test_complex.py
@@ -526,17 +526,20 @@
a = array(complex(3.0, 4.0))
b = a.real
assert b == array(3)
+ assert a.imag == array(4)
a.real = 1024
a.imag = 2048
assert a.real == 1024 and a.imag == 2048
- assert a.imag == array(4)
assert b.dtype == dtype(float)
a = array(4.0)
b = a.imag
assert b == 0
assert b.dtype == dtype(float)
- raises(TypeError, 'a.imag = 1024')
- raises(ValueError, 'a.real = [1, 3]')
+ exc = raises(TypeError, 'a.imag = 1024')
+ assert str(exc.value).startswith("array does not have imaginary")
+ exc = raises(ValueError, 'a.real = [1, 3]')
+ assert str(exc.value) == \
+ "could not broadcast input array from shape (2) into shape ()"
a = array('abc')
assert str(a.real) == 'abc'
# numpy imag for flexible types returns self
@@ -610,8 +613,10 @@
assert repr(abs(complex(float('nan'), float('nan')))) == 'nan'
# numpy actually raises an AttributeError,
# but numpypy raises a TypeError
- raises((TypeError, AttributeError), 'c2.real = 10.')
- raises((TypeError, AttributeError), 'c2.imag = 10.')
+ exc = raises((TypeError, AttributeError), 'c2.real = 10.')
+ assert str(exc.value) == "readonly attribute"
+ exc = raises((TypeError, AttributeError), 'c2.imag = 10.')
+ assert str(exc.value) == "readonly attribute"
assert(real(c2) == 3.0)
assert(imag(c2) == 4.0)
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit