Skip to content

Commit 8c32e17

Browse files
authored
Issue 358 (#359)
* make P(p::Poly) same as convert(P,p) * version bump
1 parent 31814ca commit 8c32e17

File tree

4 files changed

+22
-2
lines changed

4 files changed

+22
-2
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name = "Polynomials"
22
uuid = "f27b6e38-b328-58d1-80ce-0feddd5e7a45"
33
license = "MIT"
44
author = "JuliaMath"
5-
version = "2.0.15"
5+
version = "2.0.16"
66

77
[deps]
88
Intervals = "d8418881-c3e1-53bb-8760-2df7ec849ed5"

src/abstract.jl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,9 @@ macro register(name)
9292
cs = collect(coeffs)
9393
$poly{eltype(cs), Symbol(var)}(cs)
9494
end
95+
$poly{T,X}(c::AbstractPolynomial{S,Y}) where {T,X,S,Y} = convert($poly{T,X}, c)
96+
$poly{T}(c::AbstractPolynomial{S,Y}) where {T,S,Y} = convert($poly{T}, c)
97+
$poly(c::AbstractPolynomial{S,Y}) where {S,Y} = convert($poly, c)
9598
$poly{T,X}(n::S) where {T, X, S<:Number} =
9699
T(n) * one($poly{T, X})
97100
$poly{T}(n::S, var::SymbolLike = :x) where {T, S<:Number} =
@@ -121,6 +124,9 @@ macro registerN(name, params...)
121124
end
122125
$poly{$(αs...)}(coeffs::AbstractVector{T}, var::SymbolLike=:x) where {$(αs...),T} =
123126
$poly{$(αs...),T,Symbol(var)}(coeffs)
127+
$poly{$(as...),T,X}(c::AbstractPolynomial{S,Y}) where {$(as...),T,X,S,Y} = convert($poly{$(as...),T,X}, c)
128+
$poly{$(as...),T}(c::AbstractPolynomial{S,Y}) where {$(as...),T,S,Y} = convert($poly{$(as...),T}, c)
129+
$poly{$(as...),}(c::AbstractPolynomial{S,Y}) where {$(as...),S,Y} = convert($poly{$(as...),}, c)
124130

125131
$poly{$(αs...),T,X}(n::Number) where {$(αs...),T,X} = T(n)*one($poly{$(αs...),T,X})
126132
$poly{$(αs...),T}(n::Number, var::SymbolLike = :x) where {$(αs...),T} = T(n)*one($poly{$(αs...),T,Symbol(var)})

src/polynomials/ChebyshevT.jl

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,12 @@ function Base.convert(P::Type{<:Polynomial}, ch::ChebyshevT)
7575
end
7676
return c0 + c1 * x
7777
end
78-
Base.convert(C::Type{<:ChebyshevT}, p::Polynomial) = p(variable(C))
78+
79+
function Base.convert(C::Type{<:ChebyshevT}, p::Polynomial)
80+
x = variable(C)
81+
isconstant(p) || assert_same_variable(indeterminate(x),indeterminate(p))
82+
p(x)
83+
end
7984

8085
Base.promote_rule(::Type{P},::Type{Q}) where {T, X, P <: LaurentPolynomial{T,X}, S, Q <: ChebyshevT{S, X}} = LaurentPolynomial{promote_type(T, S), X}
8186

test/StandardBasis.jl

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -736,6 +736,15 @@ end
736736
# issue #287
737737
p = LaurentPolynomial([1], -5)
738738
@test p convert(LaurentPolynomial{Float64}, p)
739+
740+
# issue #358 `P(p::AbstractPolynomial)` should be `convert(P, p)` not `P(pᵢ for pᵢ ∈ p))`
741+
= Polynomial([0,0,1], :x)
742+
for P (ImmutablePolynomial, SparsePolynomial, ChebyshevT)
743+
@test P(x²) == convert(P, x²)
744+
Q = P{Float64}
745+
@test Q(x²) == convert(Q, x²)
746+
end
747+
739748
end
740749

741750
@testset "Roots" begin

0 commit comments

Comments
 (0)