Author: Matti Picus <matti.pi...@gmail.com> Branch: pypy-pyarray Changeset: r67053:2e99e8714199 Date: 2013-09-22 11:49 +0300 http://bitbucket.org/pypy/pypy/changeset/2e99e8714199/
Log: use int not type in test, fix implementation 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 @@ -7,7 +7,7 @@ from rpython.rtyper.lltypesystem import rffi from pypy.module.cpyext.api import cpython_api, Py_ssize_t, CANNOT_FAIL from pypy.module.cpyext.pyobject import PyObject -from pypy.module.micronumpy.interp_numarray import W_NDimArray, convert_to_array, wrap_impl +from pypy.module.micronumpy.interp_numarray import W_NDimArray, array from pypy.module.micronumpy.interp_dtype import get_dtype_cache from pypy.module.micronumpy.arrayimpl.concrete import ConcreteArray from pypy.module.micronumpy.arrayimpl.scalar import Scalar @@ -147,16 +147,16 @@ only used if the array is constructed that way. Almost always this parameter is NULL. """ - if dtype: - raise OperationError(space.w_NotImplementedError, space.wrap( - '_PyArray_FromAny called with not-implemented dtype argument')) 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 = convert_to_array(space, w_obj) + if not dtype: + w_array = array(space, w_obj, copy=False) + else: + w_array = array(space, w_obj, w_dtype=dtype, copy=False) if 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: @@ -172,7 +172,12 @@ @cpython_api([PyObject, Py_ssize_t, Py_ssize_t, Py_ssize_t], PyObject) def _PyArray_FromObject(space, w_obj, typenum, min_depth, max_depth): try: - return _PyArray_FromAny(space, w_obj, typenum, min_depth, max_depth, + dtype = get_dtype_cache(space).dtypes_by_num[typenum] + except KeyError: + raise OperationError(space.w_ValueError, space.wrap( + '_PyArray_FromObject called with invalid dtype %r' % typenum)) + try: + return _PyArray_FromAny(space, w_obj, dtype, min_depth, max_depth, 0, None); except OperationError, e: if e.match(space, space.w_NotImplementedError): 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 @@ -91,15 +91,13 @@ 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, - space.wrap(a), space.w_None, space.wrap(0), - space.wrap(3), space.wrap(0), space.w_None) + a, NULL, 0, 3, 0, NULL) def test_FromObject(self, space, api): a = array(space, [10, 5, 3]) - assert api._PyArray_FromObject(a, None, 0, 0) is a + assert api._PyArray_FromObject(a, a.get_dtype().num, 0, 0) is a exc = self.raises(space, api, NotImplementedError, api._PyArray_FromObject, - space.wrap(a), space.wrap(11), space.wrap(0), - space.wrap(3) ) + a, 11, 0, 3) assert exc.errorstr(space).find('FromObject') >= 0 def test_list_from_fixedptr(self, space, api): _______________________________________________ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit