Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
BUG: avoid data race in PyArray_Repeat
  • Loading branch information
ngoldbaum authored and charris committed Jan 21, 2025
commit cec8fbfbb8ad4fe3f5255336d35071adfe38c146
13 changes: 10 additions & 3 deletions numpy/_core/src/multiarray/item_selection.c
Original file line number Diff line number Diff line change
Expand Up @@ -922,16 +922,23 @@ PyArray_Repeat(PyArrayObject *aop, PyObject *op, int axis)
}
}

/* Fill in dimensions of new array */
npy_intp dims[NPY_MAXDIMS] = {0};

for (int i = 0; i < PyArray_NDIM(aop); i++) {
dims[i] = PyArray_DIMS(aop)[i];
}

dims[axis] = total;

/* Construct new array */
PyArray_DIMS(aop)[axis] = total;
Py_INCREF(PyArray_DESCR(aop));
ret = (PyArrayObject *)PyArray_NewFromDescr(Py_TYPE(aop),
PyArray_DESCR(aop),
PyArray_NDIM(aop),
PyArray_DIMS(aop),
dims,
NULL, NULL, 0,
(PyObject *)aop);
PyArray_DIMS(aop)[axis] = n;
if (ret == NULL) {
goto fail;
}
Expand Down