Skip to content

Commit

Permalink
Merge pull request #23337 from peytondmurray/argminmax-nep42-dtype-su…
Browse files Browse the repository at this point in the history
…pport

ENH: Add support for argmin and argmax for NEP42 dtypes
  • Loading branch information
seberg committed Mar 8, 2023
2 parents 4db5303 + 3c2a5d4 commit ea0b170
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions numpy/core/src/multiarray/calculation.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

#include "numpy/arrayobject.h"
#include "lowlevel_strided_loops.h"
#include "dtypemeta.h"

#include "npy_config.h"

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand All @@ -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).
*/
Expand Down

0 comments on commit ea0b170

Please sign in to comment.