-
-
Notifications
You must be signed in to change notification settings - Fork 4.6k
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 calculation of rank of matrix. #11479
Conversation
@@ -27,7 +27,10 @@ | |||
|
|||
def _iszero(x): | |||
"""Returns True if x is zero.""" | |||
return x.is_zero | |||
if hasattr(x, "free_symbols") and not x.free_symbols: |
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.
When does x not have free_symbols
?
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.
At any rate, you can use getattr(x, 'free_symbols', set())
.
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.
Actually, I think, if x does not have free_symbols
, value of hasattr(x, "free_symbols") and not x.free_symbols
will False and we use else-branch. But, yes, I can use getattr
This should also fix some issues with |
I think using equals in _iszero is a good fix for this issue (at least until we write matrices with real domains). Raw simplify is too slow, as you saw (it's actually worse, because unlike your benchmark, it's really easy for simplify to just hang forever). is_zero has simple errors. equals should be a good middle ground, that misses most errors, but is performant as well. |
PR #11554 resolves this issue, but doesn't include any benchmarks. Could this PR be reworked to include benchmarks? |
@ rpisarev Do you want to rework this as benchmarks? If not, we will close the PR. |
Hi. I don't know how I should add benchmark |
@rpisarev I think benchmarks are in the separate repository https://github.com/sympy/sympy_benchmarks Can you send a PR there? |
@siefkenj did PR sympy/sympy_benchmarks#34 made all the necessary benchmarks? Should this PR be closed or kept open? |
The benchmarks added in sympy/sympy_benchmarks#34 are slightly different, but they should be sufficient. |
So I think this PR can be closed then. The necessary code got merged in PR #11554 and the necessary benchmarks were added in sympy/sympy_benchmarks#34 . Thanks @siefkenj for the explanation. |
Fix calculation of rank of a matrix with complicated elements.
This PR able to close #9480 and #11238.
I did some performance test for 3 implementations of _iszero()
So, 1st function (from current master):
We can see next:
If we can use function from #10650,
we will get
So, the second implementation is slower as first and as wrong, as first.
Third function (this PR):
And we have output:
Third implementation is slower as first too, and even as second. But, it is absolutly right.