Author: Matti Picus <[email protected]>
Branch:
Changeset: r67169:0be2466b3263
Date: 2013-10-06 22:46 +0300
http://bitbucket.org/pypy/pypy/changeset/0be2466b3263/
Log: implement, test more of numpy c api
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
@@ -149,14 +149,17 @@
only used if the array is constructed that way. Almost always this
parameter is NULL.
"""
- if min_depth !=0 or max_depth != 0:
- raise OperationError(space.w_NotImplementedError, space.wrap(
- '_PyArray_FromAny called with not-implemented min_dpeth or
max_depth argument'))
if requirements not in (0, NPY_DEFAULT):
raise OperationError(space.w_NotImplementedError, space.wrap(
'_PyArray_FromAny called with not-implemented requirements
argument'))
w_array = array(space, w_obj, w_dtype=w_dtype, copy=False)
- if w_array.is_scalar():
+ if min_depth !=0 and len(w_array.get_shape()) < min_depth:
+ raise OperationError(space.w_ValueError, space.wrap(
+ 'object of too small depth for desired array'))
+ elif max_depth !=0 and len(w_array.get_shape()) > max_depth:
+ raise OperationError(space.w_ValueError, space.wrap(
+ 'object of too deep for desired array'))
+ elif w_array.is_scalar():
# since PyArray_DATA() fails on scalars, create a 1D array and set
empty
# shape. So the following combination works for *reading* scalars:
# PyObject *arr = PyArray_FromAny(obj);
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
@@ -90,15 +90,16 @@
def test_FromAny(self, space, api):
a = array(space, [10, 5, 3])
assert api._PyArray_FromAny(a, NULL, 0, 0, 0, NULL) is a
- self.raises(space, api, NotImplementedError, api._PyArray_FromAny,
- a, NULL, 0, 3, 0, NULL)
+ assert api._PyArray_FromAny(a, NULL, 1, 4, 0, NULL) is a
+ self.raises(space, api, ValueError, api._PyArray_FromAny,
+ a, NULL, 4, 5, 0, NULL)
def test_FromObject(self, space, api):
a = array(space, [10, 5, 3])
assert api._PyArray_FromObject(a, a.get_dtype().num, 0, 0) is a
- exc = self.raises(space, api, NotImplementedError,
api._PyArray_FromObject,
- a, 11, 0, 3)
- assert exc.errorstr(space).find('FromObject') >= 0
+ exc = self.raises(space, api, ValueError, api._PyArray_FromObject,
+ a, 11, 4, 5)
+ assert exc.errorstr(space).find('desired') >= 0
def test_list_from_fixedptr(self, space, api):
A = lltype.GcArray(lltype.Float)
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit