Author: Brian Kearns <bdkea...@gmail.com> Branch: Changeset: r67821:07b43a29d735 Date: 2013-11-04 01:07 -0500 http://bitbucket.org/pypy/pypy/changeset/07b43a29d735/
Log: fix complex cast on complex scalar diff --git a/pypy/module/micronumpy/interp_boxes.py b/pypy/module/micronumpy/interp_boxes.py --- a/pypy/module/micronumpy/interp_boxes.py +++ b/pypy/module/micronumpy/interp_boxes.py @@ -339,6 +339,10 @@ descr__new__, _get_dtype, descr_reduce = new_dtype_getter("float64") class W_ComplexFloatingBox(W_InexactBox): + def descr_complex(self, space): + assert isinstance(self, ComplexBox) + return space.wrap(complex(self.real, self.imag)) + def descr_get_real(self, space): dtype = self._COMPONENTS_BOX._get_dtype(space) box = self.convert_real_to(dtype) @@ -644,6 +648,7 @@ __module__ = "numpypy", __new__ = interp2app(W_Complex64Box.descr__new__.im_func), __reduce__ = interp2app(W_Complex64Box.descr_reduce), + __complex__ = interp2app(W_ComplexFloatingBox.descr_complex), real = GetSetProperty(W_ComplexFloatingBox.descr_get_real), imag = GetSetProperty(W_ComplexFloatingBox.descr_get_imag), ) @@ -652,6 +657,7 @@ __module__ = "numpypy", __new__ = interp2app(W_Complex128Box.descr__new__.im_func), __reduce__ = interp2app(W_Complex128Box.descr_reduce), + __complex__ = interp2app(W_ComplexFloatingBox.descr_complex), real = GetSetProperty(W_ComplexFloatingBox.descr_get_real), imag = GetSetProperty(W_ComplexFloatingBox.descr_get_imag), ) @@ -667,6 +673,7 @@ __module__ = "numpypy", __new__ = interp2app(W_ComplexLongBox.descr__new__.im_func), __reduce__ = interp2app(W_ComplexLongBox.descr_reduce), + __complex__ = interp2app(W_ComplexFloatingBox.descr_complex), real = GetSetProperty(W_ComplexFloatingBox.descr_get_real), imag = GetSetProperty(W_ComplexFloatingBox.descr_get_imag), ) diff --git a/pypy/module/micronumpy/test/dummy_module.py b/pypy/module/micronumpy/test/dummy_module.py --- a/pypy/module/micronumpy/test/dummy_module.py +++ b/pypy/module/micronumpy/test/dummy_module.py @@ -5,7 +5,9 @@ ufunc = type(sin) types = ['bool8', 'byte', 'ubyte', 'short', 'ushort', 'longlong', 'ulonglong', - 'single', 'longfloat', 'longdouble', 'csingle', 'cfloat', 'void'] + 'single', 'double', 'longfloat', 'longdouble', + 'csingle', 'cdouble', 'cfloat', 'clongdouble', + 'void'] for t in ('int', 'uint'): for s in (8, 16, 32, 64, 'p'): types.append(t + str(s)) diff --git a/pypy/module/micronumpy/test/test_scalar.py b/pypy/module/micronumpy/test/test_scalar.py --- a/pypy/module/micronumpy/test/test_scalar.py +++ b/pypy/module/micronumpy/test/test_scalar.py @@ -63,3 +63,9 @@ assert value.itemsize == 8 assert value.shape == () assert value.ndim == 0 + + def test_complex_scalar_complex_cast(self): + import numpy as np + for tp in [np.csingle, np.cdouble, np.clongdouble]: + x = tp(1+2j) + assert complex(x) == 1+2j _______________________________________________ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit