Skip to content

Commit

Permalink
Issue 358 (#359)
Browse files Browse the repository at this point in the history
* make P(p::Poly) same as convert(P,p)

* version bump
  • Loading branch information
jverzani authored Oct 20, 2021
1 parent 31814ca commit 8c32e17
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name = "Polynomials"
uuid = "f27b6e38-b328-58d1-80ce-0feddd5e7a45"
license = "MIT"
author = "JuliaMath"
version = "2.0.15"
version = "2.0.16"

[deps]
Intervals = "d8418881-c3e1-53bb-8760-2df7ec849ed5"
Expand Down
6 changes: 6 additions & 0 deletions src/abstract.jl
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,9 @@ macro register(name)
cs = collect(coeffs)
$poly{eltype(cs), Symbol(var)}(cs)
end
$poly{T,X}(c::AbstractPolynomial{S,Y}) where {T,X,S,Y} = convert($poly{T,X}, c)
$poly{T}(c::AbstractPolynomial{S,Y}) where {T,S,Y} = convert($poly{T}, c)
$poly(c::AbstractPolynomial{S,Y}) where {S,Y} = convert($poly, c)
$poly{T,X}(n::S) where {T, X, S<:Number} =
T(n) * one($poly{T, X})
$poly{T}(n::S, var::SymbolLike = :x) where {T, S<:Number} =
Expand Down Expand Up @@ -121,6 +124,9 @@ macro registerN(name, params...)
end
$poly{$(αs...)}(coeffs::AbstractVector{T}, var::SymbolLike=:x) where {$(αs...),T} =
$poly{$(αs...),T,Symbol(var)}(coeffs)
$poly{$(as...),T,X}(c::AbstractPolynomial{S,Y}) where {$(as...),T,X,S,Y} = convert($poly{$(as...),T,X}, c)
$poly{$(as...),T}(c::AbstractPolynomial{S,Y}) where {$(as...),T,S,Y} = convert($poly{$(as...),T}, c)
$poly{$(as...),}(c::AbstractPolynomial{S,Y}) where {$(as...),S,Y} = convert($poly{$(as...),}, c)

$poly{$(αs...),T,X}(n::Number) where {$(αs...),T,X} = T(n)*one($poly{$(αs...),T,X})
$poly{$(αs...),T}(n::Number, var::SymbolLike = :x) where {$(αs...),T} = T(n)*one($poly{$(αs...),T,Symbol(var)})
Expand Down
7 changes: 6 additions & 1 deletion src/polynomials/ChebyshevT.jl
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,12 @@ function Base.convert(P::Type{<:Polynomial}, ch::ChebyshevT)
end
return c0 + c1 * x
end
Base.convert(C::Type{<:ChebyshevT}, p::Polynomial) = p(variable(C))

function Base.convert(C::Type{<:ChebyshevT}, p::Polynomial)
x = variable(C)
isconstant(p) || assert_same_variable(indeterminate(x),indeterminate(p))
p(x)
end

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}

Expand Down
9 changes: 9 additions & 0 deletions test/StandardBasis.jl
Original file line number Diff line number Diff line change
Expand Up @@ -736,6 +736,15 @@ end
# issue #287
p = LaurentPolynomial([1], -5)
@test p convert(LaurentPolynomial{Float64}, p)

# issue #358 `P(p::AbstractPolynomial)` should be `convert(P, p)` not `P(pᵢ for pᵢ ∈ p))`
= Polynomial([0,0,1], :x)
for P (ImmutablePolynomial, SparsePolynomial, ChebyshevT)
@test P(x²) == convert(P, x²)
Q = P{Float64}
@test Q(x²) == convert(Q, x²)
end

end

@testset "Roots" begin
Expand Down

2 comments on commit 8c32e17

@jverzani
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/47080

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v2.0.16 -m "<description of version>" 8c32e17046386030ac237a2a134687c952ddb5aa
git push origin v2.0.16

Please sign in to comment.