Fix failed atan2 elimination by splitting SVD into two methods - #583
Open
tomcur wants to merge 1 commit into
Open
Fix failed atan2 elimination by splitting SVD into two methods#583tomcur wants to merge 1 commit into
atan2 elimination by splitting SVD into two methods#583tomcur wants to merge 1 commit into
Conversation
One method calculates the singular values, the other the rotation. This is motivated by the observations in linebender#569 (comment): we're often interested only in the scaling, but the `atan2` call for the rotation is not optimized out by the compiler when it's dead code (probably because the compiler does not know the call is side-effect free). With this change, the call no longer shows up in places where we only use the scales. This is somewhat more verbose, but the methods are not public. The overlap between the two calculations is quite small, and when we do need both (e.g., in `Ellipse::radii_and_rotation`), the inlining of both methods should still allow the compiler to optimize (though I haven't directly verified).
tomcur
commented
May 12, 2026
Comment on lines
-796
to
+795
| let s = mat(1., 1., 1., 1.).svd().0; | ||
| assert_near(s.to_point(), Point::new(2., 0.)); | ||
|
|
||
| let s = mat(1., 1., 1., 1.).svd().0; | ||
| let s = mat(1., 1., 1., 1.).svd_singular_values(); |
Member
Author
There was a problem hiding this comment.
This test was duplicated. Removed one, updated the other.
raphlinus
approved these changes
Jun 5, 2026
raphlinus
left a comment
Contributor
There was a problem hiding this comment.
Thanks, looks good. Glad we didn't make svd a public API.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
One method calculates the singular values, the other the rotation.
This is motivated by the observations in #569 (comment): we're often interested only in the scaling, but the
atan2call for the rotation is not optimized out by the compiler when it's dead code (probably because the compiler does not know the call is side-effect free). With this change, the call no longer shows up in places where we only use the scales.This is somewhat more verbose, but the methods are not public.
The overlap between the two calculations is quite small, and when we do need both (e.g., in
Ellipse::radii_and_rotation), the inlining of both methods should still allow the compiler to optimize (though I haven't directly verified).