Commits

mattip committed 1fa45ad

test untested ndarrayobject.py functions

  • Participants
  • Parent commits 5352a97
  • Branches pypy-pyarray

Comments (0)

Files changed (3)

 
 - 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__()

pypy/module/cpyext/ndarrayobject.py

 
 @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):

pypy/module/cpyext/test/test_ndarrayobject.py

         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
                     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)
         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])