Skip to content

Commit feae79d

Browse files
authored
Issue 449b (#451)
* over_ring * change name; special case factored polynomial * fix issues with 449
1 parent 591b40a commit feae79d

File tree

4 files changed

+16
-8
lines changed

4 files changed

+16
-8
lines changed

Project.toml

+1-1
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 = "3.2.1"
5+
version = "3.2.2"
66

77
[deps]
88
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"

src/common.jl

+9-4
Original file line numberDiff line numberDiff line change
@@ -467,14 +467,19 @@ function _eltype(P::Type{<:AbstractPolynomial}, p::AbstractPolynomial)
467467
end
468468

469469
"""
470-
copy_with_eltype(T, [X], p::AbstractPolynomial)
470+
copy_with_eltype(::Val{T}, [::Val{X}], p::AbstractPolynomial)
471471
472472
Copy polynomial `p` changing the underlying element type and optionally the symbol.
473473
"""
474-
function copy_with_eltype(::Type{T}, X, p::P) where {T, S, Y, P<:AbstractPolynomial{S, Y}}
474+
copy_with_eltype(::Val{T}, ::Val{X}, p::P) where {T, X, S, Y, P <:AbstractPolynomial{S,Y}} =
475475
(P){T, X}(p.coeffs)
476-
end
477-
copy_with_eltype(::Type{T}, p::P) where {T, S, X, P<:AbstractPolynomial{S,X}} = copy_with_eltype(T, X, p)
476+
copy_with_eltype(V::Val{T}, p::P) where {T, S, Y, P <:AbstractPolynomial{S,Y}} =
477+
copy_with_eltype(V, Val(Y), p)
478+
# easier to type if performance isn't an issue, but could be dropped
479+
copy_with_eltype(::Type{T}, X, p::P) where {T, S, Y, P<:AbstractPolynomial{S, Y}} =
480+
copy_with_eltype(Val(T), Val(X), p)
481+
copy_with_eltype(::Type{T}, p::P) where {T, S, X, P<:AbstractPolynomial{S,X}} =
482+
copy_with_eltype(Val(T), Val(X), p)
478483

479484
Base.iszero(p::AbstractPolynomial) = all(iszero, p)
480485

src/polynomials/factored_polynomial.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ function Base.convert(P::Type{<:FactoredPolynomial}, p::Polynomial{T,X}) where {
119119
(P)(coeffs(p), X)
120120
end
121121

122-
function copy_with_eltype(::Type{T}, X, p::P) where {T, S, Y, P<:FactoredPolynomial{S, Y}}
122+
function copy_with_eltype(::Val{T}, ::Val{X}, p::P) where {T, X, S, Y, P<:FactoredPolynomial{S, Y}}
123123
d = convert(Dict{T, Int}, p.coeffs)
124124
FactoredPolynomial{T, X}(d)
125125
end

test/StandardBasis.jl

+5-2
Original file line numberDiff line numberDiff line change
@@ -800,8 +800,11 @@ end
800800
for T in (Float64, Rational)
801801
xs = [1,2,3]
802802
p = fromroots(P,xs)
803-
@test Polynomials.copy_with_eltype(T, p) == fromroots(P, T.(xs))
804-
@test Polynomials.copy_with_eltype(T, :u, p) == fromroots(P, T.(xs); var=:u)
803+
@test Polynomials.copy_with_eltype(Val(T), p) == fromroots(P, T.(xs))
804+
@test Polynomials.copy_with_eltype(Val(T), Val(:u), p) == fromroots(P, T.(xs); var=:u)
805+
P == ImmutablePolynomial && continue
806+
@inferred Polynomials.copy_with_eltype(Val(T), Val(:u), p)
807+
@inferred Polynomials.copy_with_eltype(Val(T), p)
805808
end
806809
end
807810
end

0 commit comments

Comments
 (0)