ENH: Add support for flat indexing on flat iterator#27343
ENH: Add support for flat indexing on flat iterator#27343ngoldbaum merged 4 commits intonumpy:mainfrom
Conversation
b4be96c to
8fd41d0
Compare
8fd41d0 to
76b1b65
Compare
|
For static type-checking purposes it would help if the typing stubs would also reflect this change |
|
I think this is fine, but it should work by converting to an array via normal |
|
I am saying that we shouldn't implement |
mhvk
left a comment
There was a problem hiding this comment.
Yes, makes sense to solve this!
| goto fail; | ||
| } | ||
|
|
||
| if (PyArray_SIZE(tmp_arr) == 0) { |
There was a problem hiding this comment.
Would be good to explicitly test this branch. Should it run only if obj was not already an ndarray?
|
I don't have a problem with the extra |
Does this mean that we should not do the |
|
Something like that. The best thing may be to just call the normal indexing preparation code to ensure we do the same thing. Not sure if that works, but I suspect it will. |
Yeah, that seems like a more involved fix however, since the whole |
|
No, not a complete adjustment hopefully, you would call: numpy/numpy/_core/src/multiarray/mapping.c Line 277 in cc9f8aa |
Would we use |
|
Hmmm, True, so it might not actually work without changes. It may be that all it needs from the array is the number of dimensions, but not sure. |
|
I gave this a try, but I'm too unfamiliar with this part of the codebase so I didn't have much progress. Maybe it'd be okay for this to go in as-is (after I've added some more tests) and open a follow-up issue to rework |
|
Friendly ping. |
|
Well, I can see that re-using numpy/numpy/_core/src/multiarray/mapping.c Line 413 in c045306 The only reason not to do that, is that it would fix currently broken cases like:
Which means you can convince me that we don't need to merge it, but I think only if we allow doing it in the future (and deprecate/warn about those). |
|
We looked at this in a triage meeting and would like to see this handle more general array types as @seberg says just above. @lysnikolaou what do you think? |
|
Thanks for the update @mattip and sorry for taking so long to reply here. I'll spend some time on this this week to hopefully get it over the finish line. |
|
Hey folks! Sorry for the delay here, but I came back to this today and I just pushed a commit that I think is closer to what we want. EDIT: Deleted a question that I didn't think through. Answer is clear to me now. |
|
Gentle ping on this, in case anyone has some spare cycles for a review. |
seberg
left a comment
There was a problem hiding this comment.
I'll approve in the grand-scheme of things. I haven't quite thought about the non-integer madness here.
(In a sense, I am not sure I think the size == 0 check matters, since we already accept the empty list and that is what I would worry most about. But it also seems right, so...)
And yeah, merging with the above only works if we try to start fixing the fact that arr.flat[[False, True, False]] returns the wrong thing. Which we absolutely should do of course
|
Thanks @lysnikolaou! Could you open the followup issue to track further improvements to |
Closes #27342.
Obviously a bit of discussion might be needed before this gets accepted. I'm opening the PR as a means to show that the implementation only requires a minimal amount of changes.