diff options
-rw-r--r-- | scipy/base/code_generators/generate_array_api.py | 16 | ||||
-rw-r--r-- | scipy/base/numeric.py | 8 | ||||
-rw-r--r-- | scipy/base/src/_compiled_base.c | 6 | ||||
-rw-r--r-- | scipy/base/src/arrayobject.c | 9 | ||||
-rw-r--r-- | scipy/base/src/multiarraymodule.c | 52 | ||||
-rw-r--r-- | scipy/basic/basic_lite.py | 4 | ||||
-rw-r--r-- | scipy/doc/CAPI.txt | 5 |
7 files changed, 66 insertions, 34 deletions
diff --git a/scipy/base/code_generators/generate_array_api.py b/scipy/base/code_generators/generate_array_api.py index 978a01cef..374abdefc 100644 --- a/scipy/base/code_generators/generate_array_api.py +++ b/scipy/base/code_generators/generate_array_api.py @@ -111,12 +111,26 @@ objectapi_list = [ If max_dimensions = 0, then any number of dimensions are allowed. Fix the dimension by setting min_dimension == max_dimension. If the array is already contiguous (and aligned and not swapped) - no copy is done, just a new reference created. + no copy is done, just a new reference created. + Base-class ndarray is returned. """, 'ContiguousFromObject', 'PyObject *, int typenum, int, int', 'PyObject *'), + (r"""Construct an array from an arbitrary Python Object. + Last two integers are min_dimensions, and max_dimensions. + If max_dimensions = 0, then any number of dimensions are allowed. + Fix the dimension by setting min_dimension == max_dimension. + If the array is already contiguous (and aligned and not swapped) + no copy is done, just a new reference created. Subclasses + passed through. + """, + 'ContiguousFromAny', + 'PyObject *, int typenum, int, int', + 'PyObject *'), + + (r"""Same as ContiguousFromObject except ensure a copy. """, 'CopyFromObject','PyObject *, int, int, int','PyObject *'), diff --git a/scipy/base/numeric.py b/scipy/base/numeric.py index 8e0306877..3f2688b4d 100644 --- a/scipy/base/numeric.py +++ b/scipy/base/numeric.py @@ -97,8 +97,8 @@ def outer(a,b): result(i,j) = a(i)*b(j) when a and b are vectors Will accept any arguments that can be made into vectors. """ - a = asndarray(a) - b = asndarray(b) + a = asarray(a) + b = asarray(b) return a.ravel()[:,newaxis]*b.ravel()[newaxis,:] def vdot(a, b): @@ -136,8 +136,8 @@ def cross(a, b, axisa=-1, axisb=-1, axisc=-1): the z-component of the equivalent three-dimensional cross product is returned. """ - a = _move_axis_to_0(asndarray(a), axisa) - b = _move_axis_to_0(asndarray(b), axisb) + a = _move_axis_to_0(asarray(a), axisa) + b = _move_axis_to_0(asarray(b), axisb) msg = "incompatible dimensions for cross product\n"\ "(dimension must be 2 or 3)" if (a.shape[0] not in [2,3]) or (b.shape[0] not in [2,3]): diff --git a/scipy/base/src/_compiled_base.c b/scipy/base/src/_compiled_base.c index 5a5d5e492..9b1276614 100644 --- a/scipy/base/src/_compiled_base.c +++ b/scipy/base/src/_compiled_base.c @@ -100,7 +100,7 @@ arr_bincount(PyObject *self, PyObject *args, PyObject *kwds) Py_Try(PyArg_ParseTupleAndKeywords(args, kwds, "O|O", kwlist, &list, &weight)); - Py_Try(lst = PyArray_ContiguousFromObject(list, PyArray_INTP, 1, 1)); + Py_Try(lst = PyArray_ContiguousFromAny(list, PyArray_INTP, 1, 1)); len = PyArray_SIZE(lst); numbers = (intp *) PyArray_DATA(lst); mxi = mxx (numbers, len) ; @@ -116,8 +116,8 @@ arr_bincount(PyObject *self, PyObject *args, PyObject *kwds) Py_DECREF(lst); } else { - Py_Try(wts = PyArray_ContiguousFromObject(weight, - PyArray_DOUBLE, 1, 1)); + Py_Try(wts = PyArray_ContiguousFromAny(weight, + PyArray_DOUBLE, 1, 1)); weights = (double *)PyArray_DATA (wts); Py_Assert(PyArray_SIZE(wts) == len, "bincount: length of weights " \ "does not match that of list"); diff --git a/scipy/base/src/arrayobject.c b/scipy/base/src/arrayobject.c index 8849aec4d..a7df05d95 100644 --- a/scipy/base/src/arrayobject.c +++ b/scipy/base/src/arrayobject.c @@ -5534,6 +5534,15 @@ PyArray_CopyFromObject(PyObject *op, int type, int min_depth, /* End of deprecated */ +static PyObject * +PyArray_ContiguousFromAny(PyObject *op, int type, int min_depth, + int max_depth) +{ + PyArray_Typecode typecode = {0,0,0}; + typecode.type_num = type; + return PyArray_FromAny(op, &typecode, min_depth, + max_depth, DEFAULT_FLAGS); +} static int PyArray_CanCastSafely(int fromtype, int totype) diff --git a/scipy/base/src/multiarraymodule.c b/scipy/base/src/multiarraymodule.c index 1f2069766..76a08fd6c 100644 --- a/scipy/base/src/multiarraymodule.c +++ b/scipy/base/src/multiarraymodule.c @@ -1199,7 +1199,7 @@ PyArray_Repeat(PyArrayObject *aop, PyObject *op, int axis) { PyArrayObject *ret=NULL; char *new_data, *old_data; - repeats = (PyAO *)PyArray_ContiguousFromObject(op, PyArray_INTP, 0, 1); + repeats = (PyAO *)PyArray_ContiguousFromAny(op, PyArray_INTP, 0, 1); if (repeats == NULL) return NULL; nd = repeats->nd; counts = (intp *)repeats->data; @@ -1325,12 +1325,12 @@ PyArray_Choose(PyArrayObject *ip, PyObject *op) { if ((otmp = PySequence_GetItem(op, i)) == NULL) goto fail; mps[i] = (PyArrayObject*) - PyArray_ContiguousFromObject(otmp, type_num, + PyArray_ContiguousFromAny(otmp, type_num, 0, 0); Py_DECREF(otmp); } - ap = (PyArrayObject *)PyArray_ContiguousFromObject((PyObject *)ip, + ap = (PyArrayObject *)PyArray_ContiguousFromAny((PyObject *)ip, PyArray_INTP, 0, 0); if (ap == NULL) goto fail; @@ -1508,7 +1508,7 @@ PyArray_ArgSort(PyArrayObject *op, int axis) SWAPAXES(op, ap); - ap = (PyArrayObject *)PyArray_ContiguousFromObject((PyObject *)op, + ap = (PyArrayObject *)PyArray_ContiguousFromAny((PyObject *)op, PyArray_NOTYPE, 1, 0); Py_DECREF(op); @@ -1611,11 +1611,11 @@ PyArray_SearchSorted(PyArrayObject *op1, PyObject *op2) typenum = PyArray_ObjectType((PyObject *)op1, 0); typenum = PyArray_ObjectType(op2, typenum); ret = NULL; - ap1 = (PyArrayObject *)PyArray_ContiguousFromObject((PyObject *)op1, + ap1 = (PyArrayObject *)PyArray_ContiguousFromAny((PyObject *)op1, typenum, 1, 1); if (ap1 == NULL) return NULL; - ap2 = (PyArrayObject *)PyArray_ContiguousFromObject(op2, typenum, + ap2 = (PyArrayObject *)PyArray_ContiguousFromAny(op2, typenum, 0, 0); if (ap2 == NULL) goto fail; @@ -1665,10 +1665,10 @@ PyArray_InnerProduct(PyObject *op1, PyObject *op2) typenum = PyArray_ObjectType(op2, typenum); ret = NULL; - ap1 = (PyArrayObject *)PyArray_ContiguousFromObject(op1, typenum, + ap1 = (PyArrayObject *)PyArray_ContiguousFromAny(op1, typenum, 0, 0); if (ap1 == NULL) return NULL; - ap2 = (PyArrayObject *)PyArray_ContiguousFromObject(op2, typenum, + ap2 = (PyArrayObject *)PyArray_ContiguousFromAny(op2, typenum, 0, 0); if (ap2 == NULL) goto fail; @@ -1769,16 +1769,18 @@ PyArray_MatrixProduct(PyObject *op1, PyObject *op2) intp matchDim, otherDim, is2r, is1r; PyTypeObject *subtype; double prior1, prior2; + PyArray_Typecode typec = {0,0,0}; typenum = PyArray_ObjectType(op1, 0); typenum = PyArray_ObjectType(op2, typenum); + typec.type_num = typenum; ret = NULL; - ap1 = (PyArrayObject *)PyArray_ContiguousFromObject(op1, typenum, - 0, 0); + ap1 = (PyArrayObject *)PyArray_FromAny(op1, &typec, 0, 0, + DEFAULT_FLAGS); if (ap1 == NULL) return NULL; - ap2 = (PyArrayObject *)PyArray_ContiguousFromObject(op2, typenum, - 0, 0); + ap2 = (PyArrayObject *)PyArray_FromAny(op2, &typec, 0, 0, + DEFAULT_FLAGS); if (ap2 == NULL) goto fail; if (ap1->nd == 0 || ap2->nd == 0) { @@ -1945,16 +1947,18 @@ PyArray_Correlate(PyObject *op1, PyObject *op2, int mode) int is1, is2, os; char *ip1, *ip2, *op; PyArray_DotFunc *dot; + PyArray_Typecode typec = {0,0,0}; typenum = PyArray_ObjectType(op1, 0); typenum = PyArray_ObjectType(op2, typenum); - + + typec.type_num = typenum; ret = NULL; - ap1 = (PyArrayObject *)PyArray_ContiguousFromObject(op1, typenum, - 1, 1); + ap1 = (PyArrayObject *)PyArray_FromAny(op1, &typec, 1, 1, + DEFAULT_FLAGS); if (ap1 == NULL) return NULL; - ap2 = (PyArrayObject *)PyArray_ContiguousFromObject(op2, typenum, - 1, 1); + ap2 = (PyArrayObject *)PyArray_FromAny(op1, &typec, 1, 1, + DEFAULT_FLAGS); if (ap2 == NULL) goto fail; n1 = ap1->dimensions[ap1->nd-1]; @@ -2132,8 +2136,8 @@ PyArray_ArgMax(PyArrayObject *op, int axis) SWAPAXES(op, ap); ap = (PyArrayObject *)\ - PyArray_ContiguousFromObject((PyObject *)op, - PyArray_NOTYPE, 1, 0); + PyArray_ContiguousFromAny((PyObject *)op, + PyArray_NOTYPE, 1, 0); Py_DECREF(op); if (ap == NULL) return NULL; @@ -2189,7 +2193,7 @@ PyArray_Take(PyArrayObject *self0, PyObject *indices0, int axis) { self = (PyAO *)_check_axis(self0, &axis, CARRAY_FLAGS); if (self == NULL) return NULL; - indices = (PyArrayObject *)PyArray_ContiguousFromObject(indices0, + indices = (PyArrayObject *)PyArray_ContiguousFromAny(indices0, PyArray_INTP, 1, 0); if (indices == NULL) goto fail; @@ -2275,12 +2279,12 @@ PyArray_Put(PyArrayObject *self, PyObject *indices0, PyObject* values0) dest = self->data; chunk = self->itemsize; - indices = (PyArrayObject *)PyArray_ContiguousFromObject(indices0, PyArray_INTP, 0, 0); + indices = (PyArrayObject *)PyArray_ContiguousFromAny(indices0, PyArray_INTP, 0, 0); if (indices == NULL) goto fail; ni = PyArray_SIZE(indices); values = (PyArrayObject *)\ - PyArray_ContiguousFromObject(values0, self->descr->type_num, + PyArray_ContiguousFromAny(values0, self->descr->type_num, 0, 0); if (values == NULL) goto fail; nv = PyArray_SIZE(values); @@ -2335,7 +2339,7 @@ PyArray_PutMask(PyArrayObject *self, PyObject *mask0, PyObject* values0) chunk = self->itemsize; mask = (PyArrayObject *)\ - PyArray_ContiguousFromObject(mask0, PyArray_BOOL, 0, 0); + PyArray_ContiguousFromAny(mask0, PyArray_BOOL, 0, 0); if (mask == NULL) goto fail; ni = PyArray_SIZE(mask); if (ni != max_item) { @@ -2347,7 +2351,7 @@ PyArray_PutMask(PyArrayObject *self, PyObject *mask0, PyObject* values0) thistype = self->descr->type_num; values = (PyArrayObject *)\ - PyArray_ContiguousFromObject(values0, thistype, 0, 0); + PyArray_ContiguousFromAny(values0, thistype, 0, 0); if (values == NULL) goto fail; nv = PyArray_SIZE(values); /* zero if null array */ if (nv > 0) { diff --git a/scipy/basic/basic_lite.py b/scipy/basic/basic_lite.py index 2871c6120..61f99a33a 100644 --- a/scipy/basic/basic_lite.py +++ b/scipy/basic/basic_lite.py @@ -411,8 +411,8 @@ the number of rows, then residuals will be returned as an empty array otherwise resids = sum((b-dot(A,x)**2). Singular values less than s[0]*rcond are treated as zero. """ - a = asndarray(a) - b = asndarary(b) + a = asarray(a) + b = asarray(b) one_eq = len(b.shape) == 1 if one_eq: b = b[:, Numeric.NewAxis] diff --git a/scipy/doc/CAPI.txt b/scipy/doc/CAPI.txt index cdda9394e..c4afae2f3 100644 --- a/scipy/doc/CAPI.txt +++ b/scipy/doc/CAPI.txt @@ -211,6 +211,11 @@ PyArray_Typecode structure } +PyArray_ContiguousFromAny(op, typenum, min_depth, max_depth) is equivalent +to PyArray_ContiguousFromObject(...) (which is still available), except +it will return the subclass if op is already a subclass of the ndarray. +The ContiguousFromObject version will always return an ndarray (or a bigndarray). + Passing Data Type information to C-code ============================================ |