Skip to content

Commit

Permalink
Implement explicit_basis_covering for same basis (#48)
Browse files Browse the repository at this point in the history
* Implement explicit_basis_covering for same basis

* Fix format
  • Loading branch information
blegat authored Jul 10, 2024
1 parent 67ae0a6 commit e4737e2
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/monomial.jl
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ function Base.getindex(basis::SubBasis{B,M}, value::Polynomial{B,M}) where {B,M}
return mono
end

function explicit_basis_covering(::FullBasis{B}, target::SubBasis{B}) where {B}
return SubBasis{B}(target.monomials)
end

const MonomialIndexedBasis{B,M} = Union{SubBasis{B,M},FullBasis{B,M}}

MP.monomial_type(::Type{<:SubBasis{B,M}}) where {B,M} = M
Expand Down Expand Up @@ -295,6 +299,14 @@ function explicit_basis_covering(
return SubBasis{B}(target.monomials)
end

# To break ambiguity
function explicit_basis_covering(
::FullBasis{B},
target::SubBasis{B},
) where {B<:AbstractMonomial}
return SubBasis{B}(target.monomials)
end

function Base.adjoint(p::Polynomial{B}) where {B<:AbstractMonomialIndexed}
return Polynomial{B}(adjoint(p.monomial))
end
Expand Down
4 changes: 4 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ function api_test(B::Type{<:MB.AbstractMonomialIndexed}, degree)
full_basis,
MB.SubBasis{ScaledMonomial}(monomials(x, 0:degree)),
),
explicit_basis_covering(
full_basis,
MB.SubBasis{B}(monomials(x, 0:degree)),
),
]
_test_basis(basis)
@test basis isa MB.explicit_basis_type(typeof(full_basis))
Expand Down

0 comments on commit e4737e2

Please sign in to comment.