Skip to content

Commit 0cc7d89

Browse files
authored
Fix dispatch for coeff (#39)
* Fix dispatch for coeff * Fixes
1 parent 1027a0b commit 0cc7d89

File tree

3 files changed

+12
-9
lines changed

3 files changed

+12
-9
lines changed

src/monomial.jl

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -423,10 +423,11 @@ function SA.coeffs(
423423
# The defaults initialize to zero and then sums which promotes
424424
# `JuMP.VariableRef` to `JuMP.AffExpr`
425425
return SA.SparseCoefficients(_vec(source.monomials), _vec(cfs))
426-
elseif B2 === Monomial
427-
res = SA.zero_coeffs(_promote_coef(valtype(cfs), B1), target)
428-
return SA.coeffs!(res, cfs, source, target)
429426
else
430-
error("Convertion from `$source` to `$target` not implemented yet")
427+
res = SA.zero_coeffs(
428+
_promote_coef(_promote_coef(valtype(cfs), B1), B2),
429+
target,
430+
)
431+
return SA.coeffs!(res, cfs, source, target)
431432
end
432433
end

test/hermite.jl

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,4 @@ end
4848
M = typeof(x^2)
4949
mono = MB.FullBasis{MB.Monomial,M}()
5050
basis = MB.FullBasis{MB.PhysicistsHermite,M}()
51-
err = ErrorException(
52-
"Convertion from `$mono` to `$basis` not implemented yet",
53-
)
54-
@test_throws err SA.coeffs(MB.algebra_element(x + 1), basis)
5551
end

test/scaled.jl

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,13 @@ end
2020
basis = MB.SubBasis{MB.ScaledMonomial}([x^2, x * y, y^2])
2121
@test polynomial_type(basis, Int) == polynomial_type(x, Float64)
2222
@test polynomial(i -> i^2, basis) == 9x^2 + 4 * 2 * x * y + y^2
23-
@test coefficients(x^2 + 4x * y + 9y^2, basis) == [9, 4 / 2, 1]
23+
p = x^2 + 4x * y + 9y^2
24+
@test coefficients(p, basis) == [9, 4 / 2, 1]
25+
a = MB.algebra_element(p)
26+
@test SA.coeffs(a, basis) == [9, 4 / 2, 1]
27+
full = MB.FullBasis{MB.ScaledMonomial,monomial_type(p)}()
28+
@test SA.coeffs(a, full) ==
29+
SA.SparseCoefficients([y^2, x * y, x^2], [9, 4 / 2, 1])
2430
@test polynomial(basis[1]) == y^2
2531
@test polynomial(basis[2]) == 2 * x * y
2632
@test polynomial(basis[3]) == x^2

0 commit comments

Comments
 (0)