[pypy-commit] pypy numpy-back-to-applevel: implement copy kwarg
fijal
noreply at buildbot.pypy.org
Sat Jan 21 19:28:30 CET 2012
Author: Maciej Fijalkowski <fijall at gmail.com>
Branch: numpy-back-to-applevel
Changeset: r51603:cc80fb4d3ab9
Date: 2012-01-21 20:23 +0200
http://bitbucket.org/pypy/pypy/changeset/cc80fb4d3ab9/
Log: implement copy kwarg
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
@@ -1077,11 +1077,11 @@
@unwrap_spec(subok=bool, copy=bool, ownmaskna=bool)
def array(space, w_item_or_iterable, w_dtype=None, w_order=None,
- subok=True, copy=False, w_maskna=None, ownmaskna=False):
+ subok=True, copy=True, w_maskna=None, ownmaskna=False):
# find scalar
if w_maskna is None:
w_maskna = space.w_None
- if (not subok or copy or not space.is_w(w_maskna, space.w_None) or
+ if (not subok or not space.is_w(w_maskna, space.w_None) or
ownmaskna):
raise OperationError(space.w_NotImplementedError, space.wrap("Unsupported args"))
if not space.issequence_w(w_item_or_iterable):
@@ -1099,6 +1099,14 @@
if order != 'C': # or order != 'F':
raise operationerrfmt(space.w_ValueError, "Unknown order: %s",
order)
+ if isinstance(w_item_or_iterable, BaseArray):
+ if (not space.is_w(w_dtype, space.w_None) and
+ w_item_or_iterable.find_dtype() is not w_dtype):
+ raise OperationError(space.w_NotImplementedError, space.wrap(
+ "copying over different dtypes unsupported"))
+ if copy:
+ return w_item_or_iterable.copy(space)
+ return w_item_or_iterable
shape, elems_w = find_shape_and_elems(space, w_item_or_iterable)
# they come back in C order
size = len(elems_w)
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
@@ -1358,7 +1358,13 @@
a[a & 1 == 1] = array([8, 9, 10])
assert (a == [[0, 8], [2, 9], [4, 10]]).all()
-
+ def test_copy_kwarg(self):
+ from _numpypy import array
+ x = array([1, 2, 3])
+ assert (array(x) == x).all()
+ assert array(x) is not x
+ assert array(x, copy=False) is x
+ assert array(x, copy=True) is not x
class AppTestSupport(BaseNumpyAppTest):
def setup_class(cls):
More information about the pypy-commit
mailing list