Rewrite forward_substitution and back_substitution#152
Rewrite forward_substitution and back_substitution#152AtheMathmo merged 7 commits intoAtheMathmo:masterfrom
Conversation
This lets us leverage the optimized implementation of dot, and the resulting code is a lot cleaner. Plus, we avoid an unnecessary allocation to boot.
|
Update: I took the liberty of removing the |
|
This is awesome! I don't think that removing |
|
@AtheMathmo: please take as long as you want with the reviews. I'd rather you focus properly on your midterm :) I just found myself with some unexpected time to work on |
|
I massively appreciate all of the changes you've put in so far - they're big leaps in usability and performance. Thank you! |
|
Thanks for saying so! I'm learning a lot myself in the process, so I'm very happy to work on it :) |
|
I merged in #142 which has given some conflicts here. I'll try to review regardless. |
| let true_solution = vector![42.85714286, 18.75, 7.14285714, 52.67857143, | ||
| 25.0, 9.82142857, 42.85714286, 18.75, 7.14285714]; | ||
|
|
||
| // Note: the "true_solution" given here has way too few |
There was a problem hiding this comment.
This is definitely fine - I think if we are within 1e-8 we can safely assume the implementation is correct. We might be missing some tricks to improve accuracy but these should be captured in a separate test where necessary.
|
This looks good to me. Once the conflicts are resolved I am happy to merge. |
|
Should be good to go now assuming tests complete successfully. Thanks for taking a look! |
I had some problems with these functions because they returned an error for empty matrices. In my opinion, solving a system
Ax = bfor emptyAandbshould merely return an emptyx. I've had some major grievances in the past with this exact situation with Eigen, which doesn't handle this situation very well. My application generated linear systems from geometrical meshes, and sometimes these systems turned out to be "empty". Graceful handling is thus important so that users don't need to special-case these scenarios.In any case, I took the liberty to completely rewrite the forward and backward substitution functions. I used some of the techniques I discovered when working on #150 to rewrite them in terms of the highly optimized
utils::dotfunction, as well as leveraging our row iterators. They no longer contain any unsafe code, except for needing to callget_unchecked(i, i)fromBaseMatrix. See #151.The resulting code is significantly simpler, does not allocate a new vector like the previous implementation and is also significantly faster. Here are the benchmarks before making the changes:
Here are the benchmarks after making the changes: