Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

BUG: index overlap copy #26958

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
May 15, 2025
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
Next Next commit
MAINT: PR 26958 revisions
* Revise the fix for index memory overlap to use
a regular array copy on the indices rather than
a deepcopy, which was a bit more heavyweight than
needed.
  • Loading branch information
tylerjereddy committed May 10, 2025
commit 7557d693991b0698ae65c7279341491648e43b64
16 changes: 1 addition & 15 deletions 16 numpy/_core/src/multiarray/mapping.c
Original file line number Diff line number Diff line change
Expand Up @@ -1797,7 +1797,6 @@ array_assign_subscript(PyArrayObject *self, PyObject *ind, PyObject *op)
PyArray_Descr *descr = PyArray_DESCR(self);
PyArrayObject *view = NULL;
PyArrayObject *tmp_arr = NULL;
PyObject *copy, *deepcopy;
npy_index_info indices[NPY_MAXDIMS * 2 + 1];

PyArrayMapIterObject *mit = NULL;
Expand Down Expand Up @@ -1971,20 +1970,7 @@ array_assign_subscript(PyArrayObject *self, PyObject *ind, PyObject *op)
Py_SETREF(tmp_arr, (PyArrayObject *)PyArray_NewCopy(tmp_arr, NPY_ANYORDER));
}
if (index_has_memory_overlap(self, index_type, indices, index_num, (PyObject *)tmp_arr) == 1) {
copy = PyImport_ImportModule("copy");
if (copy == NULL) {
goto fail;
}
deepcopy = PyObject_GetAttrString(copy, "deepcopy");
if (deepcopy == NULL) {
Py_DECREF(copy);
goto fail;
}
Py_DECREF(copy);
PyObject *args = PyTuple_Pack(1, indices->object);
Py_SETREF(indices->object, PyObject_CallObject(deepcopy, args));
Py_DECREF(deepcopy);
Py_DECREF(args);
Py_SETREF(indices->object, PyArray_NewCopy((PyArrayObject *)indices->object, NPY_KEEPORDER));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I don't know how I missed both pings. This doesn't work, indices-> is a C array of index information.

If you add a test like:

a[2:][None, a[:-2]] = 3

that should just segfault. The other place where the index_has_memoverlap is used actually copies the result (self here and then uses the Writebackifcopy mechanism to make that work).

Now, it may be however, that this is sufficient, because it could be that this only is relevant to the fast path (because otherwise the iterator setup can protect us).


Either way, not sure that you want to look at it again, which is fine... Just realized that I never responded.

}

/*
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.