Author: Yichao Yu <yyc1...@gmail.com>
Branch: numpy-generic-item
Changeset: r74056:edc2afc71097
Date: 2014-09-23 22:40 -0400
http://bitbucket.org/pypy/pypy/changeset/edc2afc71097/

Log:    generic.fill, generic.conj

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
@@ -424,6 +424,9 @@
     def descr_swapaxes(self, space, axis1, axis2):
         return self.item(space)
 
+    def descr_fill(self, space, w_value):
+        self.get_dtype(space).coerce(space, w_value)
+
 class W_BoolBox(W_GenericBox, PrimitiveBox):
     descr__new__, _get_dtype, descr_reduce = new_dtype_getter(NPY.BOOL)
 
@@ -669,6 +672,7 @@
     ravel = interp2app(W_GenericBox.descr_ravel),
     round = interp2app(W_GenericBox.descr_round),
     conjugate = interp2app(W_GenericBox.descr_conjugate),
+    conj = interp2app(W_GenericBox.descr_conjugate),
     astype = interp2app(W_GenericBox.descr_astype),
     view = interp2app(W_GenericBox.descr_view),
     squeeze = interp2app(W_GenericBox.descr_self),
@@ -679,6 +683,7 @@
     reshape = interp2app(W_GenericBox.descr_reshape),
     swapaxes = interp2app(W_GenericBox.descr_swapaxes),
     nonzero = interp2app(W_GenericBox.descr_nd_nonzero),
+    fill = interp2app(W_GenericBox.descr_fill),
 
     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
@@ -380,3 +380,29 @@
             assert res[0] == 0
             res, = t(0).nonzero()
             assert len(res) == 0
+
+    def test_fill(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):
+            t(17).fill(2)
+            raises(ValueError, t(17).fill, '')
+
+    def test_conj(self):
+        from numpypy import int8, int16, int32, int64, float32, float64
+        from numpypy import complex64, complex128
+
+        def _do_test(np_type, orig_val, exp_val):
+            val = np_type(orig_val)
+            assert val == orig_val
+            assert val.conj() == exp_val
+            assert val.conjugate() == exp_val
+
+        for t in (int8, int16, int32, int64, float32, float64,
+                  complex64, complex128):
+            _do_test(t, 17, 17)
+
+        for t in complex64, complex128:
+            _do_test(t, 17j, -17j)
_______________________________________________
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to