[pypy-commit] pypy default: fix for translation and copying scalars
alex_gaynor
noreply at buildbot.pypy.org
Mon Nov 28 12:38:07 CET 2011
Author: Alex Gaynor <alex.gaynor at gmail.com>
Branch:
Changeset: r49894:1baa8d5c0e0b
Date: 2011-11-28 06:37 -0500
http://bitbucket.org/pypy/pypy/changeset/1baa8d5c0e0b/
Log: fix for translation and copying scalars
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
@@ -521,10 +521,7 @@
return space.wrap(self.find_size())
def descr_copy(self, space):
- concrete = self.get_concrete()
- array = NDimArray(concrete.size, concrete.shape[:], concrete.dtype, concrete.order)
- rffi.c_memcpy(array.storage, concrete.storage, array.size * array.dtype.num_bytes)
- return array
+ return self.get_concrete().copy()
def descr_len(self, space):
return self.get_concrete().descr_len(space)
@@ -866,6 +863,9 @@
def to_str(self, space, comma, builder, indent=' ', use_ellipsis=False):
builder.append(self.dtype.str_format(self.value))
+ def copy(self):
+ return Scalar(self.dtype, self.value)
+
class VirtualArray(BaseArray):
"""
@@ -1120,6 +1120,11 @@
def eval(self, iter):
return self.dtype.getitem(self.storage, iter.get_offset())
+ def copy(self):
+ array = NDimArray(self.size, self.shape[:], self.dtype, self.order)
+ rffi.c_memcpy(array.storage, self.storage, self.size * self.dtype.num_bytes)
+ return array
+
def descr_len(self, space):
if len(self.shape):
return space.wrap(self.shape[0])
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
@@ -210,6 +210,9 @@
a[3] = 22
assert b[3] == 3
+ a = array(1)
+ assert a.copy() == a
+
def test_iterator_init(self):
from numpypy import array
a = array(range(5))
More information about the pypy-commit
mailing list