Skip to content

Commit

Permalink
Issue 449b (#451)
Browse files Browse the repository at this point in the history
* over_ring

* change name; special case factored polynomial

* fix issues with 449
  • Loading branch information
jverzani authored Jan 11, 2023
1 parent 591b40a commit feae79d
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 8 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 = "3.2.1"
version = "3.2.2"

[deps]
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
Expand Down
13 changes: 9 additions & 4 deletions src/common.jl
Original file line number Diff line number Diff line change
Expand Up @@ -467,14 +467,19 @@ function _eltype(P::Type{<:AbstractPolynomial}, p::AbstractPolynomial)
end

"""
copy_with_eltype(T, [X], p::AbstractPolynomial)
copy_with_eltype(::Val{T}, [::Val{X}], p::AbstractPolynomial)
Copy polynomial `p` changing the underlying element type and optionally the symbol.
"""
function copy_with_eltype(::Type{T}, X, p::P) where {T, S, Y, P<:AbstractPolynomial{S, Y}}
copy_with_eltype(::Val{T}, ::Val{X}, p::P) where {T, X, S, Y, P <:AbstractPolynomial{S,Y}} =
(P){T, X}(p.coeffs)
end
copy_with_eltype(::Type{T}, p::P) where {T, S, X, P<:AbstractPolynomial{S,X}} = copy_with_eltype(T, X, p)
copy_with_eltype(V::Val{T}, p::P) where {T, S, Y, P <:AbstractPolynomial{S,Y}} =
copy_with_eltype(V, Val(Y), p)
# easier to type if performance isn't an issue, but could be dropped
copy_with_eltype(::Type{T}, X, p::P) where {T, S, Y, P<:AbstractPolynomial{S, Y}} =
copy_with_eltype(Val(T), Val(X), p)
copy_with_eltype(::Type{T}, p::P) where {T, S, X, P<:AbstractPolynomial{S,X}} =
copy_with_eltype(Val(T), Val(X), p)

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

Expand Down
2 changes: 1 addition & 1 deletion src/polynomials/factored_polynomial.jl
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ function Base.convert(P::Type{<:FactoredPolynomial}, p::Polynomial{T,X}) where {
(P)(coeffs(p), X)
end

function copy_with_eltype(::Type{T}, X, p::P) where {T, S, Y, P<:FactoredPolynomial{S, Y}}
function copy_with_eltype(::Val{T}, ::Val{X}, p::P) where {T, X, S, Y, P<:FactoredPolynomial{S, Y}}
d = convert(Dict{T, Int}, p.coeffs)
FactoredPolynomial{T, X}(d)
end
Expand Down
7 changes: 5 additions & 2 deletions test/StandardBasis.jl
Original file line number Diff line number Diff line change
Expand Up @@ -800,8 +800,11 @@ end
for T in (Float64, Rational)
xs = [1,2,3]
p = fromroots(P,xs)
@test Polynomials.copy_with_eltype(T, p) == fromroots(P, T.(xs))
@test Polynomials.copy_with_eltype(T, :u, p) == fromroots(P, T.(xs); var=:u)
@test Polynomials.copy_with_eltype(Val(T), p) == fromroots(P, T.(xs))
@test Polynomials.copy_with_eltype(Val(T), Val(:u), p) == fromroots(P, T.(xs); var=:u)
P == ImmutablePolynomial && continue
@inferred Polynomials.copy_with_eltype(Val(T), Val(:u), p)
@inferred Polynomials.copy_with_eltype(Val(T), p)
end
end
end
Expand Down

2 comments on commit feae79d

@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/75517

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 v3.2.2 -m "<description of version>" feae79dd5febf1b9ff2454a2c55565b1a5d40b95
git push origin v3.2.2

Please sign in to comment.