NUMPY_API *LexSort an array providing indices that will sort a collection of arrays *lexicographically. The first key is sorted on first, followed by the second key *-- requires that arg"merge"sort is available for each sort_key * *Returns an index array that shows the indexes for the lexicographic sort along *the given axis. */
| 1768 | *the given axis. |
| 1769 | */ |
| 1770 | NPY_NO_EXPORT PyObject * |
| 1771 | PyArray_LexSort(PyObject *sort_keys, int axis) |
| 1772 | { |
| 1773 | PyArrayObject **mps; |
| 1774 | PyArrayIterObject **its; |
| 1775 | PyArrayObject *ret = NULL; |
| 1776 | PyArrayIterObject *rit = NULL; |
| 1777 | npy_intp n, N, size, i, j; |
| 1778 | npy_intp astride, rstride, *iptr; |
| 1779 | int nd; |
| 1780 | int needcopy = 0; |
| 1781 | int elsize; |
| 1782 | int maxelsize; |
| 1783 | int object = 0; |
| 1784 | PyArray_ArgSortFunc *argsort; |
| 1785 | NPY_BEGIN_THREADS_DEF; |
| 1786 | |
| 1787 | if (!PySequence_Check(sort_keys) |
| 1788 | || ((n = PySequence_Size(sort_keys)) <= 0)) { |
| 1789 | PyErr_SetString(PyExc_TypeError, |
| 1790 | "need sequence of keys with len > 0 in lexsort"); |
| 1791 | return NULL; |
| 1792 | } |
| 1793 | mps = (PyArrayObject **) PyArray_malloc(n * sizeof(PyArrayObject *)); |
| 1794 | if (mps == NULL) { |
| 1795 | return PyErr_NoMemory(); |
| 1796 | } |
| 1797 | its = (PyArrayIterObject **) PyArray_malloc(n * sizeof(PyArrayIterObject *)); |
| 1798 | if (its == NULL) { |
| 1799 | PyArray_free(mps); |
| 1800 | return PyErr_NoMemory(); |
| 1801 | } |
| 1802 | for (i = 0; i < n; i++) { |
| 1803 | mps[i] = NULL; |
| 1804 | its[i] = NULL; |
| 1805 | } |
| 1806 | for (i = 0; i < n; i++) { |
| 1807 | PyObject *obj; |
| 1808 | obj = PySequence_GetItem(sort_keys, i); |
| 1809 | if (obj == NULL) { |
| 1810 | goto fail; |
| 1811 | } |
| 1812 | mps[i] = (PyArrayObject *)PyArray_FROM_O(obj); |
| 1813 | Py_DECREF(obj); |
| 1814 | if (mps[i] == NULL) { |
| 1815 | goto fail; |
| 1816 | } |
| 1817 | if (i > 0) { |
| 1818 | if ((PyArray_NDIM(mps[i]) != PyArray_NDIM(mps[0])) |
| 1819 | || (!PyArray_CompareLists(PyArray_DIMS(mps[i]), |
| 1820 | PyArray_DIMS(mps[0]), |
| 1821 | PyArray_NDIM(mps[0])))) { |
| 1822 | PyErr_SetString(PyExc_ValueError, |
| 1823 | "all keys need to be the same shape"); |
| 1824 | goto fail; |
| 1825 | } |
| 1826 | } |
| 1827 | if (!PyArray_DESCR(mps[i])->f->argsort[NPY_STABLESORT] |
no test coverage detected