-
Notifications
You must be signed in to change notification settings - Fork 269
BUG: change the type of @
result from MatrixVariable
to MatrixExpr
#1059
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
base: master
Are you sure you want to change the base?
Conversation
Implements the __matmul__ method for MatrixExpr, enabling matrix multiplication using the @ operator and ensuring the result is returned as a MatrixExpr instance.
Adds tests to verify that matrix multiplication returns MatrixExpr instead of MatrixVariable for various input shapes.
Replaces isinstance checks with type() comparisons for MatrixExpr in matrix matmul return type tests to ensure exact type matching.
# test 1D @ 1D → 0D | ||
x = m.addMatrixVar(3) | ||
assert type(x @ x) is MatrixExpr |
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.
Here, we can't use isinstance
. Because MatrixVariable
is a subclass of MatrixExpr
.
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.
The result of x@x
is a size 1 matrix. What type should it be, MatrixExpr
or Expr
?
Related to #1057
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.
Should isinstance(x @ x)
not be True
for both MatrixVariable
and MatrixExpr
? I personally don't mind using type
, but is there actually a need?
A size 1 matrix should still be a MatrixExpr
. I don't think we should be removing the matrix language for the user, as that's just going to cause confusion.
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.
MatrixVariable
has the .vtype()
method. But the x@x
doesn't have this method.
So the result of x@x
should be MatrixExpr
, not MatrixVariable
.
To test this, I use type
to check x@x
is a MatrixExpr
.
Corrects the shapes of matrix variables in test_matrix_matmul_return_type to ensure proper 2D matrix multiplication and type assertion.
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.
Happy with this change! (Would like an answer to type
vs isinstance
first though)
Thanks for the contribution!
fix #1058