Skip to content

Commit

Permalink
Fixes for BigFloat (#89)
Browse files Browse the repository at this point in the history
  • Loading branch information
blegat committed Aug 21, 2024
1 parent 54ef263 commit b1240ff
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 20 deletions.
4 changes: 4 additions & 0 deletions src/extract.jl
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ function solve_weight(
centers,
::MomentMatrixWeightSolver,
) where {T}
if isempty(centers)
# Failing for `BigFloat`
return T[]
end
vars = MP.variables(ν)
A = Matrix{T}(undef, length.Q.Q), length(centers))
vbasis = vectorized_basis(ν)
Expand Down
1 change: 1 addition & 0 deletions test/Project.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
[deps]
DynamicPolynomials = "7c1d4256-1411-5781-91ec-d7bc3513ac07"
GenericLinearAlgebra = "14197337-ba66-59df-a3e3-ca00e7dcff7a"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
MultivariateBases = "be282fd4-ad43-11e9-1d11-8bd9d7e43378"
MultivariateMoments = "f4abf1af-0426-5881-a0da-e2f168889b5e"
Expand Down
45 changes: 25 additions & 20 deletions test/extract.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ using MultivariatePolynomials
import MultivariateBases as MB
using SemialgebraicSets
using MultivariateMoments
import GenericLinearAlgebra # Needed for `svd` to work on `Matrix{BigFloat}`

struct DummySolver <: SemialgebraicSets.AbstractAlgebraicSolver end
SemialgebraicSets.promote_for(::Type{T}, ::Type{DummySolver}) where {T} = T
Expand Down Expand Up @@ -34,18 +35,18 @@ function _atoms(atoms, rank_check, solver)
atoms = atomic_measure(ν, rank_check, solver)
@test atoms !== nothing
if !isnothing(atoms)
@test atoms η
@test atoms η rtol = 1e-8
end
end

function atoms_1(rank_check, solver)
atoms = [[1, 2]]
function atoms_1(T, rank_check, solver)
atoms = [T[1, 2]]
_atoms(atoms, rank_check, solver)
return
end

function atoms_2(rank_check, solver)
atoms = [[1, 1], [1, -1]]
function atoms_2(T, rank_check, solver)
atoms = [T[1, 1], T[1, -1]]
_atoms(atoms, rank_check, solver)
return
end
Expand Down Expand Up @@ -351,10 +352,10 @@ function jcg14_6_1(rank_check, ok::Bool = true)
end
end

function large_norm(rank_check)
function large_norm(T, rank_check)
# If the norm of `M` is given to `rref!` instead of `√||M||`, `atomic_measure` will error.
Mod.@polyvar x[1:2]
Q = [
Q = T[
586.8034549325414 -800.152792847183
-800.152792847183 2749.376669556701
]
Expand Down Expand Up @@ -390,19 +391,21 @@ _short(x) = _short(string(x))

function test_extract()
default_solver = SemialgebraicSets.default_algebraic_solver([1.0x - 1.0x])
@testset "$(_short(solver))" for solver in [
FlatExtension(),
FlatExtension(NewtonTypeDiagonalization()),
Echelon(),
ImageSpaceSolver(ShiftCholeskyLDLT(1e-15), Echelon()),
ShiftNullspace(),
ImageSpaceSolver(ShiftCholeskyLDLT(1e-15), ShiftNullspace()),
]
@testset "$T $(_short(solver))" for T in [Float64, BigFloat],
solver in [
FlatExtension(),
FlatExtension(NewtonTypeDiagonalization()),
Echelon(),
ImageSpaceSolver(ShiftCholeskyLDLT(1e-15), Echelon()),
ShiftNullspace(),
ImageSpaceSolver(ShiftCholeskyLDLT(1e-15), ShiftNullspace()),
]

@testset "Atom 1" begin
atoms_1(1e-10, solver)
atoms_1(T, 1e-10, solver)
end
@testset "Atom 2" begin
atoms_2(1e-10, solver)
atoms_2(T, 1e-10, solver)
end
end
@testset "hl05_2_3 $(_short(lrc))" for lrc in
Expand Down Expand Up @@ -465,11 +468,13 @@ function test_extract()
lpj20_3_9(FixedRank(7), 0)
jcg14_6_1(6e-3)
jcg14_6_1(8e-4, false)
large_norm(1e-2)
@testset "$T" for T in [Float64, BigFloat]
large_norm(T, 1e-2)
end
@testset "No comm fix $(_short(solver)) $T" for solver in
[ShiftNullspace()],
T in [Float64]
#, BigFloat]
T in [Float64, BigFloat]

no_com(solver, T)
end
return
Expand Down

0 comments on commit b1240ff

Please sign in to comment.