diff --git a/src/monomial.jl b/src/monomial.jl index 8c99ad0..13ae659 100644 --- a/src/monomial.jl +++ b/src/monomial.jl @@ -423,10 +423,11 @@ function SA.coeffs( # The defaults initialize to zero and then sums which promotes # `JuMP.VariableRef` to `JuMP.AffExpr` return SA.SparseCoefficients(_vec(source.monomials), _vec(cfs)) - elseif B2 === Monomial - res = SA.zero_coeffs(_promote_coef(valtype(cfs), B1), target) - return SA.coeffs!(res, cfs, source, target) else - error("Convertion from `$source` to `$target` not implemented yet") + res = SA.zero_coeffs( + _promote_coef(_promote_coef(valtype(cfs), B1), B2), + target, + ) + return SA.coeffs!(res, cfs, source, target) end end diff --git a/test/hermite.jl b/test/hermite.jl index c72c97e..cd28b62 100644 --- a/test/hermite.jl +++ b/test/hermite.jl @@ -48,8 +48,4 @@ end M = typeof(x^2) mono = MB.FullBasis{MB.Monomial,M}() basis = MB.FullBasis{MB.PhysicistsHermite,M}() - err = ErrorException( - "Convertion from `$mono` to `$basis` not implemented yet", - ) - @test_throws err SA.coeffs(MB.algebra_element(x + 1), basis) end diff --git a/test/scaled.jl b/test/scaled.jl index 77d4ae5..4975b21 100644 --- a/test/scaled.jl +++ b/test/scaled.jl @@ -20,7 +20,13 @@ end basis = MB.SubBasis{MB.ScaledMonomial}([x^2, x * y, y^2]) @test polynomial_type(basis, Int) == polynomial_type(x, Float64) @test polynomial(i -> i^2, basis) == 9x^2 + 4 * √2 * x * y + y^2 - @test coefficients(x^2 + 4x * y + 9y^2, basis) == [9, 4 / √2, 1] + p = x^2 + 4x * y + 9y^2 + @test coefficients(p, basis) == [9, 4 / √2, 1] + a = MB.algebra_element(p) + @test SA.coeffs(a, basis) == [9, 4 / √2, 1] + full = MB.FullBasis{MB.ScaledMonomial,monomial_type(p)}() + @test SA.coeffs(a, full) == + SA.SparseCoefficients([y^2, x * y, x^2], [9, 4 / √2, 1]) @test polynomial(basis[1]) == y^2 @test polynomial(basis[2]) == √2 * x * y @test polynomial(basis[3]) == x^2