Skip to content

Commit de37170

Browse files
committed
Fixes
1 parent f2f02b4 commit de37170

File tree

4 files changed

+25
-21
lines changed

4 files changed

+25
-21
lines changed

src/arithmetic.jl

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,15 @@ const _APL = MP.AbstractPolynomialLike
22
# We don't define it for all `AlgebraElement` as this would be type piracy
33
const _AE = SA.AlgebraElement{<:SA.StarAlgebra{<:Variables}}
44

5+
function _polynomial(b::FullBasis{Monomial}, c::SA.SparseCoefficients)
6+
return MP.polynomial(collect(SA.values(c)), MP.monomial.(getindex.(Ref(b), SA.keys(c))))
7+
end
8+
9+
function MP.polynomial(a::SA.AlgebraElement)
10+
b = FullBasis{Monomial}(MP.variables(a))
11+
return _polynomial(b, SA.coeffs(a, b))
12+
end
13+
514
for op in [:+, :-, :*]
615
@eval begin
716
function MA.promote_operation(

src/monomial.jl

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,14 @@ end
4545
SA.coeffs(p::Polynomial{Monomial}, ::FullBasis{Monomial}) = p.monomial
4646

4747
function MP.polynomial_type(
48-
::Union{SubBasis{B,M},Type{<:SubBasis{B,M}}},
48+
::Union{SubBasis{B,V,E},Type{<:SubBasis{B,V,E}}},
4949
::Type{T},
50-
) where {B,M,T}
51-
return MP.polynomial_type(FullBasis{B,M}, T)
50+
) where {B,V,E,T}
51+
return _polynomial_type(B, V, T)
5252
end
5353

54-
function MP.polynomial_type(::Type{Polynomial{B,M}}, ::Type{T}) where {B,M,T}
55-
return MP.polynomial_type(FullBasis{B,M}, T)
54+
function MP.polynomial_type(::Type{Polynomial{B,V,E}}, ::Type{T}) where {B,V,E,T}
55+
return _polynomial_type(B, V, T)
5656
end
5757

5858
function MP.polynomial(f::Function, mb::SubBasis{Monomial})
@@ -136,8 +136,12 @@ end
136136

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

139-
function MP.polynomial_type(::Type{FullBasis{B,M}}, ::Type{T}) where {T,B,M}
140-
return MP.polynomial_type(M, _promote_coef(T, B))
139+
function MP.polynomial_type(::Type{<:FullBasis{B,V}}, ::Type{T}) where {T,B,V}
140+
return _polynomial_type(B, V, T)
141+
end
142+
143+
function _polynomial_type(::Type{B}, ::Type{V}, ::Type{T}) where {B, V, T}
144+
return MP.polynomial_type(MP.monomial_type(V), _promote_coef(T, B))
141145
end
142146

143147
_vec(v::Vector) = v

src/orthogonal.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ function univariate_orthogonal_basis(
108108
return univariate_eval!(
109109
B,
110110
Vector{
111-
MP.polynomial_type(Polynomial{B,MP.monomial_type(variable)}, Int),
111+
_polynomial_type(B, typeof(MP.variables(variable)), Int),
112112
}(
113113
undef,
114114
degree + 1,
@@ -158,9 +158,9 @@ function explicit_basis_covering(
158158
end
159159

160160
function explicit_basis_covering(
161-
full::FullBasis{B,M},
162-
monos::SubBasis{<:AbstractMonomial,M},
163-
) where {B<:AbstractMultipleOrthogonal,M}
161+
full::FullBasis{B,V,E},
162+
monos::SubBasis{<:AbstractMonomial,V,E},
163+
) where {B<:AbstractMultipleOrthogonal,V,E}
164164
return SA.SubBasis(full, _covering(full, monos.keys))
165165
end
166166

src/polynomial.jl

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ end
102102
function _algebra_element(p, ::Type{B}) where {B<:AbstractMonomialIndexed}
103103
return algebra_element(
104104
sparse_coefficients(p),
105-
FullBasis{B,MP.monomial_type(typeof(p))}(MP.variables(p)),
105+
FullBasis{B}(MP.variables(p)),
106106
)
107107
end
108108

@@ -158,15 +158,6 @@ function convert_basis(basis::SA.AbstractBasis, p::SA.AlgebraElement)
158158
return SA.AlgebraElement(SA.coeffs(p, basis), algebra(basis))
159159
end
160160

161-
function _polynomial(b::FullBasis{Monomial}, c::SA.SparseCoefficients)
162-
return MP.polynomial(collect(SA.values(c)), MP.monomial.(getindex.(Ref(b), SA.keys(c))))
163-
end
164-
165-
function MP.polynomial(a::SA.AlgebraElement)
166-
b = FullBasis{Monomial}(MP.variables(a))
167-
return _polynomial(b, SA.coeffs(a, b))
168-
end
169-
170161
function Base.isapprox(
171162
p::MP.AbstractPolynomialLike,
172163
a::SA.AlgebraElement;

0 commit comments

Comments
 (0)