1. Pypy
  2. Untitled project
  3. pypy

Commits

mattip  committed 2a7f866

test, fix for scalars

  • Participants
  • Parent commits 217b2f1
  • Branches numpypy-ellipse-indexing

Comments (0)

Files changed (2)

File pypy/module/micronumpy/arrayimpl/scalar.py

View file
 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):
         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():
         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(
                              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):

File pypy/module/micronumpy/test/test_numarray.py

View file
         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()
         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()
         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