Skip to content

Commit

Permalink
Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
blegat committed Jun 17, 2024
1 parent fee4ab8 commit 97e0aea
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 19 deletions.
2 changes: 1 addition & 1 deletion src/MultivariateBases.jl
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export AbstractMultipleOrthogonal,
ProbabilistsHermite, PhysicistsHermite, Laguerre
export AbstractGegenbauer,
Legendre, Chebyshev, ChebyshevFirstKind, ChebyshevSecondKind
export generators,
export algebra_element, sparse_coefficients,
univariate_orthogonal_basis,
reccurence_first_coef,
reccurence_second_coef,
Expand Down
9 changes: 1 addition & 8 deletions src/monomial.jl
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ function sparse_coefficients(p::MP.AbstractPolynomial)
return SA.SparseCoefficients(MP.monomials(p), MP.coefficients(p))
end

function sparse_coefficients(t::MP.AbstractTerm)
function sparse_coefficients(t::MP.AbstractTermLike)
return SA.SparseCoefficients((MP.monomial(t),), (MP.coefficient(t),))
end

Expand All @@ -186,13 +186,6 @@ function algebra_element(p::MP.AbstractPolynomialLike)
)
end

function algebra_element(p::Polynomial{B,M}) where {B,M}
return algebra_element(
sparse_coefficients(MP.term(1, p.monomial)),
FullBasis{B,M}(),
)
end

function algebra_element(f::Function, basis::SubBasis)
return algebra_element(map(f, eachindex(basis)), basis)
end
Expand Down
7 changes: 4 additions & 3 deletions src/polynomial.jl
Original file line number Diff line number Diff line change
Expand Up @@ -72,16 +72,17 @@ MP.variables(p::Polynomial) = MP.variables(p.monomial)
MP.nvariables(p::Polynomial) = MP.nvariables(p.monomial)

MP.monomial_type(::Type{<:SA.SparseCoefficients{K}}) where {K} = K
MP.polynomial(p::Polynomial) = MP.polynomial(algebra_element(p))

function algebra_element(p, basis::SA.AbstractBasis)
return SA.AlgebraElement(p, algebra(basis))
end

function _algebra_element(p, ::Type{B}) where {B<:AbstractMonomialIndexed}
return algebra_element(p, FullBasis{B,MP.monomial_type(typeof(p))}())
return algebra_element(sparse_coefficients(p), FullBasis{B,MP.monomial_type(typeof(p))}())
end

function _algebra_element(p::Polynomial{B,M}) where {B,M}
function algebra_element(p::Polynomial{B,M}) where {B,M}
return _algebra_element(p.monomial, B)
end

Expand Down Expand Up @@ -151,7 +152,7 @@ function MA.operate_to!(
end

function MP.polynomial(a::SA.AbstractCoefficients)
return MP.polynomial(SA.values(a), SA.keys(a))
return MP.polynomial(collect(SA.values(a)), collect(SA.keys(a)))
end

function MP.polynomial(a::SA.AlgebraElement)
Expand Down
4 changes: 2 additions & 2 deletions test/monomial.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ using DynamicPolynomials
@polyvar x
a = MB.Polynomial{MB.Monomial}(x)
b = a * a
@test b.coeffs == x^2
@test typeof(b.coeffs) == typeof(x^2)
@test b.coeffs == sparse_coefficients(x^2)
@test typeof(b.coeffs) == typeof(sparse_coefficients(x^2))
@test MB.Polynomial{MB.Monomial}(x^2) == MB.Polynomial{MB.Monomial}(x^2)
@test MB.Polynomial{MB.Monomial}(x^3) != MB.Polynomial{MB.Monomial}(x^2)
end
Expand Down
6 changes: 1 addition & 5 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,6 @@ function api_test(B::Type{<:MB.AbstractMonomialIndexed}, degree)
@test length(empty_basis(typeof(basis))) == 0
@test polynomial_type(basis, Float64) == polynomial_type(x[1], Float64)
@test polynomial(i -> 0.0, basis) isa polynomial_type(basis, Float64)
@test polynomial(zeros(n, n), basis, Float64) isa
polynomial_type(basis, Float64)
@test polynomial(ones(n, n), basis, Float64) isa
polynomial_type(basis, Float64)
end
end

Expand Down Expand Up @@ -99,7 +95,7 @@ end
function coefficient_test(basis::SubBasis, p, coefs; kwargs...)
cc = coefficients(p, basis)
@test isapprox(coefs, cc; kwargs...)
@test isapprox(p, polynomial(cc, basis); kwargs...)
@test isapprox(p, algebra_element(cc, basis); kwargs...)
end

function coefficient_test(basis::SubBasis, coefs::AbstractVector; kwargs...)
Expand Down

0 comments on commit 97e0aea

Please sign in to comment.