Author: Matti Picus <[email protected]>
Branch: numpypy-ellipse-indexing
Changeset: r64063:2a7f866e80e8
Date: 2013-05-14 11:12 +0300
http://bitbucket.org/pypy/pypy/changeset/2a7f866e80e8/

Log:    test, fix for scalars

diff --git a/pypy/module/micronumpy/arrayimpl/scalar.py 
b/pypy/module/micronumpy/arrayimpl/scalar.py
--- a/pypy/module/micronumpy/arrayimpl/scalar.py
+++ b/pypy/module/micronumpy/arrayimpl/scalar.py
@@ -3,6 +3,7 @@
 from pypy.module.micronumpy.base import W_NDimArray, convert_to_array
 from pypy.module.micronumpy import support
 from pypy.interpreter.error import OperationError
+from pypy.interpreter.special import Ellipsis
 
 class ScalarIterator(base.BaseArrayIterator):
     def __init__(self, v):
@@ -73,7 +74,7 @@
         dtype = self.dtype.float_type or self.dtype
         if len(w_arr.get_shape()) > 0:
             raise OperationError(space.w_ValueError, space.wrap(
-                "could not broadcast input array from shape " + 
+                "could not broadcast input array from shape " +
                 "(%s) into shape ()" % (
                     ','.join([str(x) for x in w_arr.get_shape()],))))
         if self.dtype.is_complex_type():
@@ -102,7 +103,7 @@
         dtype = self.dtype.float_type
         if len(w_arr.get_shape()) > 0:
             raise OperationError(space.w_ValueError, space.wrap(
-                "could not broadcast input array from shape " + 
+                "could not broadcast input array from shape " +
                 "(%s) into shape ()" % (
                     ','.join([str(x) for x in w_arr.get_shape()],))))
         self.value = self.dtype.itemtype.composite(
@@ -119,7 +120,10 @@
                              space.wrap("scalars cannot be indexed"))
 
     def descr_setitem(self, space, _, w_idx, w_val):
-        raise OperationError(space.w_IndexError,
+        if isinstance(w_idx, Ellipsis):
+            self.value = self.dtype.coerce(space, w_val)
+        else:
+            raise OperationError(space.w_IndexError,
                              space.wrap("scalars cannot be indexed"))
 
     def setitem_index(self, space, idx, w_val):
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
@@ -1634,7 +1634,7 @@
         assert (zeros(1)[[]] == []).all()
 
     def test_int_array_index_setitem(self):
-        from numpypy import arange, zeros
+        from numpypy import arange, zeros, array
         a = arange(10)
         a[[3, 2, 1, 5]] = zeros(4, dtype=int)
         assert (a == [0, 0, 0, 0, 4, 0, 6, 7, 8, 9]).all()
@@ -1662,7 +1662,7 @@
         raises(ValueError, "array([1, 2])[array([True, False, True])] = [1, 2, 
3]")
 
     def test_ellipse_index(self):
-        from numpypy import arange
+        from numpypy import arange, array
         b = arange(24).reshape(2,3,4)
         b[...] = 100
         assert (b == 100).all()
@@ -1673,6 +1673,11 @@
         assert b.shape == b[...].shape
         assert (b == b[...]).all()
 
+        a = array(1)
+        a[...] = 100
+        assert (a == 100).all()
+        assert a == a[...]
+
     def test_weakref(self):
         import _weakref
         from numpypy import array
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to