Skip to content

use Symmetric() to get rid of complex eigen() results #68

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

Merged
merged 2 commits into from
Nov 18, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/bounds/ellipsoid.jl
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ volume(ell::Ellipsoid) = ell.volume
# Returns the principal axes
axes(ell::Ellipsoid) = ell.axes

function decompose(A::AbstractMatrix)
decompose(A::AbstractMatrix) = decompose(Symmetric(A)) # ensure that eigen() always returns real values

function decompose(A::Symmetric)
E = eigen(A)
axlens = @. 1 / sqrt(E.values)
axes = E.vectors * Diagonal(axlens)
Expand Down
7 changes: 7 additions & 0 deletions test/bounds/bounds.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,13 @@ const BOUNDST = [
Bounds.MultiEllipsoid
]

@testset "pathological cases" begin
A_almost_symmetric = [2.6081830533175096e8 -5.4107420917559285e6 -1.9314298704966028e9 -2.360066561768968e9; -5.410742091755895e6 379882.440454782 6.715028007245775e7 2.0195280814040575e7; -1.931429870496611e9 6.715028007245693e7 9.811342987452753e10 -4.6579127705367036e7; -2.3600665617689605e9 2.0195280814042665e7 -4.6579127705418006e7 9.80946804720486e10]
# shouldn't fail:
ell = Bounds.Ellipsoid(zeros(4), A_almost_symmetric)
Bounds.volume(ell)
end

@testset "interface - $B, $T, D=$D" for B in BOUNDST, T in [Float32, Float64], D in 1:20
# creation, inspection
bound = B(T, D)
Expand Down
3 changes: 2 additions & 1 deletion test/bounds/ellipsoids.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ const NMAX = 20
@test volume(ell) ≈ volume_prefactor(N) * scale^N
axs, axlens = decompose(ell)
@test axlens ≈ fill(scale, N)
@test axs ≈ Bounds.axes(ell) ≈ scale * Matrix(I, N, N)
@test axs ≈ Bounds.axes(ell)
@test norm.(eachcol(axs)) == fill(scale, N)
end

@testset "Scaling" begin
Expand Down