Skip to content
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

Add block_diagonal function #80

Merged
merged 3 commits into from
May 28, 2024
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
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
Loading