Author: Brian Kearns <[email protected]>
Branch: numpy-refactor
Changeset: r69474:4a9b7ee9934d
Date: 2014-02-26 15:17 -0500
http://bitbucket.org/pypy/pypy/changeset/4a9b7ee9934d/
Log: fix str/repr of scalar views
diff --git a/pypy/module/micronumpy/arrayimpl/concrete.py
b/pypy/module/micronumpy/arrayimpl/concrete.py
--- a/pypy/module/micronumpy/arrayimpl/concrete.py
+++ b/pypy/module/micronumpy/arrayimpl/concrete.py
@@ -337,7 +337,7 @@
r[0], r[1], shape)
if not require_index:
return iter.ConcreteArrayIterator(self)
- if len(self.get_shape()) == 1:
+ if len(self.get_shape()) <= 1:
return iter.OneDimViewIterator(self, self.start,
self.get_strides(),
self.get_shape())
@@ -440,7 +440,7 @@
backward_broadcast)
return iter.MultiDimViewIterator(self, self.start,
r[0], r[1], shape)
- if len(self.get_shape()) == 1:
+ if len(self.get_shape()) <= 1:
return iter.OneDimViewIterator(self, self.start,
self.get_strides(),
self.get_shape())
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
@@ -292,9 +292,9 @@
def create_iter(self, shape=None, backward_broadcast=False,
require_index=False):
assert isinstance(self.implementation, BaseConcreteArray)
- return self.implementation.create_iter(shape=shape,
- backward_broadcast=backward_broadcast,
- require_index=require_index)
+ return self.implementation.create_iter(
+ shape=shape, backward_broadcast=backward_broadcast,
+ require_index=require_index)
def create_axis_iter(self, shape, dim, cum):
return self.implementation.create_axis_iter(shape, dim, cum)
diff --git a/pypy/module/micronumpy/iter.py b/pypy/module/micronumpy/iter.py
--- a/pypy/module/micronumpy/iter.py
+++ b/pypy/module/micronumpy/iter.py
@@ -211,9 +211,15 @@
def __init__(self, array, start, strides, shape):
self.array = array
self.offset = start
- self.skip = strides[0]
self.index = 0
- self.size = shape[0]
+ assert len(strides) == len(shape)
+ if len(shape) == 0:
+ self.skip = array.dtype.elsize
+ self.size = 1
+ else:
+ assert len(shape) == 1
+ self.skip = strides[0]
+ self.size = shape[0]
def next(self):
self.offset += self.skip
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
@@ -3200,6 +3200,7 @@
assert str(array(['abc'], 'S3')) == "['abc']"
assert str(array('abc')) == 'abc'
assert str(array(1.5)) == '1.5'
+ assert str(array(1.5).real) == '1.5'
class AppTestRepr(BaseNumpyAppTest):
@@ -3218,6 +3219,7 @@
assert repr(array([1, 2, 3])) == 'array([1, 2, 3])'
assert repr(array(['abc'], 'S3')) == "array(['abc'])"
assert repr(array(1.5)) == "array(1.5)"
+ assert repr(array(1.5).real) == "array(1.5)"
def teardown_class(cls):
if option.runappdirect:
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit