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

Test algebra_element and sparse_coefficients #33

Merged
merged 2 commits into from
Jun 20, 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
10 changes: 8 additions & 2 deletions src/monomial.jl
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,14 @@ end

MP.variables(c::SA.AbstractCoefficients) = MP.variables(SA.keys(c))

_lazy_collect(v::AbstractVector) = collect(v)
_lazy_collect(v::Vector) = v

function sparse_coefficients(p::MP.AbstractPolynomial)
return SA.SparseCoefficients(MP.monomials(p), MP.coefficients(p))
return SA.SparseCoefficients(
_lazy_collect(MP.monomials(p)),
_lazy_collect(MP.coefficients(p)),
)
end

function sparse_coefficients(t::MP.AbstractTermLike)
Expand All @@ -178,7 +184,7 @@ function MA.promote_operation(
) where {P<:MP.AbstractPolynomialLike}
M = MP.monomial_type(P)
T = MP.coefficient_type(P)
return SA.SparseCoefficients{M,T,MP.monomial_vector_type(M),Vector{T}}
return SA.SparseCoefficients{M,T,Vector{M},Vector{T}}
end

function algebra_element(p::MP.AbstractPolynomialLike)
Expand Down
4 changes: 4 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@ function api_test(B::Type{<:MB.AbstractMonomialIndexed}, degree)
@test MB.algebra_element(MB.Polynomial{B}(const_mono)) + const_mono == 2
@test iszero(const_mono - MB.algebra_element(MB.Polynomial{B}(const_mono)))
@test iszero(MB.algebra_element(MB.Polynomial{B}(const_mono)) - const_mono)
@test typeof(MB.sparse_coefficients(sum(x))) ==
MA.promote_operation(MB.sparse_coefficients, typeof(sum(x)))
@test typeof(MB.algebra_element(sum(x))) ==
MA.promote_operation(MB.algebra_element, typeof(sum(x)))
end

function univ_orthogonal_test(
Expand Down
Loading