Commits

mattip committed a0980f7

flesh out ScalarIterator so no 'if arr.is_scalar()' everywhere

  • Participants
  • Parent commits 9fb8098

Comments (0)

Files changed (1)

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

 class ScalarIterator(base.BaseArrayIterator):
     def __init__(self, v):
         self.v = v
+        self.called_once = False
 
     def next(self):
-        pass
+        self.called_once = True
 
     def getitem(self):
-        return self.v
+        return self.v.get_scalar_value()
 
     def setitem(self, v):
-        raise Exception("Don't call setitem on scalar iterators")
+        self.v.set_scalar_value(v)
 
     def done(self):
-        raise Exception("should not call done on scalar")
+        return self.called_once
 
     def reset(self):
         pass
         return []
 
     def create_iter(self, shape=None):
-        return ScalarIterator(self.value)
+        return ScalarIterator(self)
 
     def get_scalar_value(self):
         return self.value