Skip to content

Commit

Permalink
Add block_diagonal function (#80)
Browse files Browse the repository at this point in the history
* Add block_diagonal function

* Fix

* Fix format
  • Loading branch information
blegat committed May 28, 2024
1 parent 4e2094f commit 71944e4
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
7 changes: 5 additions & 2 deletions src/dependence.jl
Original file line number Diff line number Diff line change
Expand Up @@ -247,8 +247,11 @@ function BasisDependence{StaircaseDependence}(
end
end
vars = MP.variables(basis)
full_basis =
MB.maxdegree_basis(MB.Monomial, vars, MP.maxdegree(basis.monomials))
full_basis = MB.maxdegree_basis(
MB.FullBasis{MB.Monomial,M}(),
vars,
MP.maxdegree(basis.monomials),
)
d = StaircaseDependence[]
# This sieve of [LLR08, Algorithm 1] is a performance improvement but not only.
# It also ensures that the standard monomials have the "staircase structure".
Expand Down
4 changes: 4 additions & 0 deletions src/moment_matrix.jl
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,10 @@ struct BlockDiagonalMomentMatrix{T,B<:SA.ExplicitBasis,MT} <:
blocks::Vector{MomentMatrix{T,B,MT}}
end

function block_diagonal(blocks::Vector{<:MomentMatrix})
return BlockDiagonalMomentMatrix(blocks)
end

function show_basis_indexed_blocks(io::IO, blocks)
print(io, " with $(length(blocks)) blocks:")
nd = ndigits(length(blocks))
Expand Down
2 changes: 1 addition & 1 deletion test/moment_matrix.jl
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ And entries in a 2×2 SymMatrix{$Int}:
@test nvariables(ν) == 2
end
@test_throws ArgumentError moment_matrix(moment_vector([1], [x]), [y])
block_ν = BlockDiagonalMomentMatrix([ν1, ν2])
block_ν = block_diagonal([ν1, ν2])
@test block_ν isa BlockDiagonalMomentMatrix{Int,typeof(ν1.basis)}
@test sprint(show, block_ν) == """
BlockDiagonalMomentMatrix with 2 blocks:
Expand Down

0 comments on commit 71944e4

Please sign in to comment.