Skip to content

Commit eb1644b

Browse files
authored
Fixes for BigFloat (#89)
1 parent 0fc52a7 commit eb1644b

File tree

3 files changed

+30
-20
lines changed

3 files changed

+30
-20
lines changed

src/extract.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ function solve_weight(
3030
centers,
3131
::MomentMatrixWeightSolver,
3232
) where {T}
33+
if isempty(centers)
34+
# Failing for `BigFloat`
35+
return T[]
36+
end
3337
vars = MP.variables(ν)
3438
A = Matrix{T}(undef, length.Q.Q), length(centers))
3539
vbasis = vectorized_basis(ν)

test/Project.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
[deps]
22
DynamicPolynomials = "7c1d4256-1411-5781-91ec-d7bc3513ac07"
3+
GenericLinearAlgebra = "14197337-ba66-59df-a3e3-ca00e7dcff7a"
34
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
45
MultivariateBases = "be282fd4-ad43-11e9-1d11-8bd9d7e43378"
56
MultivariateMoments = "f4abf1af-0426-5881-a0da-e2f168889b5e"

test/extract.jl

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ using MultivariatePolynomials
33
import MultivariateBases as MB
44
using SemialgebraicSets
55
using MultivariateMoments
6+
import GenericLinearAlgebra # Needed for `svd` to work on `Matrix{BigFloat}`
67

78
struct DummySolver <: SemialgebraicSets.AbstractAlgebraicSolver end
89
SemialgebraicSets.promote_for(::Type{T}, ::Type{DummySolver}) where {T} = T
@@ -34,18 +35,18 @@ function _atoms(atoms, rank_check, solver)
3435
atoms = atomic_measure(ν, rank_check, solver)
3536
@test atoms !== nothing
3637
if !isnothing(atoms)
37-
@test atoms η
38+
@test atoms η rtol = 1e-8
3839
end
3940
end
4041

41-
function atoms_1(rank_check, solver)
42-
atoms = [[1, 2]]
42+
function atoms_1(T, rank_check, solver)
43+
atoms = [T[1, 2]]
4344
_atoms(atoms, rank_check, solver)
4445
return
4546
end
4647

47-
function atoms_2(rank_check, solver)
48-
atoms = [[1, 1], [1, -1]]
48+
function atoms_2(T, rank_check, solver)
49+
atoms = [T[1, 1], T[1, -1]]
4950
_atoms(atoms, rank_check, solver)
5051
return
5152
end
@@ -351,10 +352,10 @@ function jcg14_6_1(rank_check, ok::Bool = true)
351352
end
352353
end
353354

354-
function large_norm(rank_check)
355+
function large_norm(T, rank_check)
355356
# If the norm of `M` is given to `rref!` instead of `√||M||`, `atomic_measure` will error.
356357
Mod.@polyvar x[1:2]
357-
Q = [
358+
Q = T[
358359
586.8034549325414 -800.152792847183
359360
-800.152792847183 2749.376669556701
360361
]
@@ -390,19 +391,21 @@ _short(x) = _short(string(x))
390391

391392
function test_extract()
392393
default_solver = SemialgebraicSets.default_algebraic_solver([1.0x - 1.0x])
393-
@testset "$(_short(solver))" for solver in [
394-
FlatExtension(),
395-
FlatExtension(NewtonTypeDiagonalization()),
396-
Echelon(),
397-
ImageSpaceSolver(ShiftCholeskyLDLT(1e-15), Echelon()),
398-
ShiftNullspace(),
399-
ImageSpaceSolver(ShiftCholeskyLDLT(1e-15), ShiftNullspace()),
400-
]
394+
@testset "$T $(_short(solver))" for T in [Float64, BigFloat],
395+
solver in [
396+
FlatExtension(),
397+
FlatExtension(NewtonTypeDiagonalization()),
398+
Echelon(),
399+
ImageSpaceSolver(ShiftCholeskyLDLT(1e-15), Echelon()),
400+
ShiftNullspace(),
401+
ImageSpaceSolver(ShiftCholeskyLDLT(1e-15), ShiftNullspace()),
402+
]
403+
401404
@testset "Atom 1" begin
402-
atoms_1(1e-10, solver)
405+
atoms_1(T, 1e-10, solver)
403406
end
404407
@testset "Atom 2" begin
405-
atoms_2(1e-10, solver)
408+
atoms_2(T, 1e-10, solver)
406409
end
407410
end
408411
@testset "hl05_2_3 $(_short(lrc))" for lrc in
@@ -465,11 +468,13 @@ function test_extract()
465468
lpj20_3_9(FixedRank(7), 0)
466469
jcg14_6_1(6e-3)
467470
jcg14_6_1(8e-4, false)
468-
large_norm(1e-2)
471+
@testset "$T" for T in [Float64, BigFloat]
472+
large_norm(T, 1e-2)
473+
end
469474
@testset "No comm fix $(_short(solver)) $T" for solver in
470475
[ShiftNullspace()],
471-
T in [Float64]
472-
#, BigFloat]
476+
T in [Float64, BigFloat]
477+
473478
no_com(solver, T)
474479
end
475480
return

0 commit comments

Comments
 (0)