[pypy-commit] pypy numpypy-real-as-view: some tests pass
mattip
noreply at buildbot.pypy.org
Wed Jan 9 21:18:37 CET 2013
Author: mattip <matti.picus at gmail.com>
Branch: numpypy-real-as-view
Changeset: r59896:b36dcabcd239
Date: 2013-01-09 18:50 +0200
http://bitbucket.org/pypy/pypy/changeset/b36dcabcd239/
Log: some tests pass
diff --git a/pypy/module/micronumpy/arrayimpl/concrete.py b/pypy/module/micronumpy/arrayimpl/concrete.py
--- a/pypy/module/micronumpy/arrayimpl/concrete.py
+++ b/pypy/module/micronumpy/arrayimpl/concrete.py
@@ -222,21 +222,26 @@
return None
def get_real(self):
+ strides = self.get_strides()
+ backstrides = self.get_backstrides()
if self.dtype.is_complex_type():
- raise NotImplementedError('waiting for astype()')
- return SliceArray(self.start, self.get_strides(),
- self.get_backstrides(), self.get_shape(), self)
+ dtype = self.dtype.float_type
+ return SliceArray(self.start, strides, backstrides,
+ self.get_shape(), self, dtype=dtype)
+ return SliceArray(self.start, strides, backstrides,
+ self.get_shape(), self)
def get_imag(self):
+ strides = self.get_strides()
+ backstrides = self.get_backstrides()
if self.dtype.is_complex_type():
- raise NotImplementedError('waiting for astype()')
+ dtype = self.dtype.float_type
+ return SliceArray(self.start + dtype.get_size(), strides,
+ backstrides, self.get_shape(), self, dtype=dtype)
if self.dtype.is_flexible_type():
# numpy returns self for self.imag
- return SliceArray(self.start, self.get_strides(),
- self.get_backstrides(), self.get_shape(), self)
-
- strides, backstrides = support.calc_strides(self.get_shape(), self.dtype,
- self.order)
+ return SliceArray(self.start, strides, backstrides,
+ self.get_shape(), self)
impl = NonWritableArray(self.get_shape(), self.dtype, self.order, strides,
backstrides)
impl.fill(self.dtype.box(0))
diff --git a/pypy/module/micronumpy/interp_dtype.py b/pypy/module/micronumpy/interp_dtype.py
--- a/pypy/module/micronumpy/interp_dtype.py
+++ b/pypy/module/micronumpy/interp_dtype.py
@@ -136,7 +136,7 @@
return self.kind == SIGNEDLTR
def is_complex_type(self):
- return (self.num == 14 or self.num == 15 or self.num == 16)
+ return False
def is_bool_type(self):
return self.kind == BOOLLTR
@@ -155,6 +155,19 @@
def get_size(self):
return self.itemtype.get_element_size()
+class W_ComplexDtype(W_Dtype):
+
+ def __init__(self, itemtype, num, kind, name, char, w_box_type,
+ alternate_constructors=[], aliases=[],
+ fields=None, fieldnames=None, native=True, float_type=None):
+ W_Dtype.__init__(self, itemtype, num, kind, name, char, w_box_type,
+ alternate_constructors=[], aliases=[],
+ fields=None, fieldnames=None, native=True)
+ self.float_type = float_type
+
+ def is_complex_type(self):
+ return True
+
def dtype_from_list(space, w_lst):
lst_w = space.listview(w_lst)
fields = {}
@@ -413,15 +426,16 @@
alternate_constructors=[space.w_float],
aliases=["float"],
)
- self.w_complex64dtype = W_Dtype(
+ self.w_complex64dtype = W_ComplexDtype(
types.Complex64(),
num=14,
kind=COMPLEXLTR,
name="complex64",
char="F",
w_box_type = space.gettypefor(interp_boxes.W_Complex64Box),
+ float_type = self.w_float32dtype,
)
- self.w_complex128dtype = W_Dtype(
+ self.w_complex128dtype = W_ComplexDtype(
types.Complex128(),
num=15,
kind=COMPLEXLTR,
@@ -430,6 +444,7 @@
w_box_type = space.gettypefor(interp_boxes.W_Complex128Box),
alternate_constructors=[space.w_complex],
aliases=["complex"],
+ float_type = self.w_float64dtype,
)
if interp_boxes.long_double_size == 12:
self.w_float96dtype = W_Dtype(
@@ -443,7 +458,7 @@
)
self.w_longdouble = self.w_float96dtype
- self.w_complex192dtype = W_Dtype(
+ self.w_complex192dtype = W_ComplexDtype(
types.Complex192(),
num=16,
kind=COMPLEXLTR,
@@ -452,6 +467,7 @@
w_box_type = space.gettypefor(interp_boxes.W_Complex192Box),
alternate_constructors=[space.w_complex],
aliases=["clongdouble", "clongfloat"],
+ float_type = self.w_float96dtype,
)
self.w_clongdouble = self.w_complex192dtype
@@ -467,7 +483,7 @@
)
self.w_longdouble = self.w_float128dtype
- self.w_complex256dtype = W_Dtype(
+ self.w_complex256dtype = W_ComplexDtype(
types.Complex256(),
num=16,
kind=COMPLEXLTR,
@@ -476,6 +492,7 @@
w_box_type = space.gettypefor(interp_boxes.W_Complex256Box),
alternate_constructors=[space.w_complex],
aliases=["clongdouble", "clongfloat"],
+ float_type = self.w_float128dtype,
)
self.w_clongdouble = self.w_complex256dtype
else:
diff --git a/pypy/module/micronumpy/test/test_numarray.py b/pypy/module/micronumpy/test/test_numarray.py
--- a/pypy/module/micronumpy/test/test_numarray.py
+++ b/pypy/module/micronumpy/test/test_numarray.py
@@ -1360,10 +1360,14 @@
assert a[1] == b[1]
b[1] = 'xyz'
assert a[1] == 'xyz'
- a=array([1+1j, 2-3j])
- assert a.real[1] == 2
- a.real[1] = -20
- assert a[1].real == -20
+ a=array([[1+1j, 2-3j, 4+5j],[-6+7j, 8-9j, -2-1j]])
+ assert a.real[0,1] == 2
+ a.real[0,1] = -20
+ assert a[0,1].real == -20
+ b = a.imag
+ assert b[1,2] == -1
+ b[1,2] = 30
+ assert a[1,2].imag == 30
def test_tolist_scalar(self):
from _numpypy import int32, bool_
More information about the pypy-commit
mailing list