[pypy-commit] pypy pypy-pyarray: test untested ndarrayobject.py functions

mattip noreply at buildbot.pypy.org
Thu Sep 19 23:03:39 CEST 2013


Author: Matti Picus <matti.picus at gmail.com>
Branch: pypy-pyarray
Changeset: r67010:1fa45adb9429
Date: 2013-09-19 22:57 +0300
http://bitbucket.org/pypy/pypy/changeset/1fa45adb9429/

Log:	test untested ndarrayobject.py functions

diff --git a/TODO.txt b/TODO.txt
--- a/TODO.txt
+++ b/TODO.txt
@@ -3,8 +3,6 @@
 
 - test "from numpypy import *" esp. get_include()
 - test all *.h files under pypy/module/cpyext/include/numpy
-- make sure meaningful cpyext changes are tested:
-    copy_header_files() in api.py (changed)
-    all ndarrayobject.py (new)
+- make sure copy_header_files() in api.py is used in package.py
 - test, implement use of __array_prepare__()
 - test, implement use of __array_wrap__()
diff --git a/pypy/module/cpyext/ndarrayobject.py b/pypy/module/cpyext/ndarrayobject.py
--- a/pypy/module/cpyext/ndarrayobject.py
+++ b/pypy/module/cpyext/ndarrayobject.py
@@ -171,17 +171,7 @@
 
 @cpython_api([PyObject, Py_ssize_t, Py_ssize_t, Py_ssize_t], PyObject)
 def _PyArray_FromObject(space, w_obj, typenum, min_depth, max_depth):
-    if min_depth !=0 or max_depth != 0:
-        raise OperationError(space.w_NotImplementedError, space.wrap(
-            '_PyArray_FromObject called with not-implemented min_dpeth or max_depth argument'))
-    dtype = get_dtype_cache(space).dtypes_by_num[typenum]
-    w_array = convert_to_array(space, w_obj)
-    impl = w_array.implementation
-    if w_array.is_scalar():
-        return W_NDimArray.new_scalar(space, dtype, impl.value)
-    else:
-        new_impl = impl.astype(space, dtype)
-        return wrap_impl(space, space.type(w_array), w_array, new_impl)
+    return _PyArray_FromAny(space, w_obj, typenum, min_depth, max_depth, NPY_BEHAVED);
 
 
 def get_shape_and_dtype(space, nd, dims, typenum):
diff --git a/pypy/module/cpyext/test/test_ndarrayobject.py b/pypy/module/cpyext/test/test_ndarrayobject.py
--- a/pypy/module/cpyext/test/test_ndarrayobject.py
+++ b/pypy/module/cpyext/test/test_ndarrayobject.py
@@ -51,6 +51,10 @@
         a = array(space, [10, 5, 3])
         assert api._PyArray_DIM(a, 1) == 5
 
+    def test_STRIDE(self, space, api):
+        a = array(space, [10, 5, 3], )
+        assert api._PyArray_STRIDE(a, 1) == a.implementation.get_strides()[1]
+
     def test_SIZE(self, space, api):
         a = array(space, [10, 5, 3])
         assert api._PyArray_SIZE(a) == 150
@@ -90,6 +94,13 @@
                     space.wrap(a), space.w_None, space.wrap(0),
                     space.wrap(3), space.wrap(0), space.w_None)
 
+    def test_FromObject(self, space, api):
+        a = array(space, [10, 5, 3])
+        assert api._PyArray_FromObject(a, NULL, 0, 0, 0, NULL) is a
+        self.raises(space, api, NotImplementedError, api._PyArray_FromObject,
+                    space.wrap(a), space.w_None, space.wrap(0),
+                    space.wrap(3), space.wrap(0), space.w_None)
+
     def test_list_from_fixedptr(self, space, api):
         A = lltype.GcArray(lltype.Float)
         ptr = lltype.malloc(A, 3)
@@ -184,6 +195,11 @@
         ptr_r = rffi.cast(rffi.DOUBLEP, api._PyArray_DATA(res))
         for i in range(150):
             assert ptr_r[i] == float(i)
+        res = api._PyArray_SimpleNewFromDataOwning(nd, ptr_s, num, ptr_a)
+        x = rffi.cast(rffi.DOUBLEP, ptr_a)
+        ptr_r = rffi.cast(rffi.DOUBLEP, api._PyArray_DATA(res))
+        x[20] = -100.
+        assert ptr_r[20] == -100.
 
     def test_SimpleNewFromData_complex(self, space, api):
         a = array(space, [2])


More information about the pypy-commit mailing list