MAINT: do not use copyswap in flatiter internals#24176
Conversation
seberg
left a comment
There was a problem hiding this comment.
Some nits, mostly leave or take (or probably just leave because the below comment makes them not matter anymore).
One larger comment. It seems to me we can pass in the function into iter_ass_sub_int, iter_ass_sub_Bool, etc. Which means we can liberate getting the transfer function to before the if (PySlice_Check(ind)).
That will mean we only to the code once rather than 3 times and the cleanup is fully outside of those helpers.
The same should work for the iter_subscript* paths, with the added finish: label and goto finish.
70d33bf to
e2259b2
Compare
|
Thanks for the review @seberg! Simplified so there's only one cast setup that is passed to the boolean and integer indexing helpers. Let me know if you spot any additional issues. |
seberg
left a comment
There was a problem hiding this comment.
Thanks for that and even doing some of the smaller things. Cleanup now looks all good to me, so lets put it in.
Fixes #23486.
Updates all the code paths used by the flatiter getter and setter to use single-element casts instead of copyswap. This allows new dtypes to use these code paths without seg faulting.
I ran the flatiter benchmarks and didn't see any significant performance changes, but there seem to only be benchmarks for boolean indexing. I could probably substantially improve performance by only using copyswap in situations where it's required but using a hand-unrolled
memcpylikefasttakeotherwise but only want to fix the seg faults for now.