[pypy-commit] pypy default: test and fix for passing out=None to ndarray.clip/choose
bdkearns
noreply at buildbot.pypy.org
Sat Feb 23 08:14:13 CET 2013
Author: Brian Kearns <bdkearns at gmail.com>
Branch:
Changeset: r61642:34f8c678ef62
Date: 2013-02-23 02:03 -0500
http://bitbucket.org/pypy/pypy/changeset/34f8c678ef62/
Log: test and fix for passing out=None to ndarray.clip/choose
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
@@ -453,13 +453,13 @@
@unwrap_spec(mode=str)
def descr_choose(self, space, w_choices, mode='raise', w_out=None):
- if w_out is not None and not isinstance(w_out, W_NDimArray):
+ if not space.is_none(w_out) and not isinstance(w_out, W_NDimArray):
raise OperationError(space.w_TypeError, space.wrap(
"return arrays must be of ArrayType"))
return interp_arrayops.choose(space, self, w_choices, w_out, mode)
def descr_clip(self, space, w_min, w_max, w_out=None):
- if w_out is not None and not isinstance(w_out, W_NDimArray):
+ if not space.is_none(w_out) and not isinstance(w_out, W_NDimArray):
raise OperationError(space.w_TypeError, space.wrap(
"return arrays must be of ArrayType"))
min = convert_to_array(space, w_min)
diff --git a/pypy/module/micronumpy/test/test_arrayops.py b/pypy/module/micronumpy/test/test_arrayops.py
--- a/pypy/module/micronumpy/test/test_arrayops.py
+++ b/pypy/module/micronumpy/test/test_arrayops.py
@@ -99,10 +99,13 @@
def test_choose_out(self):
from _numpypy import array
a, b, c = array([1, 2, 3]), [4, 5, 6], 13
+ r = array([2, 1, 0]).choose([a, b, c], out=None)
+ assert (r == [13, 5, 3]).all()
+ assert (a == [1, 2, 3]).all()
r = array([2, 1, 0]).choose([a, b, c], out=a)
assert (r == [13, 5, 3]).all()
assert (a == [13, 5, 3]).all()
-
+
def test_choose_modes(self):
from _numpypy import array
a, b, c = array([1, 2, 3]), [4, 5, 6], 13
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
@@ -1705,7 +1705,8 @@
from _numpypy import array
a = array([1, 2, 17, -3, 12])
assert (a.clip(-2, 13) == [1, 2, 13, -2, 12]).all()
- assert (a.clip(-1, 1) == [1, 1, 1, -1, 1]).all()
+ assert (a.clip(-1, 1, out=None) == [1, 1, 1, -1, 1]).all()
+ assert (a == [1, 2, 17, -3, 12]).all()
assert (a.clip(-1, [1, 2, 3, 4, 5]) == [1, 2, 3, -1, 5]).all()
assert (a.clip(-2, 13, out=a) == [1, 2, 13, -2, 12]).all()
assert (a == [1, 2, 13, -2, 12]).all()
More information about the pypy-commit
mailing list