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

Fix dispatch for coeff #39

Merged
merged 2 commits into from
Jul 3, 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
9 changes: 5 additions & 4 deletions src/monomial.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 0 additions & 4 deletions test/hermite.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
8 changes: 7 additions & 1 deletion test/scaled.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading