Author: Yichao Yu <yyc1...@gmail.com> Branch: numpy-generic-item Changeset: r74055:e6d67911e7a8 Date: 2014-09-23 12:41 -0400 http://bitbucket.org/pypy/pypy/changeset/e6d67911e7a8/
Log: generic.nonzero diff --git a/pypy/module/micronumpy/boxes.py b/pypy/module/micronumpy/boxes.py --- a/pypy/module/micronumpy/boxes.py +++ b/pypy/module/micronumpy/boxes.py @@ -403,6 +403,10 @@ w_meth = space.getattr(self.descr_ravel(space), space.wrap('reshape')) return space.call_args(w_meth, __args__) + def descr_nd_nonzero(self, space, __args__): + w_meth = space.getattr(self.descr_ravel(space), space.wrap('nonzero')) + return space.call_args(w_meth, __args__) + def descr_get_real(self, space): return self.get_dtype(space).itemtype.real(self) @@ -674,6 +678,7 @@ tobytes = interp2app(W_GenericBox.descr_tostring), reshape = interp2app(W_GenericBox.descr_reshape), swapaxes = interp2app(W_GenericBox.descr_swapaxes), + nonzero = interp2app(W_GenericBox.descr_nd_nonzero), dtype = GetSetProperty(W_GenericBox.descr_get_dtype), size = GetSetProperty(W_GenericBox.descr_get_size), diff --git a/pypy/module/micronumpy/test/test_scalar.py b/pypy/module/micronumpy/test/test_scalar.py --- a/pypy/module/micronumpy/test/test_scalar.py +++ b/pypy/module/micronumpy/test/test_scalar.py @@ -368,3 +368,15 @@ for t in complex64, complex128: _do_test(t, complex, 17j, 17j) + + def test_nonzero(self): + from numpypy import int8, int16, int32, int64, float32, float64 + from numpypy import complex64, complex128 + + for t in (int8, int16, int32, int64, float32, float64, + complex64, complex128): + res, = t(17).nonzero() + assert len(res) == 1 + assert res[0] == 0 + res, = t(0).nonzero() + assert len(res) == 0 _______________________________________________ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit