-
-
Notifications
You must be signed in to change notification settings - Fork 11k
BUG (I guess?): Make a @= b error out #6000
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
Doh, right, there's actually no way to test this at all except on py3.5. Our current |
43d7e90
to
3859b2f
Compare
Just pushed a new version of this that's ready for review. I tested 3859b2f locally against a recent python 3.5 build, and the new test passed. |
# we avoid writing the token `exec` so as not to crash python 2's | ||
# parser | ||
exec_ = getattr(builtins, "exec") | ||
assert_raises(TypeError, exec_, "a @= b", globals(), locals()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could also use operator.imatmul
probably, though I am not sure I care.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Eh, sure, I'll throw that in too :-)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought to avoid the exec dance ;p, but nvm. All is good in any case.
Anyway, seems the right thing to do to just not support it for the moment. For stacked matrices, it would probably be easy to support (and make sense to safe memory), since einsum supports it, and I think we currently use einsum (for non-stacked, a simple assignment using |
Nvm. it is not possible to support even with einsum, since it should be (at least almost) impossible to force correct/large enough buffering. (It might be that forcing buffering + iteration size would do, but I don't even think einsum exposes that). |
Before this change, we defined a nb_matrix_multiply slot but not a nb_inplace_matrix_multiply slot, which means that a statement like a @= b would be silently expanded by the CPython interpreter to become a = a @ b This is undesireable, because it produces unexpected memory allocations, breaks view relationships, and so forth. This commit adds a nb_inplace_matrix_multiply slot which simply errors out, and suggests that users write 'a = a @ b' explicitly if that's what they want.
3859b2f
to
1adcdf7
Compare
Addressed all comments. |
Thanks. |
Before this change, we defined a
nb_matrix_multiply
slot but not anb_inplace_matrix_multiply
slot, which means that a statement likewould be silently expanded by the CPython interpreter to become
This is undesireable, because it produces unexpected memory
allocations, breaks view relationships, and so forth.
This commit adds a
nb_inplace_matrix_multiply
slot which simply errorsout, and suggests that users write
a = a @ b
explicitly if that'swhat they want.
[Noticed this while working on a
__numpy_ufunc__
patch, so here's a quick fix that I haven't even tested yet :-). Let's see what Travis says...]