-
Notifications
You must be signed in to change notification settings - Fork 129
Fix bug in TensorVariable.__rmatmul__
#465
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
TensorVariable.__rmatmul__
I'm not positive Digging a bit into the failure case:
exp_res looks like this:
The dprint for each cell looks like this (this is cell 0,0)
Evidently it's broadcasting multiplication of
It seems like it's treating X like a batch? |
To be clear, numpy.array().dot(TensorVariable) doesn't work (and never did AFAICT) and I couldn't see anything we could do about it without delving into the I added an explicit check on a test so we "know it's broken". Note that |
About the |
@@ -98,10 +100,15 @@ def test_infix_matmul_method(): | |||
assert equal_computations([res], [exp_res]) | |||
|
|||
X_val = np.arange(2 * 3).reshape((2, 3)) | |||
res = as_tensor(X_val) @ y | |||
res = X_val @ y |
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.
This is the test relevant to the reported bug
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 was running test_dot_method
, and it failed with an error that __dot__
was not implemented
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.
Right but if that's the only test that used it, it's not a reason to have the mysterious dunder method. I couldn't see it being used anywhere else nor could I see how to trigger it naturally
I will believe you that np.array @ TensorVariable never worked, but it seems a bit sus. Shouldn't this have come up before if true? PyMC users mix numpy/pytensor objects all the time. EDIT: Actually I'm all confused now. @tomicapretto reported that Array @ Tensor ( |
@ worked!!! But it used to use pt.dot under the hood and not pt.matmul. I fixed it to use pt.matmul in #452 but messed up the order of arguments in
|
To recap:
|
4869cf1
to
0a058bd
Compare
0a058bd
to
686725c
Compare
Okay so the pytensor/pytensor/tensor/math.py Lines 2045 to 2066 in 071eadd
Seems a bit odd, and I am sure other stuff like |
Codecov Report
Additional details and impacted files@@ Coverage Diff @@
## main #465 +/- ##
=======================================
Coverage 80.65% 80.65%
=======================================
Files 160 160
Lines 46022 46022
Branches 11265 11265
=======================================
+ Hits 37120 37121 +1
+ Misses 6669 6668 -1
Partials 2233 2233
|
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.
Thanks for being patient with my questions. This is good to go. I agree the infixes for dot are a strange design choice, but it's a detail for another day.
Introduced in #452
Closes #464
CC @tomicapretto