Skip to content

Commit

Permalink
fix format
Browse files Browse the repository at this point in the history
  • Loading branch information
blegat committed Jun 17, 2024
1 parent 58aa653 commit 7a3380c
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 32 deletions.
10 changes: 4 additions & 6 deletions src/chebyshev.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ _promote_div(::Type{T}) where {T<:Number} = MA.promote_operation(/, T, Int)
# which does not support division with `Int`
_promote_div(::Type{F}) where {F} = F

_promote_coef(::Type{T}, ::Type{<:AbstractChebyshev}) where {T} = _promote_div(T)
function _promote_coef(::Type{T}, ::Type{<:AbstractChebyshev}) where {T}
return _promote_div(T)
end

reccurence_first_coef(::Type{<:AbstractChebyshev}, degree) = 2
reccurence_third_coef(::Type{<:AbstractChebyshev}, degree) = -1
Expand Down Expand Up @@ -106,11 +108,7 @@ function SA.coeffs(
)
end

function SA.coeffs(
cfs,
::FullBasis{Monomial},
target::FullBasis{Chebyshev},
)
function SA.coeffs(cfs, ::FullBasis{Monomial}, target::FullBasis{Chebyshev})
return SA.coeffs(
SA.values(cfs),
SubBasis{Monomial}(collect(SA.keys(cfs))),
Expand Down
20 changes: 10 additions & 10 deletions src/monomial.jl
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,9 @@ one get ths [`ScaledMonomial`](@ref).
"""
struct Monomial <: AbstractMonomial end

(::Mul{Monomial})(a::MP.AbstractMonomial, b::MP.AbstractMonomial) = sparse_coefficients(a * b)
function (::Mul{Monomial})(a::MP.AbstractMonomial, b::MP.AbstractMonomial)
return sparse_coefficients(a * b)
end

SA.coeffs(p::Polynomial{Monomial}, ::FullBasis{Monomial}) = p.monomial

Expand All @@ -278,10 +280,7 @@ function MP.polynomial_type(
return MP.polynomial_type(FullBasis{B,M}, T)
end

function MP.polynomial_type(
::Type{Polynomial{B,M}},
::Type{T},
) where {B,M,T}
function MP.polynomial_type(::Type{Polynomial{B,M}}, ::Type{T}) where {B,M,T}
return MP.polynomial_type(FullBasis{B,M}, T)
end

Expand Down Expand Up @@ -366,15 +365,16 @@ end

_promote_coef(::Type{T}, ::Type{Monomial}) where {T} = T

function MP.polynomial_type(
::Type{FullBasis{B,M}},
::Type{T},
) where {T,B,M}
function MP.polynomial_type(::Type{FullBasis{B,M}}, ::Type{T}) where {T,B,M}
return MP.polynomial_type(M, _promote_coef(T, B))
end

# Adapted from SA to incorporate `_promote_coef`
function SA.coeffs(cfs, source::MonomialIndexedBasis{B}, target::MonomialIndexedBasis{Monomial}) where {B}
function SA.coeffs(
cfs,
source::MonomialIndexedBasis{B},
target::MonomialIndexedBasis{Monomial},
) where {B}
source === target && return cfs
source == target && return cfs
res = SA.zero_coeffs(_promote_coef(valtype(cfs), B), target)
Expand Down
3 changes: 2 additions & 1 deletion src/orthogonal.jl
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,8 @@ function MP.coefficients(
return map(basis) do el
q = SA.coeffs(el, FullBasis{Monomial,M}())
poly_q = MP.polynomial(q)
return LinearAlgebra.dot(poly_p, poly_q, B) / LinearAlgebra.dot(poly_q, poly_q, B)
return LinearAlgebra.dot(poly_p, poly_q, B) /
LinearAlgebra.dot(poly_q, poly_q, B)
end
end

Expand Down
2 changes: 1 addition & 1 deletion src/polynomial.jl
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ end
function Base.:*(a::Polynomial{B}, b::Polynomial{B}) where {B}
return algebra_element(
Mul{B}()(a.monomial, b.monomial),
FullBasis{B,promote_type(typeof(a.monomial),typeof(b.monomial))}(),
FullBasis{B,promote_type(typeof(a.monomial), typeof(b.monomial))}(),
)
end

Expand Down
12 changes: 2 additions & 10 deletions src/quotient.jl
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,11 @@ function MP.coefficients(p, basis::QuotientBasis)
return MP.coefficients(rem(p, basis.divisor), basis.basis)
end

function SA.coeffs(
p,
::FullBasis{Monomial},
basis::QuotientBasis,
)
function SA.coeffs(p, ::FullBasis{Monomial}, basis::QuotientBasis)
return MP.coefficients(MP.polynomial(p), basis)
end

function SA.coeffs(
coeffs,
sub::SubBasis{Monomial},
basis::QuotientBasis,
)
function SA.coeffs(coeffs, sub::SubBasis{Monomial}, basis::QuotientBasis)
return SA.coeffs(MP.polynomial(coeffs, sub.monomials), parent(sub), basis)
end

Expand Down
3 changes: 2 additions & 1 deletion test/chebyshev.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ using DynamicPolynomials
b = a * a
@test b.coeffs == MB.sparse_coefficients(1 // 2 + 1 // 2 * x^2)
c = b * b
@test c.coeffs == MB.sparse_coefficients(3 // 8 + 1 // 2 * x^2 + 1 // 8 * x^4)
@test c.coeffs ==
MB.sparse_coefficients(3 // 8 + 1 // 2 * x^2 + 1 // 8 * x^4)
@test a * MB.Polynomial{MB.Chebyshev}(constant_monomial(typeof(x))) ==
a * MB.Polynomial{MB.Chebyshev}(x^0)
end
Expand Down
15 changes: 12 additions & 3 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,14 @@ function api_test(B::Type{<:MB.AbstractMonomialIndexed}, degree)
full_basis = FullBasis{B,M}()
for basis in [
maxdegree_basis(full_basis, x, degree),
explicit_basis_covering(full_basis, MB.SubBasis{MB.Monomial}(monomials(x, 0:degree))),
explicit_basis_covering(full_basis, MB.SubBasis{ScaledMonomial}(monomials(x, 0:degree))),
explicit_basis_covering(
full_basis,
MB.SubBasis{MB.Monomial}(monomials(x, 0:degree)),
),
explicit_basis_covering(
full_basis,
MB.SubBasis{ScaledMonomial}(monomials(x, 0:degree)),
),
]
@test basis isa MB.explicit_basis_type(typeof(full_basis))
n = binomial(2 + degree, 2)
Expand Down Expand Up @@ -115,7 +121,10 @@ function coefficient_test(
)
@polyvar x y
p = x^4 * y^2 + x^2 * y^4 - 3 * x^2 * y^2 + 1
basis = explicit_basis_covering(FullBasis{B,typeof(x * y)}(), SubBasis{MB.Monomial}(monomials(p)))
basis = explicit_basis_covering(
FullBasis{B,typeof(x * y)}(),
SubBasis{MB.Monomial}(monomials(p)),
)
coefficient_test(basis, p, coefs; kwargs...)
return
end
Expand Down

0 comments on commit 7a3380c

Please sign in to comment.