-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
Optimized arithmetic methods for strided triangular matrices #52571
Conversation
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.
LGTM
Since the values stored in the parent corresponding to the structural zeros of a tridiagonal matrix aren't well-defined, using it in `ldiv!` is a footgun that may lead to heisenbugs (one seen in https://buildkite.com/julialang/julia-master/builds/31285#018c7cc7-6c77-41ac-a01b-1c7d14cb1b15). This PR changes it to using the tridiagonal matrix directly in `ldiv!`, which should lead to predictable results, and be bug-free. The failing tests for #52571 pass locally with this change.
Although this PR improves performance and resolves several issues, I don't really like the hacky nature of the new methods that are specifically working around bugs with using a partly initialized |
Ready to go? I still like it. 😉 |
Looks good to me. Perhaps we should update the branch to ensure that the tests are passing? Unfortunately my computer has broken down, so progress has stalled |
Test failures appear unrelated, so should be good |
Since the values stored in the parent corresponding to the structural zeros of a tridiagonal matrix aren't well-defined, using it in `ldiv!` is a footgun that may lead to heisenbugs (one seen in https://buildkite.com/julialang/julia-master/builds/31285#018c7cc7-6c77-41ac-a01b-1c7d14cb1b15). This PR changes it to using the tridiagonal matrix directly in `ldiv!`, which should lead to predictable results, and be bug-free. The failing tests for #52571 pass locally with this change. (cherry picked from commit ef549ae)
Since the values stored in the parent corresponding to the structural zeros of a tridiagonal matrix aren't well-defined, using it in `ldiv!` is a footgun that may lead to heisenbugs (one seen in https://buildkite.com/julialang/julia-master/builds/31285#018c7cc7-6c77-41ac-a01b-1c7d14cb1b15). This PR changes it to using the tridiagonal matrix directly in `ldiv!`, which should lead to predictable results, and be bug-free. The failing tests for #52571 pass locally with this change. (cherry picked from commit ef549ae)
This uses broadcasting for operations like
A::UpperTriangular + B::UpperTriangular
in case the parents areStridedMatrix
es. Looping only over the triangular part is usually faster for large matrices, where presumably memory is the bottleneck.Some performance comparisons, using
-U
1.011 ms (3 allocations: 7.63 MiB)
559.680 μs (3 allocations: 7.63 MiB)
U + U
/U - U
971.740 μs (3 allocations: 7.63 MiB)
560.063 μs (3 allocations: 7.63 MiB)
U + U1
/U - U1
3.014 ms (9 allocations: 22.89 MiB)
944.772 μs (3 allocations: 7.63 MiB)
U1 + U1
4.509 ms (12 allocations: 30.52 MiB)
1.687 ms (3 allocations: 7.63 MiB)
U1 - U1
3.357 ms (9 allocations: 22.89 MiB)
1.763 ms (3 allocations: 7.63 MiB)
I've retained the existing methods as fallback, in case there's current code that works without broadcasting.