Skip to content

Commit

Permalink
Merge pull request #68 from aplavin/patch-3
Browse files Browse the repository at this point in the history
  • Loading branch information
mileslucas authored Nov 18, 2021
2 parents 29a7cbe + fde53e4 commit b6e4381
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
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

0 comments on commit b6e4381

Please sign in to comment.