diff options
author | pdmurray <peynmurray@gmail.com> | 2023-03-03 11:21:37 -0800 |
---|---|---|
committer | pdmurray <peynmurray@gmail.com> | 2023-03-07 14:32:33 -0800 |
commit | 3c2a5d430ea6ce97fe7c4864a996f23415281b17 (patch) | |
tree | 33996958eb37a00b2ea6d9d32265dafc9b32fe75 /numpy | |
parent | 74a127974a66b6a70667cc6d6d3597880bc81d2b (diff) | |
download | numpy-3c2a5d430ea6ce97fe7c4864a996f23415281b17.tar.gz |
ENH: Add support for argmin and argmax for NEP42 dtypes
Diffstat (limited to 'numpy')
-rw-r--r-- | numpy/core/src/multiarray/calculation.c | 17 |
1 files changed, 11 insertions, 6 deletions
diff --git a/numpy/core/src/multiarray/calculation.c b/numpy/core/src/multiarray/calculation.c index a985a2308..62a994c64 100644 --- a/numpy/core/src/multiarray/calculation.c +++ b/numpy/core/src/multiarray/calculation.c @@ -7,6 +7,7 @@ #include "numpy/arrayobject.h" #include "lowlevel_strided_loops.h" +#include "dtypemeta.h" #include "npy_config.h" @@ -50,7 +51,7 @@ _PyArray_ArgMinMaxCommon(PyArrayObject *op, int axis_copy = axis; npy_intp _shape_buf[NPY_MAXDIMS]; npy_intp *out_shape; - // Keep the number of dimensions and shape of + // Keep the number of dimensions and shape of // original array. Helps when `keepdims` is True. npy_intp* original_op_shape = PyArray_DIMS(op); int out_ndim = PyArray_NDIM(op); @@ -87,9 +88,13 @@ _PyArray_ArgMinMaxCommon(PyArrayObject *op, op = ap; } - /* Will get native-byte order contiguous copy. */ - ap = (PyArrayObject *)PyArray_ContiguousFromAny((PyObject *)op, - PyArray_DESCR(op)->type_num, 1, 0); + // Will get native-byte order contiguous copy. + PyArray_Descr *descr = NPY_DT_CALL_ensure_canonical(PyArray_DESCR(op)); + if (descr == NULL) { + return NULL; + } + ap = (PyArrayObject *)PyArray_FromArray(op, descr, NPY_ARRAY_DEFAULT); + Py_DECREF(op); if (ap == NULL) { return NULL; @@ -106,9 +111,9 @@ _PyArray_ArgMinMaxCommon(PyArrayObject *op, for (int i = 0; i < out_ndim; i++) { out_shape[i] = 1; } - } + } else { - /* + /* * While `ap` may be transposed, we can ignore this for `out` because the * transpose only reorders the size 1 `axis` (not changing memory layout). */ |