From 574fe369112ded91f80502db73022a8fd79d3fe3 Mon Sep 17 00:00:00 2001 From: Travis Oliphant Date: Sat, 2 Dec 2006 00:35:09 +0000 Subject: Add order keyword to argsort and fix documentation of sort and argsort. Also, fix so that a Python long is passed to mmap instead of an array scalar. Fix setting when using mixed array indices and slice objects by making sure to swap the object in the reverse direction to the swapping that takes place on the MapGet operations. --- numpy/core/src/arraymethods.c | 36 +++++++++++++++++++++++++++++++----- 1 file changed, 31 insertions(+), 5 deletions(-) (limited to 'numpy/core/src/arraymethods.c') diff --git a/numpy/core/src/arraymethods.c b/numpy/core/src/arraymethods.c index b48c0c02b..d33fbc70e 100644 --- a/numpy/core/src/arraymethods.c +++ b/numpy/core/src/arraymethods.c @@ -862,12 +862,13 @@ array_sort(PyArrayObject *self, PyObject *args, PyObject *kwds) &order)) return NULL; + if (order == Py_None) order = NULL; if (order != NULL) { PyObject *new_name; saved = self->descr; if (saved->names == NULL) { PyErr_SetString(PyExc_ValueError, "Cannot specify " \ - "order with no fields."); + "order when the array has no fields."); return NULL; } new_name = PyObject_CallMethod(_numpy_internal, "_newnames", @@ -893,13 +894,38 @@ array_argsort(PyArrayObject *self, PyObject *args, PyObject *kwds) { int axis=-1; PyArray_SORTKIND which=PyArray_QUICKSORT; - static char *kwlist[] = {"axis", "kind", NULL}; + PyObject *order=NULL, *res; + PyArray_Descr *newd, *saved=NULL; + static char *kwlist[] = {"axis", "kind", "order", NULL}; - if (!PyArg_ParseTupleAndKeywords(args, kwds, "|iO&", kwlist, &axis, - PyArray_SortkindConverter, &which)) + if (!PyArg_ParseTupleAndKeywords(args, kwds, "|iO&O", kwlist, &axis, + PyArray_SortkindConverter, &which, + &order)) return NULL; - return _ARET(PyArray_ArgSort(self, axis, which)); + if (order == Py_None) order = NULL; + if (order != NULL) { + PyObject *new_name; + saved = self->descr; + if (saved->names == NULL) { + PyErr_SetString(PyExc_ValueError, "Cannot specify " \ + "order when the array has no fields."); + return NULL; + } + new_name = PyObject_CallMethod(_numpy_internal, "_newnames", + "OO", saved, order); + if (new_name == NULL) return NULL; + newd = PyArray_DescrNew(saved); + newd->names = new_name; + self->descr = newd; + } + + res = PyArray_ArgSort(self, axis, which); + if (order != NULL) { + Py_XDECREF(self->descr); + self->descr = saved; + } + return _ARET(res); } static PyObject * -- cgit v1.2.1