-
Notifications
You must be signed in to change notification settings - Fork 176
add matrix magic methods #4729
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: main
Are you sure you want to change the base?
add matrix magic methods #4729
Conversation
| else: | ||
| return NotImplemented | ||
|
|
||
| def __matmul__(self, other): |
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.
If this class inherits from ufl.Matrix, and ufl.Matrix is a BaseForm, shouldn't it already inherit addition and scalar multiplication?
I'm not aware of matrix multiplication being implemented in BaseForm, but it seems that it would not harm to have it there.
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.
Matrix multiplication is there, but it seems that it only supports multiplication times a Function (and breaks for Cofunction and Matrix).
https://github.com/FEniCS/ufl/blob/main/ufl/form.py#L247
https://github.com/FEniCS/ufl/blob/main/ufl/form.py#L219-L225
| def __truediv__(self, other): | ||
| # Scalar division | ||
| if isinstance(other, Complex | Constant): | ||
| other = other.values().item() if isinstance(other, Constant) else other |
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 a bit dangerous, we are silently freezing the Constant. This returns a symbolic expression that no longer makes reference to the Constant, which is inconsistent with how scalar multiplication is 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.
It might be better to leave this one for a separate PR where we enable BaseFormAssembler to numerically evaluate constant-valued symbolic expressions in the weights of a FormSum.
No description provided.