-
-
Notifications
You must be signed in to change notification settings - Fork 10.9k
BUG difference in behaviour for subclass output in ufuncs #4753
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
Conversation
Is this something that was not addressed in gh-4626? EDIT: apparently yes. this is an oversight |
@cowlicks: overlooked case. Also, what should |
Checking 1.10 blockers brought up by my |
I'll take a look this weekend. |
Okay so what currently happens is |
Surely there is somewhere in the ufunc logic where the arguments are ...okay reading the code you linked to I see that the numpy_ufunc code On Mon, Jan 26, 2015 at 4:00 AM, Blake Griffith notifications@github.com
Nathaniel J. Smith |
They are only normalized (to what |
I know it's more work and may spill over into cleaning up other people's
|
Yeah, that is definitely the right way to do this. I'm not sure why I did not do it that way originally. I'll try to find where that happens and check it out... After I get this working. |
Had a look at the prototype and while it looks good generally, I worry it would still break for ufuncs with two outputs (where |
Little update: I rebased on current master and the segfault went away... So it wasn't my fault I guess? That had me stumped for a while. Working on a fix taking @mhvk's comments into consideration. |
This seems to fix it. But I have not refactored to use the general arg processing as suggested by @njsmith. I have not assessed the difficulty of that yet. If it seems hard I'll make an issue with a plan of action. I think there is still cleaning up to do. And I have not checked that I did not create any memory leaks. I'm not confident in my C coding. So I'll double check this then make a PR. |
looks good to me, but am definitely even less of an expert. |
There is a bit of a problem. The def __numpy_ufunc__(self, ufunc, method, i, inputs, **kwargs) Where " Basically |
FWIW: I think the approach you took, of just continuing to add to |
Hmm, fortunately, |
If it hasn't been released perhaps the signature should be changed. Maybe add an Is it documented anywhere that passing an output array can effect the ufunc dispatch? Seems kind of surprising that it work this way. |
@ewmoore - but the output should not just be treated as an arbitrary |
Only the option |
I'd also think |
Okay. I'll correct the test that is failing to check for |
No I never got around it. There is a lot of discussion around |
@cowlicks - I think this bug has little to do with the (long) discussion about what to do with |
…tely for the case where self is among outputs but not among inputs. Ensure it works both out passed on as an argument and with out in a keyword argument.
OK, I added further tests that the index passed on to |
OK, going to say something unpopular. (Certainly I'm annoyed at myself for saying it, but nonetheless...) I've been debating this with myself for a while, and I've come to the conclusion that we should bite the bullet and drop the index argument from Rationale:
Sorry. I'm the one who suggested adding it in the first place, but it was a bad idea :-/ Also while we're at it, we should make the out= argument unconditionally a tuple, rather than sometimes a single ndarray and sometimes a tuple of them. This would simplify argument processing (see: all the times we wrote |
@njsmith - I made your point a new issue #5986, as I think it deserves better discussion than it might get here. Also, this PR is really not so much about what to do with the |
I think the status is: this is an uncontroversial bug, and @mhvk has a plausible patch here, which hasn't been converted into a PR yet. This isn't necessarily a 1.10 blocker (it would be annoying to release with a bug in As a practical matter it would probably be best to get #6001 and #5986 sorted out first before addressing this, to avoid collisions. |
@njsmith - note that my patch did get converted to a PR -- this issue itself has been converted to a PR [1]. I actually don't think it impacts any other the other PR too much. If we remove |
Moved this to the 1.11.0 release with the rest of the |
@charris - I think this PR is all OK for the present So, my feeling is to merge this, in order to let the test case rather than this open PR guard against the problem recurring. |
BUG difference in behaviour for subclass output in ufuncs
@mhvk OK, merging. Thanks. |
If one wants to have the output of a
ufunc
passed to a ndarray subclass, but the input is a regular array, the behaviour differs depending on whether one passes the output as a positional or as a keyword argument: if passed as positional argument,__numpy_ufunc__
is called, while if passed as a keyword argument,__array_prepare__
and__array_wrap__
are called. I would have expected for__numpy_ufunc__
to be called in both cases.p.s. If the input is a subclass, it always works as expected.
Example script: