diff options
author | Travis Oliphant <oliphant@enthought.com> | 2006-03-24 22:12:48 +0000 |
---|---|---|
committer | Travis Oliphant <oliphant@enthought.com> | 2006-03-24 22:12:48 +0000 |
commit | 28b7d9fb65da6e36eff3158f77b2a023edf7f733 (patch) | |
tree | 9075b6f51ca22d2ee6ce2934962e50ee43d47a28 /numpy/core/src | |
parent | 76612bfed9caef1f619c12bdd867b4974e93d8f4 (diff) | |
download | numpy-28b7d9fb65da6e36eff3158f77b2a023edf7f733.tar.gz |
Changed fortran= keywords to order= keywords
Diffstat (limited to 'numpy/core/src')
-rw-r--r-- | numpy/core/src/arraymethods.c | 28 | ||||
-rw-r--r-- | numpy/core/src/arrayobject.c | 23 | ||||
-rw-r--r-- | numpy/core/src/multiarraymodule.c | 112 |
3 files changed, 95 insertions, 68 deletions
diff --git a/numpy/core/src/arraymethods.c b/numpy/core/src/arraymethods.c index 9c1715678..2d4c82054 100644 --- a/numpy/core/src/arraymethods.c +++ b/numpy/core/src/arraymethods.c @@ -68,7 +68,7 @@ array_putmask(PyArrayObject *self, PyObject *args, PyObject *kwds) } static char doc_reshape[] = \ - "self.reshape(d1, d2, ..., dn, fortran=False) \n" \ + "self.reshape(d1, d2, ..., dn, order='C') \n" \ "Return a new array from this one. \n" \ "\n The new array must have the same number of elements as self. " \ "Also\n a copy of the data only occurs if necessary."; @@ -78,14 +78,14 @@ array_reshape(PyArrayObject *self, PyObject *args, PyObject *kwds) { PyArray_Dims newshape; PyObject *ret; - PyArray_CONDITION fortran=PyArray_FALSE; + PyArray_ORDER order=PyArray_CORDER; int n; if (kwds != NULL) { PyObject *ref; - ref = PyDict_GetItemString(kwds, "fortran"); - if (ref == NULL || \ - (PyArray_ConditionConverter(ref, &fortran) == PY_FAIL)) + ref = PyDict_GetItemString(kwds, "order"); + if (ref == NULL || \ + (PyArray_OrderConverter(ref, &order) == PY_FAIL)) return NULL; } @@ -109,7 +109,7 @@ array_reshape(PyArrayObject *self, PyObject *args, PyObject *kwds) return PyArray_Ravel(self, 0); } - ret = PyArray_Newshape(self, &newshape, fortran); + ret = PyArray_Newshape(self, &newshape, order); PyDimMem_FREE(newshape.ptr); return ret; @@ -623,8 +623,8 @@ static char doc_copy[] = "m.copy(|fortran). Return a copy of the array.\n"\ static PyObject * array_copy(PyArrayObject *self, PyObject *args) { - PyArray_CONDITION fortran=PyArray_FALSE; - if (!PyArg_ParseTuple(args, "|O&", PyArray_ConditionConverter, + PyArray_ORDER fortran=PyArray_CORDER; + if (!PyArg_ParseTuple(args, "|O&", PyArray_OrderConverter, &fortran)) return NULL; return PyArray_NewCopy(self, fortran); @@ -642,7 +642,7 @@ array_resize(PyArrayObject *self, PyObject *args, PyObject *kwds) PyObject *ret; int n; int refcheck = 1; - PyArray_CONDITION fortran=PyArray_DONTCARE; + PyArray_ORDER fortran=PyArray_ANYORDER; if (kwds != NULL) { PyObject *ref; @@ -655,7 +655,7 @@ array_resize(PyArrayObject *self, PyObject *args, PyObject *kwds) } ref = PyDict_GetItemString(kwds, "fortran"); if (ref != NULL || - (PyArray_ConditionConverter(ref, &fortran) == PY_FAIL)) + (PyArray_OrderConverter(ref, &fortran) == PY_FAIL)) return NULL; } n = PyTuple_Size(args); @@ -1443,9 +1443,9 @@ static char doc_flatten[] = "a.flatten([fortran]) return a 1-d array (always cop static PyObject * array_flatten(PyArrayObject *self, PyObject *args) { - PyArray_CONDITION fortran=PyArray_FALSE; + PyArray_ORDER fortran=PyArray_CORDER; - if (!PyArg_ParseTuple(args, "|O&", PyArray_ConditionConverter, + if (!PyArg_ParseTuple(args, "|O&", PyArray_OrderConverter, &fortran)) return NULL; return PyArray_Flatten(self, fortran); @@ -1456,9 +1456,9 @@ static char doc_ravel[] = "a.ravel([fortran]) return a 1-d array (copy only if n static PyObject * array_ravel(PyArrayObject *self, PyObject *args) { - PyArray_CONDITION fortran=PyArray_FALSE; + PyArray_ORDER fortran=PyArray_CORDER; - if (!PyArg_ParseTuple(args, "|O&", PyArray_ConditionConverter, + if (!PyArg_ParseTuple(args, "|O&", PyArray_OrderConverter, &fortran)) return NULL; return PyArray_Ravel(self, fortran); diff --git a/numpy/core/src/arrayobject.c b/numpy/core/src/arrayobject.c index bbfb94e27..084eaaf7a 100644 --- a/numpy/core/src/arrayobject.c +++ b/numpy/core/src/arrayobject.c @@ -801,12 +801,12 @@ PyArray_FromDims(int nd, int *d, int type) Copy an array. */ static PyObject * -PyArray_NewCopy(PyArrayObject *m1, PyArray_CONDITION fortran) +PyArray_NewCopy(PyArrayObject *m1, PyArray_ORDER fortran) { PyArrayObject *ret; - if (fortran == PyArray_DONTCARE) + if (fortran == PyArray_ANYORDER) fortran = PyArray_ISFORTRAN(m1); - + Py_INCREF(m1->descr); ret = (PyArrayObject *)PyArray_NewFromDescr(m1->ob_type, m1->descr, @@ -4103,7 +4103,7 @@ PyArray_NewFromDescr(PyTypeObject *subtype, PyArray_Descr *descr, int nd, */ static PyObject * PyArray_Resize(PyArrayObject *self, PyArray_Dims *newshape, int refcheck, - PyArray_CONDITION fortran) + PyArray_ORDER fortran) { intp oldsize, newsize; int new_nd=newshape->len, k, n, elsize; @@ -4120,9 +4120,9 @@ PyArray_Resize(PyArrayObject *self, PyArray_Dims *newshape, int refcheck, return NULL; } - if (fortran == PyArray_DONTCARE) - fortran = PyArray_FALSE; - + if (fortran == PyArray_ANYORDER) + fortran = PyArray_CORDER; + newsize = PyArray_MultiplyList(new_dimensions, new_nd); oldsize = PyArray_SIZE(self); @@ -4289,7 +4289,7 @@ array_new(PyTypeObject *subtype, PyObject *args, PyObject *kwds) { static char *kwlist[] = {"shape", "dtype", "buffer", /* XXX ? */ "offset", "strides", - "fortran", NULL}; + "order", NULL}; PyArray_Descr *descr=NULL; int type_num; int itemsize; @@ -4297,6 +4297,7 @@ array_new(PyTypeObject *subtype, PyObject *args, PyObject *kwds) PyArray_Dims strides = {NULL, 0}; PyArray_Chunk buffer; longlong offset=0; + PyArray_ORDER order=PyArray_CORDER; int fortran = 0; PyArrayObject *ret; @@ -4309,7 +4310,7 @@ array_new(PyTypeObject *subtype, PyObject *args, PyObject *kwds) array of a specific type and shape. */ - if (!PyArg_ParseTupleAndKeywords(args, kwds, "O&|O&O&LO&i", + if (!PyArg_ParseTupleAndKeywords(args, kwds, "O&|O&O&LO&O&", kwlist, PyArray_IntpConverter, &dims, PyArray_DescrConverter, @@ -4319,9 +4320,11 @@ array_new(PyTypeObject *subtype, PyObject *args, PyObject *kwds) &offset, &PyArray_IntpConverter, &strides, - &fortran)) + &PyArray_OrderConverter, + &order)) goto fail; + if (order == PyArray_FORTRANORDER) fortran = 1; if (descr == NULL) descr = PyArray_DescrFromType(PyArray_LONG); diff --git a/numpy/core/src/multiarraymodule.c b/numpy/core/src/multiarraymodule.c index 101af121d..72f29b5c0 100644 --- a/numpy/core/src/multiarraymodule.c +++ b/numpy/core/src/multiarraymodule.c @@ -175,12 +175,12 @@ PyArray_View(PyArrayObject *self, PyArray_Descr *type, PyTypeObject *pytype) Ravel */ static PyObject * -PyArray_Ravel(PyArrayObject *a, PyArray_CONDITION fortran) +PyArray_Ravel(PyArrayObject *a, PyArray_ORDER fortran) { PyArray_Dims newdim = {NULL,1}; intp val[1] = {-1}; - if (fortran == PyArray_DONTCARE) + if (fortran == PyArray_ANYORDER) fortran = PyArray_ISFORTRAN(a); newdim.ptr = val; @@ -189,7 +189,7 @@ PyArray_Ravel(PyArrayObject *a, PyArray_CONDITION fortran) Py_INCREF(a); return (PyObject *)a; } - return PyArray_Newshape(a, &newdim, PyArray_FALSE); + return PyArray_Newshape(a, &newdim, PyArray_CORDER); } else return PyArray_Flatten(a, fortran); @@ -313,12 +313,12 @@ PyArray_Round(PyArrayObject *a, int decimals) Flatten */ static PyObject * -PyArray_Flatten(PyArrayObject *a, PyArray_CONDITION fortran) +PyArray_Flatten(PyArrayObject *a, PyArray_ORDER fortran) { PyObject *ret, *new; intp size; - if (fortran == PyArray_DONTCARE) + if (fortran == PyArray_ANYORDER) fortran = PyArray_ISFORTRAN(a); size = PyArray_SIZE(a); @@ -366,7 +366,7 @@ PyArray_Reshape(PyArrayObject *self, PyObject *shape) PyArray_Dims newdims; if (!PyArray_IntpConverter(shape, &newdims)) return NULL; - ret = PyArray_Newshape(self, &newdims, PyArray_FALSE); + ret = PyArray_Newshape(self, &newdims, PyArray_CORDER); PyDimMem_FREE(newdims.ptr); return ret; } @@ -453,7 +453,7 @@ _fix_unknown_dimension(PyArray_Dims *newshape, intp s_original) */ static PyObject * PyArray_Newshape(PyArrayObject *self, PyArray_Dims *newdims, - PyArray_CONDITION fortran) + PyArray_ORDER fortran) { intp i; intp *dimensions = newdims->ptr; @@ -463,7 +463,7 @@ PyArray_Newshape(PyArrayObject *self, PyArray_Dims *newdims, intp *strides = NULL; intp newstrides[MAX_DIMS]; - if (fortran == PyArray_DONTCARE) + if (fortran == PyArray_ANYORDER) fortran = PyArray_ISFORTRAN(self); /* Quick check to make sure anything actually needs to be done */ @@ -487,8 +487,8 @@ PyArray_Newshape(PyArrayObject *self, PyArray_Dims *newdims, if (strides==NULL) { if ((n == 0) || - (PyArray_ISCONTIGUOUS(self) && (fortran != PyArray_TRUE)) || - (PyArray_ISFORTRAN(self) && (fortran != PyArray_FALSE))) { + (PyArray_ISCONTIGUOUS(self) && (fortran != PyArray_FORTRANORDER)) || + (PyArray_ISFORTRAN(self) && (fortran != PyArray_CORDER))) { incref = TRUE; } else { @@ -507,7 +507,7 @@ PyArray_Newshape(PyArrayObject *self, PyArray_Dims *newdims, /* replace any 0-valued strides with appropriate value to preserve contiguousness */ - if (fortran == PyArray_TRUE) { + if (fortran == PyArray_FORTRANORDER) { if (strides[0] == 0) strides[0] = self->descr->elsize; for (i=1; i<n; i++) { @@ -3306,24 +3306,40 @@ PyArray_BoolConverter(PyObject *object, Bool *val) } /*MULTIARRAY_API - Convert an object to true / false + Convert an object to FORTRAN / C / ANY */ static int -PyArray_ConditionConverter(PyObject *object, PyArray_CONDITION *val) -{ - - if (object == Py_None) - *val = PyArray_DONTCARE; - else if (PyObject_IsTrue(object)) - *val=PyArray_TRUE; - else *val=PyArray_FALSE; - if (PyErr_Occurred()) - return PY_FAIL; - return PY_SUCCEED; +PyArray_OrderConverter(PyObject *object, PyArray_ORDER *val) +{ + char *str; + if (object == Py_None) { + *val = PyArray_ANYORDER; + } + else if (!PyString_Check(object) || PyString_GET_SIZE(object) < 1) { + if (PyObject_IsTrue(object)) + *val = PyArray_FORTRANORDER; + else + *val = PyArray_CORDER; + if (PyErr_Occurred()) + return PY_FAIL; + return PY_SUCCEED; + } + else { + str = PyString_AS_STRING(object); + if (str[0] == 'C' || str[0] == 'c') { + *val = PyArray_CORDER; + } + if (str[0] == 'F' || str[0] == 'f') { + *val = PyArray_FORTRANORDER; + } + if (str[0] == 'A' || str[0] == 'a') { + *val = PyArray_ANYORDER; + } + } + return PY_SUCCEED; } - /*MULTIARRAY_API Typestr converter */ @@ -4433,24 +4449,24 @@ static char doc_fromobject[] = "array(object, dtype=None, copy=1, "\ "then a C-style contiguous array will be returned. If fotran is True\n"\ "then a Fortran-style contiguous array will be returned."; -#define STRIDING_OK(op, fortran) ((fortran) == PyArray_DONTCARE || \ - ((fortran) == PyArray_FALSE && \ - PyArray_ISCONTIGUOUS(op)) || \ - ((fortran) == PyArray_TRUE && \ - PyArray_ISFORTRAN(op))) +#define STRIDING_OK(op, order) ((order) == PyArray_ANYORDER || \ + ((order) == PyArray_CORDER && \ + PyArray_ISCONTIGUOUS(op)) || \ + ((order) == PyArray_FORTRANORDER && \ + PyArray_ISFORTRAN(op))) static PyObject * _array_fromobject(PyObject *ignored, PyObject *args, PyObject *kws) { PyObject *op, *ret=NULL; - static char *kwd[]= {"object", "dtype", "copy", "fortran", "subok", + static char *kwd[]= {"object", "dtype", "copy", "order", "subok", "ndmin", NULL}; Bool subok=FALSE; Bool copy=TRUE; int ndmin=0, nd; PyArray_Descr *type=NULL; PyArray_Descr *oldtype=NULL; - PyArray_CONDITION fortran=PyArray_DONTCARE; + PyArray_ORDER order=PyArray_ANYORDER; int flags=0; if (PyTuple_GET_SIZE(args) > 2) { @@ -4463,7 +4479,7 @@ _array_fromobject(PyObject *ignored, PyObject *args, PyObject *kws) PyArray_DescrConverter2, &type, PyArray_BoolConverter, ©, - PyArray_ConditionConverter, &fortran, + PyArray_OrderConverter, &order, PyArray_BoolConverter, &subok, &ndmin)) return NULL; @@ -4471,28 +4487,28 @@ _array_fromobject(PyObject *ignored, PyObject *args, PyObject *kws) /* fast exit if simple call */ if (PyArray_CheckExact(op)) { if (type==NULL) { - if (!copy && STRIDING_OK(op, fortran)) { + if (!copy && STRIDING_OK(op, order)) { Py_INCREF(op); ret = op; goto finish; } else { ret = PyArray_NewCopy((PyArrayObject*)op, - fortran); + order); goto finish; } } /* One more chance */ oldtype = PyArray_DESCR(op); if (PyArray_EquivTypes(oldtype, type)) { - if (!copy && STRIDING_OK(op, fortran)) { + if (!copy && STRIDING_OK(op, order)) { Py_INCREF(op); ret = op; goto finish; } else { ret = PyArray_NewCopy((PyArrayObject*)op, - fortran); + order); if (oldtype == type) return ret; Py_INCREF(oldtype); Py_DECREF(PyArray_DESCR(ret)); @@ -4505,10 +4521,11 @@ _array_fromobject(PyObject *ignored, PyObject *args, PyObject *kws) if (copy) { flags = ENSURECOPY; } - if (fortran == PyArray_FALSE) { + if (order == PyArray_CORDER) { flags |= CONTIGUOUS; } - else if ((fortran == PyArray_TRUE) || + else if ((order == PyArray_FORTRANORDER) || + /* order == PyArray_ANYORDER && */ (PyArray_Check(op) && PyArray_ISFORTRAN(op))) { flags |= FORTRAN; } @@ -4551,16 +4568,17 @@ PyArray_Empty(int nd, intp *dims, PyArray_Descr *type, int fortran) } -static char doc_empty[] = "empty((d1,...,dn),dtype=int,fortran=0) will return a new array\n of shape (d1,...,dn) and given type with all its entries uninitialized. This can be faster than zeros."; +static char doc_empty[] = "empty((d1,...,dn),dtype=int,order='C') will return a new array\n of shape (d1,...,dn) and given type with all its entries uninitialized. This can be faster than zeros."; static PyObject * array_empty(PyObject *ignored, PyObject *args, PyObject *kwds) { - static char *kwlist[] = {"shape","dtype","fortran",NULL}; + static char *kwlist[] = {"shape","dtype","order",NULL}; PyArray_Descr *typecode=NULL; PyArray_Dims shape = {NULL, 0}; - Bool fortran = FALSE; + PyArray_ORDER order = PyArray_CORDER; + Bool fortran; PyObject *ret=NULL; if (!PyArg_ParseTupleAndKeywords(args, kwds, "O&|O&O&", @@ -4568,9 +4586,12 @@ array_empty(PyObject *ignored, PyObject *args, PyObject *kwds) &shape, PyArray_DescrConverter, &typecode, - PyArray_BoolConverter, &fortran)) + PyArray_OrderConverter, &order)) goto fail; + if (order == PyArray_FORTRANORDER) fortran = TRUE; + else fortran = FALSE; + ret = PyArray_Empty(shape.len, shape.ptr, typecode, fortran); PyDimMem_FREE(shape.ptr); return ret; @@ -4676,7 +4697,7 @@ PyArray_Zeros(int nd, intp *dims, PyArray_Descr *type, int fortran) } -static char doc_zeros[] = "zeros((d1,...,dn),dtype=int,fortran=0) will return a new array of shape (d1,...,dn) and type typecode with all it's entries initialized to zero."; +static char doc_zeros[] = "zeros((d1,...,dn),dtype=int,order='C') will return a new array of shape (d1,...,dn) and type typecode with all it's entries initialized to zero."; static PyObject * @@ -4685,6 +4706,7 @@ array_zeros(PyObject *ignored, PyObject *args, PyObject *kwds) static char *kwlist[] = {"shape","dtype","fortran",NULL}; /* XXX ? */ PyArray_Descr *typecode=NULL; PyArray_Dims shape = {NULL, 0}; + PyArray_ORDER order = PyArray_CORDER; Bool fortran = FALSE; PyObject *ret=NULL; @@ -4693,10 +4715,12 @@ array_zeros(PyObject *ignored, PyObject *args, PyObject *kwds) &shape, PyArray_DescrConverter, &typecode, - PyArray_BoolConverter, + PyArray_OrderConverter, &fortran)) goto fail; + if (order == PyArray_FORTRANORDER) fortran = TRUE; + else fortran = FALSE; ret = PyArray_Zeros(shape.len, shape.ptr, typecode, (int) fortran); PyDimMem_FREE(shape.ptr); return ret; |