-
-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Fix two issues with matrices #23671
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
Fix two issues with matrices #23671
Conversation
✅ Hi, I am the SymPy bot (v167). I'm here to help you write a release notes entry. Please read the guide on how to write release notes. Your release notes are in good order. Here is what the release notes will look like:
This will be added to https://github.com/sympy/sympy/wiki/Release-Notes-for-1.11. Click here to see the pull request description that was parsed.
Update The release notes on the wiki have been updated. |
Benchmark results from GitHub Actions Lower numbers are good, higher numbers are bad. A ratio less than 1 Significantly changed benchmark results (PR vs master) before after ratio
[edf24253] [697220be]
+ 25.0±0.08μs 77.8±0.07μs 3.11 matrices.TimeMatrixExpression.time_MatAdd
Significantly changed benchmark results (master vs previous release) before after ratio
[77f1d79c] [edf24253]
<sympy-1.10.1^0>
+ 116±2ms 209±1ms 1.80 sum.TimeSum.time_doit
Full benchmark results can be found as artifacts in GitHub Actions |
@@ -34,7 +34,7 @@ class MatAdd(MatrixExpr, Add): | |||
|
|||
identity = GenericZeroMatrix() | |||
|
|||
def __new__(cls, *args, evaluate=False, check=False, _sympify=True): | |||
def __new__(cls, *args, evaluate=False, check=True, _sympify=True): | |||
if not args: |
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'm still thinking that maybe we should ignore the check argument and always check...
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 also think that is the correct way. Although it may be useful to bypass the checking in some situations...
Maybe set the default to None deprecate passing as value for one release?
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.
(And then introduce a way to create MatAdd and MatMul from correct matrices that can be used from library code.)
Looks good to me. The release note should clarify that this will lead to an exception in some cases. |
I added a deprecation commit. |
I think this looks good. The release note should explain the deprecation. |
There is also a check parameter to HadamardProduct. I guess that should be deprecated too? The docs is not rendering perfectly: https://output.circle-artifacts.com/output/job/5ed52a3a-d256-4abf-bc5c-1cc310325118/artifacts/0/doc/_build/html/explanation/active-deprecations.html?highlight=deprecation But will have to check how this differs to the others. Will improve the release note as well. |
I'm not sure what release note you expect. I can/will of course edit the deprecation section after merging, but before it it merged, it is not so clear what more is expected. |
The benchmark change is probably related?
However, it is not really realistic to have a benchmark that doesn't check... |
I guess the release note just needs the same information that's in the active deprecations file i.e. what is being checked and what specifically is deprecated. Maybe something like:
|
Probably. I don't think that this is an important benchmark but one way to improve it would be to rearrange the logic to make the common path the fast one:
You can see the benchmark here: Another possibility is to try to speed up the checking: sympy/sympy/matrices/expressions/matadd.py Lines 104 to 111 in 9a6104e
|
I thought something like that should do in the deprecation part, but it is now updated. (Note that the same holds for |
Regarding optimization, I do not see any obvious advantage now as it will do away (and there will probably be a different way to create these directly, although maybe not for the benchmarks...). |
98fe435
to
c09e379
Compare
Looks good to me. |
References to other Issues or PRs
Brief description of what is fixed or changed
For some reason the
check
argument toMatAdd
isFalse
which is inconsistent withMatMul
and allows creating things likeMatAdd(matrix, scalar)
that is later on not supported.MatExpr.as_coeff_mmul
did not return a sympified result (compare toMatMul.as_coeff_mmul
).Other comments
Release Notes
MatAdd
could be used to form a mathematically incorrect expression likeMatAdd(1, Matrix([[1, 2]], check=False)
. The intention of thecheck=False
argument is just as an optimization to avoid checking that all arguments are matrices with matching shapes for speed. However, it allowed creating objects that were both mathematically invalid and also break the internal invariant ofMatAdd
which expects that all of its args are of typeMatrixExp
leading to obscure failures in other routines such as printing. In SymPy 1.11 passingcheck
toMatAdd
,MatMul
andHadamardProduct
will emit a deprecation warning. In a future version of SymPy the arguments will always be checked and passing any non-Matrix argument will give an exception.