-
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 4 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,31 @@ 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, #694 | ||
zero = 0.0 | ||
smallest_non_zero = nextfloat(zero) | ||
smallest_normal = floatmin(zero) | ||
largest_subnormal = prevfloat(smallest_normal) | ||
epsilon = eps(1.0) | ||
one_p_epsilon = 1.0 + epsilon | ||
degenerate = (zero, -1, 1, smallest_non_zero, smallest_normal, largest_subnormal, epsilon, one_p_epsilon, -one_p_epsilon) | ||
@testset "2×2 degenerate cases" for (i, j, k) in zip(degenerate,degenerate,degenerate), uplo in (:U, :L) | ||
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 don't think this Perhaps you meant to use 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. You're totally right, that's what I meant |
||
A = SMatrix{2,2,Float64}((i, k, k, 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.
Quibble: Better written
nextfloat(1.0)
— it's the same in this case, but if you'd written1.0 - epsilon
that's not equal toprevfloat(1.0)
which is a bit of a gotcha given that the boundary in floating point discretization density lies on the powers of two.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.
👍