-
Notifications
You must be signed in to change notification settings - Fork 153
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
Improve 2x2 eigen #694
base: master
Are you sure you want to change the base?
Improve 2x2 eigen #694
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -75,24 +75,36 @@ using StaticArrays, Test, LinearAlgebra | |
@test vals::SVector ≈ sort(m_d) | ||
@test eigvals(m_c) ≈ sort(m_d) | ||
@test eigvals(Hermitian(m_c)) ≈ sort(m_d) | ||
end | ||
|
||
# issue #523 | ||
for (i, j) in ((1, 2), (2, 1)), uplo in (:U, :L) | ||
A = SMatrix{2,2,Float64}((i, 0, 0, j)) | ||
E = eigen(Symmetric(A, uplo)) | ||
@test eigvecs(E) * SDiagonal(eigvals(E)) * eigvecs(E)' ≈ A | ||
end | ||
|
||
m1_a = randn(2,2) | ||
m1_a = m1_a*m1_a' | ||
m1 = SMatrix{2,2}(m1_a) | ||
m2_a = randn(2,2) | ||
m2_a = m2_a*m2_a' | ||
m2 = SMatrix{2,2}(m2_a) | ||
@test (@inferred_maybe_allow SVector{2,ComplexF64} eigvals(m1, m2)) ≈ eigvals(m1_a, m2_a) | ||
@test (@inferred_maybe_allow SVector{2,ComplexF64} eigvals(Symmetric(m1), Symmetric(m2))) ≈ eigvals(Symmetric(m1_a), Symmetric(m2_a)) | ||
# issue #523 | ||
@testset "2×2 degenerate cases" for (i, j) in ((1 , 1), (1, 2), (2, 1)), uplo in (:U, :L) | ||
fmin = floatmin(Float64) | ||
pfmin = prevfloat(fmin) | ||
nfmin = nextfloat(fmin) | ||
A = SMatrix{2,2,Float64}((i, 0, 0, j)) | ||
E = eigen(Symmetric(A, uplo)) | ||
@test eigvecs(E) * SDiagonal(eigvals(E)) * eigvecs(E)' ≈ A | ||
A = SMatrix{2,2,Float64}((i, pfmin, pfmin, j)) | ||
E = eigen(Symmetric(A, uplo)) | ||
@test eigvecs(E) * SDiagonal(eigvals(E)) * eigvecs(E)' ≈ A | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Cool, so can you add some comment about exactly which cases we are straddling here by examining the boundary between There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd love to merge this, but I'm unsure whether these tests are testing the right thing. Do you have some thoughts on the above query? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I looked into it again. You were right, they were testing the wrong thing. When I tested the right thing it wasn't working properly. I put some time in to make it work and simplify things, mostly by using the hypot function which already has a lot of work put into making it accurate. |
||
A = SMatrix{2,2,Float64}((i, fmin, fmin, j)) | ||
E = eigen(Symmetric(A, uplo)) | ||
@test eigvecs(E) * SDiagonal(eigvals(E)) * eigvecs(E)' ≈ A | ||
A = SMatrix{2,2,Float64}((i, nfmin, nfmin, j)) | ||
E = eigen(Symmetric(A, uplo)) | ||
@test eigvecs(E) * SDiagonal(eigvals(E)) * eigvecs(E)' ≈ A | ||
end | ||
|
||
m1_a = randn(2,2) | ||
m1_a = m1_a*m1_a' | ||
m1 = SMatrix{2,2}(m1_a) | ||
m2_a = randn(2,2) | ||
m2_a = m2_a*m2_a' | ||
m2 = SMatrix{2,2}(m2_a) | ||
@test (@inferred_maybe_allow SVector{2,ComplexF64} eigvals(m1, m2)) ≈ eigvals(m1_a, m2_a) | ||
@test (@inferred_maybe_allow SVector{2,ComplexF64} eigvals(Symmetric(m1), Symmetric(m2))) ≈ eigvals(Symmetric(m1_a), Symmetric(m2_a)) | ||
|
||
@test_throws DimensionMismatch eigvals(SA[1 2 3; 4 5 6], SA[1 2 3; 4 5 5]) | ||
@test_throws DimensionMismatch eigvals(SA[1 2; 4 5], SA[1 2 3; 4 5 5; 3 4 5]) | ||
|
||
|
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.