Skip to content

Commit ad781ef

Browse files
authored
remove ambiguities (#436)
* remove ambiguities * remove module qualifier
1 parent 089d03b commit ad781ef

8 files changed

+28
-5
lines changed

src/common.jl

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -851,6 +851,7 @@ function Base.:+(p::P, c::S) where {T,X, P<:AbstractPolynomial{T,X}, S}
851851
q + R(c)
852852
end
853853

854+
854855
# polynomial + polynomial when different types
855856
function Base.:+(p::P, q::Q) where {T,X,P <: AbstractPolynomial{T,X}, S,Y,Q <: AbstractPolynomial{S,Y}}
856857
isconstant(p) && return constantterm(p) + q
@@ -944,6 +945,12 @@ function scalar_mult(c::S, p::P) where {S, T, X, P<:AbstractPolynomial{T, X}}
944945
𝐏([c * pᵢ for pᵢ coeffs(p)])
945946
end
946947

948+
scalar_mult(c::S, p::Union{P, R}) where {
949+
S<: AbstractPolynomial,
950+
T, X,
951+
P<:AbstractPolynomial{T, X},
952+
R <:AbstractPolynomial{T}
953+
} = throw(DomainError()) # avoid ambiguity, issue #435
947954

948955
function Base.:/(p::P, c::S) where {P <: AbstractPolynomial,S}
949956
_convert(p, coeffs(p) ./ c)
@@ -1082,6 +1089,11 @@ function Base.isapprox(p1::AbstractPolynomial{T},
10821089
return isapprox(p1, _convert(p1, [n]))
10831090
end
10841091

1092+
Base.isapprox(::AbstractPolynomial{T}, ::Missing, args...; kwargs...) where T =
1093+
missing
1094+
Base.isapprox(::Missing, ::AbstractPolynomial{T}, args...; kwargs...) where T =
1095+
missing
1096+
10851097
Base.isapprox(n::S,
10861098
p1::AbstractPolynomial{T};
10871099
rtol::Real = (Base.rtoldefault(T, S, 0)),

src/polynomials/ChebyshevT.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,8 @@ function Base.:+(p::ChebyshevT{T,X}, c::S) where {T,X, S<:Number}
222222
cs[1] += c
223223
ChebyshevT{R,X}(cs)
224224
end
225-
function Base.:+(p::P, c::T) where {T,X,P<:ChebyshevT{T,X}}
225+
226+
function Base.:+(p::P, c::T) where {T <: Number,X,P<:ChebyshevT{T,X}}
226227
cs = collect(T, values(p))
227228
cs[1] += c
228229
P(cs)

src/polynomials/ImmutablePolynomial.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ function scalar_mult(c::S, p::ImmutablePolynomial{T,X,N}) where {T, X,N, S <: Nu
203203
return ImmutablePolynomial(cs, X)
204204
end
205205

206-
function Base.:/(p::ImmutablePolynomial{T,X,N}, c::S) where {T,X,N,S}
206+
function Base.:/(p::ImmutablePolynomial{T,X,N}, c::S) where {T,X,N,S<:Number}
207207
R = eltype(one(T)/one(S))
208208
P = ImmutablePolynomial{R,X}
209209
(N == 0 || isinf(c)) && return zero(P)

src/polynomials/LaurentPolynomial.jl

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,10 +151,15 @@ function Base.convert(::Type{P}, q::StandardBasisPolynomial{S}) where {P <:Laure
151151
(P){T,X}([q[i] for i in eachindex(q)], firstindex(q))
152152
end
153153

154-
function Base.convert(::Type{P}, q::AbstractPolynomial) where {P <:LaurentPolynomial}
154+
function Base.convert(::Type{P}, q::AbstractPolynomial{T,X}) where {T,X,P <:LaurentPolynomial}
155155
convert(P, convert(Polynomial, q))
156156
end
157157

158+
# Ambiguity, issue #435
159+
function Base.convert(𝑷::Type{P}, p::ArnoldiFit{T, M, X}) where {P<:LaurentPolynomial, T, M, X}
160+
convert(𝑷, convert(Polynomial, p))
161+
end
162+
158163
##
159164
## generic functions
160165
##

src/polynomials/factored_polynomial.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ function scalar_mult(p::P, c::S) where {S<:Number, T, X, P <: FactoredPolynomial
273273
end
274274

275275
# scalar division
276-
function Base.:/(p::P, c::S) where {S, T, X, P <: FactoredPolynomial{T, X}}
276+
function Base.:/(p::P, c::S) where {S<:Number, T, X, P <: FactoredPolynomial{T, X}}
277277
p * (1/c)
278278
end
279279

src/polynomials/mutable-arithmetics.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,3 +65,7 @@ macro register_mutable_arithmetic(name)
6565
end
6666
end
6767
end
68+
69+
## Ambiguities. Issue #435
70+
Base.:+(p::P, ::MutableArithmetics.Zero) where {T, X, P<:AbstractPolynomial{T, X}} = p
71+
Base.:+(p::P, ::T) where {T<:MutableArithmetics.Zero, P<:StandardBasisPolynomial{T}} = p

src/polynomials/standard-basis.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -644,7 +644,7 @@ evalpoly(x, p::ArnoldiFit) = polyvalA(p.coeffs, p.H, x)
644644

645645
fit(::Type{ArnoldiFit}, x::AbstractVector{T}, y::AbstractVector{T}, deg::Int=length(x)-1; var=:x, kwargs...) where{T} = polyfitA(x, y, deg; var=var)
646646

647-
Base.convert(::Type{P}, p::ArnoldiFit) where {P <: AbstractPolynomial} = p(variable(P,indeterminate(p)))
647+
Base.convert(::Type{P}, p::ArnoldiFit{T,M,X}) where {P <: AbstractPolynomial,T,M,X} = p(variable(P,indeterminate(p)))
648648

649649

650650

src/rational-functions/common.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,7 @@ Base.:+(p::Number, q::AbstractRationalFunction) = q + p
298298
Base.:+(p::AbstractRationalFunction, q::Number) = p + q*one(p)
299299
Base.:+(p::AbstractPolynomial, q::AbstractRationalFunction) = q + p
300300
Base.:+(p::AbstractRationalFunction, q::AbstractPolynomial) = p + (q//one(q))
301+
Base.:+(p::P, q::T) where {T<: AbstractRationalFunction, P<:StandardBasisPolynomial{T}} = throw(DomainError()) # avoid ambiguity (issue #435.
301302
Base.:+(p::AbstractRationalFunction, q::AbstractRationalFunction) = sum(promote(p,q))
302303
# type should implement this
303304
function Base.:+(p::R, q::R) where {T,X,P,R <: AbstractRationalFunction{T,X,P}}

0 commit comments

Comments
 (0)