Skip to content

Commit

Permalink
Merge pull request #238 from jverzani/issue_237
Browse files Browse the repository at this point in the history
use conversion for P(n); closes #237
  • Loading branch information
jverzani authored Jul 1, 2020
2 parents ee2e948 + ea1efb3 commit 6def899
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 8 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name = "Polynomials"
uuid = "f27b6e38-b328-58d1-80ce-0feddd5e7a45"
license = "MIT"
author = "JuliaMath"
version = "1.1.1"
version = "1.1.2"

[deps]
Intervals = "d8418881-c3e1-53bb-8760-2df7ec849ed5"
Expand Down
4 changes: 2 additions & 2 deletions src/abstract.jl
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ macro register(name)
$poly{T}(x::AbstractVector{S}, var::SymbolLike = :x) where {T,S<:Number} =
$poly(T.(x), Symbol(var))
$poly{T}(n::S, var::SymbolLike = :x) where {T, S<:Number} =
$poly(T[n], Symbol(var))
$poly(n::Number, var::SymbolLike = :x) = $poly([n], Symbol(var))
n * one($poly{T}, Symbol(var))
$poly(n::S, var::SymbolLike = :x) where {S <: Number} = n * one($poly{S}, Symbol(var))
$poly{T}(var::SymbolLike=:x) where {T} = variable($poly{T}, Symbol(var))
$poly(var::SymbolLike=:x) = variable($poly, Symbol(var))
end
Expand Down
2 changes: 1 addition & 1 deletion src/common.jl
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,7 @@ Base.zero(p::P) where {P <: AbstractPolynomial} = zero(P, p.var)
Returns a representation of 1 as the given polynomial.
"""
Base.one(::Type{P}, var=:x) where {P <: AbstractPolynomial} = (P)(ones(eltype(P),1), var)
Base.one(::Type{P}, var=:x) where {P <: AbstractPolynomial} = (P)(ones(eltype(P),1), var) # assumes p₀ = 1
Base.one(p::P) where {P <: AbstractPolynomial} = one(P, p.var)

Base.oneunit(::Type{P}, args...) where {P <: AbstractPolynomial} = one(P, args...)
Expand Down
8 changes: 4 additions & 4 deletions src/polynomials/Poly.jl
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@ Polynomials.@register Poly
Base.convert(P::Type{<:Polynomial}, p::Poly{T}) where {T} = P(p.coeffs, p.var)

Base.eltype(P::Type{<:Poly}) = P
Base.zero(::Type{<:Poly{T}},var=:x) where {T} = Poly{T}(zeros(T,0), var)
Base.zero(::Type{<:Poly},var=:x) where {T} = Poly(zeros(Float64,0), var)
Base.one(::Type{<:Poly{T}},var=:x) where {T} = Poly{T}(ones(T,1), var)
Base.one(::Type{<:Poly},var=:x) where {T} = Poly(ones(Float64,1), var)
_eltype(::Type{<:Poly{T}}) where {T} = T
_eltype(::Type{Poly}) = Float64
Base.zero(P::Type{<:Poly},var=:x) = Poly(zeros(_eltype(P),0), var)
Base.one(P::Type{<:Poly},var=:x) = Poly(ones(_eltype(P),1), var)
function Polynomials.basis(P::Type{<:Poly}, k::Int, _var::Polynomials.SymbolLike=:x; var=_var)
zs = zeros(Int, k+1)
zs[end] = 1
Expand Down
4 changes: 4 additions & 0 deletions test/StandardBasis.jl
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,10 @@ end
@test iszero(p0)
P != LaurentPolynomial && @test degree(p0) == -1

# P(2) is 2 (not 2p₀) connvert(Polynomial, P(s::Number)) = Polynomial(s)
@test convert(Polynomial, P(2)) Polynomial(2)
@test P(2) 2*one(P)

# variable(), P() to generate `x` in given basis
@test degree(variable(P)) == 1
@test variable(P)(1) == 1
Expand Down

2 comments on commit 6def899

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

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 v1.1.2 -m "<description of version>" 6def89946e386085349310b581f8286c2093855f
git push origin v1.1.2

Please sign in to comment.