summaryrefslogtreecommitdiff
path: root/numpy/core/src/arraymethods.c
diff options
context:
space:
mode:
authorTravis Oliphant <oliphant@enthought.com>2006-12-02 00:35:09 +0000
committerTravis Oliphant <oliphant@enthought.com>2006-12-02 00:35:09 +0000
commit574fe369112ded91f80502db73022a8fd79d3fe3 (patch)
tree904b1b27f758c7e5d6c2790a8f5066300f5b5a15 /numpy/core/src/arraymethods.c
parent5898c2c445cb7fe14e2866b34f625e6f95bbf82f (diff)
downloadnumpy-574fe369112ded91f80502db73022a8fd79d3fe3.tar.gz
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.
Diffstat (limited to 'numpy/core/src/arraymethods.c')
-rw-r--r--numpy/core/src/arraymethods.c36
1 files changed, 31 insertions, 5 deletions
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 *