Author: Maciej Fijalkowski <[email protected]>
Branch:
Changeset: r50983:ac51513392d3
Date: 2012-01-03 11:49 +0200
http://bitbucket.org/pypy/pypy/changeset/ac51513392d3/
Log: (mikefc) add an ndim attribute
diff --git a/pypy/module/micronumpy/interp_numarray.py
b/pypy/module/micronumpy/interp_numarray.py
--- a/pypy/module/micronumpy/interp_numarray.py
+++ b/pypy/module/micronumpy/interp_numarray.py
@@ -380,6 +380,9 @@
def descr_get_dtype(self, space):
return space.wrap(self.find_dtype())
+ def descr_get_ndim(self, space):
+ return space.wrap(len(self.shape))
+
@jit.unroll_safe
def descr_get_shape(self, space):
return space.newtuple([space.wrap(i) for i in self.shape])
@@ -1185,6 +1188,7 @@
shape = GetSetProperty(BaseArray.descr_get_shape,
BaseArray.descr_set_shape),
size = GetSetProperty(BaseArray.descr_get_size),
+ ndim = GetSetProperty(BaseArray.descr_get_ndim),
T = GetSetProperty(BaseArray.descr_get_transpose),
flat = GetSetProperty(BaseArray.descr_get_flatiter),
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
@@ -179,6 +179,19 @@
ar = array(range(5))
assert type(ar) is type(ar + ar)
+ def test_ndim(self):
+ from numpypy import array
+ x = array(0.2)
+ assert x.ndim == 0
+ x = array([1,2])
+ assert x.ndim == 1
+ x = array([[1,2], [3,4]])
+ assert x.ndim == 2
+ x = array([[[1,2], [3,4]], [[5,6], [7,8]] ])
+ assert x.ndim == 3
+ # numpy actually raises an AttributeError, but numpypy raises an
AttributeError
+ raises (TypeError, 'x.ndim=3')
+
def test_init(self):
from numpypy import zeros
a = zeros(15)
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit