Author: Maciej Fijalkowski <[email protected]>
Branch: numpy-back-to-applevel
Changeset: r51809:ae72e452c1fc
Date: 2012-01-26 21:54 +0200
http://bitbucket.org/pypy/pypy/changeset/ae72e452c1fc/
Log: make tests pass with -A and return scalars on zeros(()). A bit hard
to test without is_scalar, but zeros is going back to applevel at
some point soon
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
@@ -1250,6 +1250,8 @@
space.call_function(space.gettypefor(interp_dtype.W_Dtype), w_dtype)
)
size, shape = _find_size_and_shape(space, w_size)
+ if not shape:
+ return scalar_w(space, dtype, space.wrap(0))
return space.wrap(W_NDimArray(size, shape[:], dtype=dtype))
def ones(space, w_size, w_dtype=None):
@@ -1258,6 +1260,8 @@
)
size, shape = _find_size_and_shape(space, w_size)
+ if not shape:
+ return scalar_w(space, dtype, space.wrap(1))
arr = W_NDimArray(size, shape[:], dtype=dtype)
one = dtype.box(1)
arr.dtype.fill(arr.storage, one, 0, size)
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
@@ -229,6 +229,7 @@
# And check that changes stick.
a[13] = 5.3
assert a[13] == 5.3
+ assert zeros(()).shape == ()
def test_size(self):
from _numpypy import array
@@ -388,6 +389,7 @@
assert b.shape == (5,)
c = a[:3]
assert c.shape == (3,)
+ assert array([]).shape == (0,)
def test_set_shape(self):
from _numpypy import array, zeros
@@ -1128,7 +1130,7 @@
assert _numpypy.array([[1], [2], [3]]).shape == (3, 1)
assert len(_numpypy.zeros((3, 1, 2))) == 3
raises(TypeError, len, _numpypy.zeros(()))
- raises(ValueError, _numpypy.array, [[1, 2], 3])
+ raises(ValueError, _numpypy.array, [[1, 2], 3], dtype=float)
def test_getsetitem(self):
import _numpypy
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit