Author: Brian Kearns <[email protected]>
Branch: 
Changeset: r68464:5a4adfaff6c6
Date: 2013-12-18 04:30 -0500
http://bitbucket.org/pypy/pypy/changeset/5a4adfaff6c6/

Log:    empty_like support subtypes

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
@@ -1468,12 +1468,13 @@
 @unwrap_spec(subok=bool)
 def empty_like(space, w_a, w_dtype=None, w_order=None, subok=True):
     w_a = convert_to_array(space, w_a)
-    if subok and type(w_a) is not W_NDimArray:
-        raise OperationError(space.w_NotImplementedError, space.wrap(
-            "subtypes not implemented"))
     if w_dtype is None:
-        w_dtype = w_a.get_dtype()
-    return zeros(space, w_a.descr_get_shape(space), w_dtype)
+        dtype = w_a.get_dtype()
+    else:
+        dtype = space.interp_w(interp_dtype.W_Dtype,
+            space.call_function(space.gettypefor(interp_dtype.W_Dtype), 
w_dtype))
+    return W_NDimArray.from_shape(space, w_a.get_shape(), dtype=dtype,
+                                  w_instance=w_a if subok else None)
 
 def _reconstruct(space, w_subtype, w_shape, w_dtype):
     return descr_new_array(space, w_subtype, w_shape, w_dtype)
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
@@ -357,6 +357,9 @@
 
     def test_empty_like(self):
         import numpy as np
+        a = np.empty_like(np.zeros(()))
+        assert a.shape == ()
+        assert a.dtype == np.float_
         a = np.zeros((2, 3))
         assert a.shape == (2, 3)
         a[0,0] = 1
@@ -371,16 +374,14 @@
         b = np.empty_like([1,2,3])
         assert b.shape == (3,)
         assert b.dtype == np.int_
-
         class A(np.ndarray):
             pass
-        import sys
-        if '__pypy__' not in sys.builtin_module_names:
-            b = np.empty_like(A((2, 3)))
-            assert b.shape == (2, 3)
-            assert type(b) is A
-        else:
-            raises(NotImplementedError, np.empty_like, A((2, 3)))
+        b = np.empty_like(A((2, 3)))
+        assert b.shape == (2, 3)
+        assert type(b) is A
+        b = np.empty_like(A((2, 3)), subok=False)
+        assert b.shape == (2, 3)
+        assert type(b) is np.ndarray
 
     def test_size(self):
         from numpypy import array,arange,cos
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to