Skip to content
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

Replace Unitful aware givensAlgorithm with a generic version. #54078

Closed
wants to merge 2 commits into from

Conversation

andreasnoack
Copy link
Member

@andreasnoack andreasnoack commented Apr 14, 2024

The implementation is based on

Janovská, D., & Opfer, G. (2003) "Givens’ Transformation Applied to Quaternion Valued Vectors."

Fixes #41753

@andreasnoack andreasnoack added domain:linear algebra Linear algebra kind:feature Indicates new feature / enhancement requests labels Apr 14, 2024
@oscardssmith
Copy link
Member

how is the performance of this? it doesn't look like it would be fast.

@andreasnoack
Copy link
Member Author

Since it's a generic fallback, performance wasn't really the focus, but I'm curious what specifically makes you think that it's slow.

@oscardssmith
Copy link
Member

the main thing that seems slow is the division to get sign. division is pretty slow.

The implementation is based on

Janovská, D., & Opfer, G. (2003) "Givens’ Transformation Applied to
Quaternion Valued Vectors."
nrm = hypot(f, g)
c = abs(f) / nrm
s, u = if iszero(f)
-one(first(promote(f, g))), -g
Copy link
Contributor

@devmotion devmotion Apr 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just noticed that this is inconsistent with the existing definition for Float64:

julia> using LinearAlgebra

julia> LinearAlgebra.givensAlgorithm(0.0, 2.0)
(0.0, 1.0, 2.0)

It seems to be consistent with the existing definitions we would need something like

Suggested change
-one(first(promote(f, g))), -g
one(first(promote(f, g))), g

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure it's worth trying to match the values of c and s from the two versions translated from LAPACK. Then we'd essentially have to reimplement the version for complex numbers and I'm not sure if it necessarily works for quaternions. In any case, which of the allowed values of c and s doesn't really matter. It's always the result of applying the rotation that matters and it isn't affected by this choice (except for rounding).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thought a bit more about this and concluded that you are right here. The fallback would have to make the same sign decisions as the specialized version so the approach of this PR can't work. We should probably try to make a version of the complex version that isn't restricted to Complex32/64.

@andreasnoack andreasnoack deleted the an/genericgivens branch May 1, 2024 19:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
domain:linear algebra Linear algebra kind:feature Indicates new feature / enhancement requests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

LinearAlgebra.givensAlgorithm not compatible with ForwardDiff
5 participants