GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | ||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | ||||
GeezerVison is showing github.com — PERF: avoid an unnecessary copy in np.take with out= by Ijtihed · Pull Request #31940 · numpy/numpy Conversation
Contributor
PR summaryFixes #28636.
this removes that copy so in there IS a behavior change on an out-of-bounds index since Before/after
The no- AI DisclosureUsed AI to double check my code + find any edge cases I might've missed :)
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactions
|
There was an error while loading. Please reload this page.
|
@mattip since you mentioned this I thought you might be interested :) |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
If the consensus is to just let out be modified, that is like basic guarantee in terms of c++ exception safety. I'd be tempted to add an additional message to the raised error in that case. Like if the error is raised and out= is set, you also say in the error message that out may be modified. cc @seberg @mattip what do you think? It can be done using by getting the exception that would be raised which is IndexError: index 4 is out of bounds and adding a note to it using the add_note method they have (numpy is already 3.12+). Something like
if (npy_fasttake( dest, src, indices_data, n, m, max_item, nelem, chunk, clipmode, itemsize, needs_refcounting, src_descr, dst_descr, axis) < 0) { if (out != NULL && obj == out) { PyObject *exc = PyErr_GetRaisedException(); if (exc != NULL) { PyObject *res = PyObject_CallMethod(exc, "add_note", "s", "the output array `out` may have been partially modified"); if (res == NULL) { PyErr_Clear(); } Py_XDECREF(res); PyErr_SetRaisedException(exc); } } goto fail; }
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
That might be a little bit of an excessive testing for this kind of tiny change IMO.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
|
I like the add-note idea, although it applies to many operations (i.e. if we do that, I think it should probably be a central helper and maybe added to some other places). FWIW, it seems OK to me, although I don't care too much either way ( |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
e87e7ba to
d27656a
Compare
|
thanks both! I added a compatibility release note documenting that out can now be partially modified if an out of bounds index raises (the relaxed guarantee) then dropped the refcount-asserting test and trimmed the rest down to the essentials so there's no getrefcount asserts left. leak coverage can just be left to the sanitized CI @ikrommyd @seberg I left add_note out for now since i agree it makes more sense as a central helper across the ops that can partially write out :) |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
I'd also be happy to open a pr for this too if you think it makes sense |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
take slower when out is provided
There was an error while loading. Please reload this page.