[pypy-commit] pypy numpy-subarrays: test, implement numpy-comatible base attribute

mattip noreply at buildbot.pypy.org
Fri May 17 11:01:55 CEST 2013


Author: Matti Picus <matti.picus at gmail.com>
Branch: numpy-subarrays
Changeset: r64248:ca3ad0ac48d3
Date: 2013-05-17 12:00 +0300
http://bitbucket.org/pypy/pypy/changeset/ca3ad0ac48d3/

Log:	test, implement numpy-comatible base attribute

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
@@ -65,6 +65,10 @@
         self.float_type = None
         self.shape = list(shape)
         self.subdtype = subdtype
+        if not subdtype:
+            self.base = self
+        else:
+            self.base = subdtype.base
 
     @specialize.argtype(1)
     def box(self, value):
@@ -115,6 +119,9 @@
     def descr_get_alignment(self, space):
         return space.wrap(self.itemtype.alignment)
 
+    def descr_get_base(self, space):
+        return space.wrap(self.base)
+
     def descr_get_subdtype(self, space):
         return space.newtuple([space.wrap(self.subdtype), self.descr_get_shape(space)])
 
@@ -423,6 +430,7 @@
     fields = GetSetProperty(W_Dtype.descr_get_fields),
     names = GetSetProperty(W_Dtype.descr_get_names),
     subdtype = GetSetProperty(W_Dtype.descr_get_subdtype),
+    base = GetSetProperty(W_Dtype.descr_get_base),
 )
 W_Dtype.typedef.acceptable_as_base_class = False
 
diff --git a/pypy/module/micronumpy/test/test_dtypes.py b/pypy/module/micronumpy/test/test_dtypes.py
--- a/pypy/module/micronumpy/test/test_dtypes.py
+++ b/pypy/module/micronumpy/test/test_dtypes.py
@@ -778,6 +778,7 @@
         assert d.num == 20
         assert d.itemsize == 20
         assert d.kind == 'V'
+        assert d.base == d
         assert d.type is void
         assert d.char == 'V'
         assert d.names == ("x", "y", "z", "value")
@@ -808,7 +809,8 @@
         assert dt.shape == (10,)
         assert dt.kind == 'V'
         assert dt.fields == None
-        assert dt.subdtype == (dtype("float64"), (10,))
+        assert dt.subdtype == (dtype(float), (10,))
+        assert dt.base == dtype(float)
 
 class AppTestNotDirect(BaseNumpyAppTest):
     def setup_class(cls):


More information about the pypy-commit mailing list