-
-
Notifications
You must be signed in to change notification settings - Fork 10.9k
Python nditer should reinsert removed axes into its iteration results #9808
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
Comments
In some sense, I don't think that the python side API was ever really aimed for series usage outside of testing, understanding the C-side and some stuff in the direction of numexpr. In some sense I guess it just mirrors the C-API too much. But overall, I think I would rather have a |
Hmm, it may not be intended, but we're definitely using |
I think it is not unintended to use it from python, or bad habit, but I personally believe it has too many quirks to call it a reasonable python API. So it is a very advanced feature and probably not used a lot. |
This was my use case, and I found it very confusing that the removed axes just seemed to dissapear. |
AFAICT this behavior can be traced to here: numpy/numpy/core/src/multiarray/nditer_pywrap.c Line 2001 in 29f0b53
I've noticed if hard-coding innerloopsize = 2;
innerstride = 8;
/* If the iterator is going over every element, return array scalars */
ret_ndim = 1; You get the expected result above. Obviously that's not a real solution...tried to leverage the Will try to dig further and see if there is a solution here, just sharing above in the interim in case its of use to anyone else |
That looks right, if |
I think changing this is fine. I think I remember trying to fix this in the past, and not doing so because it was hard, not because it might break compatibility. |
Cool I'll give it a look over the next few days and see if I can push a PR |
Any pointers on how to introspect the size of the operands at this point during iteration? I think the stride information is accessible through the |
It is a bit tricky, but basically, I do not think the NpyIter will help you at all. I do not even see that it holds on to the What I think you have to do is extract where the |
This sounds like the issue that stumped me. I think my conclusion was that tracking that state was the caller's problem, but I don't remember too well. |
Uh oh!
There was an error while loading. Please reload this page.
When iterating using C, all that's returned is a pointer to the start of the array, and it's the users job to index it with their own memory of its strides and dimensions (like what happens in the gufunc inner loops).
However, the python
nditer[i]
API always returns 0d arrays, and does not produce a view over the axes that were removed.My feeling is that this:
should output
whereas it outputs at the moment
Can someone with a better understanding of
NdIter
confirm that my intuition is correct here?The text was updated successfully, but these errors were encountered: