Skip to content

Commit 99dbc08

Browse files
committed
change handling of compat
1 parent 6a9739d commit 99dbc08

File tree

5 files changed

+61
-55
lines changed

5 files changed

+61
-55
lines changed

src/Polynomials.jl

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,15 @@ include("show.jl")
88
include("plots.jl")
99
include("contrib.jl")
1010

11+
# Interface for all AbstractPolynomials
12+
include("common.jl")
13+
14+
1115
# Polynomials
1216
include("polynomials/Polynomial.jl")
13-
1417
include("polynomials/ChebyshevT.jl")
1518

1619
# to be deprecated, then removed
17-
include("polynomials/Poly.jl")
18-
include("pade.jl")
19-
20-
# Interface for all AbstractPolynomials
21-
include("common.jl")
20+
include("compat.jl")
2221

2322
end # module

src/common.jl

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -354,9 +354,22 @@ function mapdomain(P::Type{<:AbstractPolynomial}, x::AbstractArray)
354354
end
355355
mapdomain(::P, x::AbstractArray) where {P <: AbstractPolynomial} = mapdomain(P, x)
356356

357+
"""
358+
mapdomain(P::Type{<:AbstractPolynomial}, a , b)
359+
360+
Returns a *linear* function ϕ: [a,b] -> domain(P)
361+
362+
If either endpoint if infinite, returns `identity`.
363+
"""
357364
function mapdomain(P::Type{<:AbstractPolynomial}, a::Number, b::Number)
358365
a, b = a < b ? (a,b) : (b,a)
359-
x -> mapdomain(P, [a,x,b])[2]
366+
dom = domain(P)
367+
m, M = first(dom), last(dom)
368+
(isinf(a) || isinf(b) || isinf(m) || isinf(M)) && return x -> x
369+
x -> begin
370+
lambda = (x-a)/(b-a)
371+
m + lambda * (last(dom) - first(dom))
372+
end
360373
end
361374

362375
#=

src/compat.jl

Lines changed: 25 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,36 @@
1+
## We have renamed the MATLAB/numpy type names to more Julian names
2+
## How to keep the old names during a transition is the question.
13
## The plan: keep these to ensure underlying changes are not disruptive
2-
## then deprecate these
3-
## then release v1.0
4+
## For now we ensure compatability by defining these for `Poly` objects such
5+
## that they do not signal a deprecation (save polyfit)),
6+
## but do for other `AbstractPolynomial` types.
7+
## At v1.0, it is likely these will be removed.
48

5-
## poly(r, var = :x) = fromroots(Polynomial, r; var = var)
6-
## polyval(p::AbstractPolynomial, x::Number) = p(x)
7-
## polyval(p::AbstractPolynomial, x) = p.(x)
9+
## Ensure compatability for now
10+
@deprecate polyval(p::AbstractPolynomial, x::Number) p(x)
11+
@deprecate polyval(p::AbstractPolynomial, x) p.(x)
812

913

10-
## polyint(p::AbstractPolynomial, C = 0) = integrate(p, C)
11-
## polyint(p::AbstractPolynomial, a, b) = integrate(p, a, b)
12-
## polyder(p::AbstractPolynomial, ord = 1) = derivative(p, ord)
13-
## polyfit(x, y, n = length(x) - 1, sym=:x) = fit(Polynomial, x, y, n; var = sym)
14-
## polyfit(x, y, sym::Symbol) = fit(Polynomial, x, y, var = sym)
14+
@deprecate polyint(p::AbstractPolynomial, C = 0) integrate(p, C)
15+
@deprecate polyint(p::AbstractPolynomial, a, b) integrate(p, a, b)
1516

16-
## padeval(PQ::Pade, x::Number) = PQ(x)
17-
## padeval(PQ::Pade, x) = PQ.(x)
17+
@deprecate polyder(p::AbstractPolynomial, ord = 1) derivative(p, ord)
1818

19-
## export poly, polyval, polyint, polyder, polyfit, padeval
19+
@deprecate polyfit(x, y, n = length(x) - 1, sym=:x) fit(Poly, x, y, n; var = sym)
20+
@deprecate polyfit(x, y, sym::Symbol) fit(Poly, x, y, var = sym)
2021

2122

22-
## @deprecate poly(r, var = :x) fromroots(Polynomial, r; var = var)
23-
## @deprecate polyval(p::AbstractPolynomial, x::Number) p(x)
24-
## @deprecate polyval(p::AbstractPolynomial, x) p.(x)
23+
include("polynomials/Poly.jl")
24+
using .PolyCompat
25+
export Poly
26+
export poly, polyval, polyint, polyder, polyfit
2527

26-
## function Base.getproperty(p::AbstractPolynomial, nm::Symbol)
27-
## if nm == :a
28-
## Base.depwarn("AbstracPolynomial.a is deprecated, use AbstracPolynomial.coeffs or coeffs(AbstractPolynomial) instead.",
29-
## Symbol("Base.getproperty"),
30-
## )
31-
## return getfield(p, :coeffs)
32-
## end
33-
## return getfield(p, nm)
34-
## end
3528

36-
## @deprecate polyint(p::AbstractPolynomial, C = 0) integrate(p, C)
37-
## @deprecate polyint(p::AbstractPolynomial, a, b) integrate(p, a, b)
38-
## @deprecate polyder(p::AbstractPolynomial, ord = 1) derivative(p, ord)
39-
## @deprecate polyfit(x, y, n = length(x) - 1) fit(Polynomial, x, y; deg = n)
40-
## @deprecate polyfit(x, y, sym::Symbol) fit(Polynomial, x, y; var = sym)
4129

42-
## @deprecate padeval(PQ::Pade, x::Number) PQ(x)
43-
## @deprecate padeval(PQ::Pade, x) PQ.(x)
30+
31+
## Pade
32+
## Pade will likely be moved into a separate pacakge
33+
include("pade.jl")
34+
using .PadeApproximation
35+
export Pade
36+
export padeval

src/pade.jl

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
module PadeApproximation
2+
3+
using ..Polynomials
4+
export Pade, padeval
5+
16
#=
27
Pade approximation
38
@@ -100,4 +105,6 @@ true
100105
padeval(PQ::Pade, x::Number) = PQ(x)
101106
padeval(PQ::Pade, x) = PQ.(x)
102107

103-
export padeval
108+
109+
110+
end

src/polynomials/Poly.jl

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
module PolyCompat
22

33
using ..Polynomials
4+
export poly, polyval, polyint, polyder, polyfit
5+
46
#=
57
This type is only here to provide stability while deprecating. This will eventually be removed in favor
68
of `Polynomial` =#
@@ -32,7 +34,7 @@ Polynomials.@register Poly
3234

3335
Base.convert(P::Type{<:Polynomial}, p::Poly{T}) where {T} = P(p.coeffs, p.var)
3436

35-
Polynomials.domain(::Type{<:Poly}) = Interval(-Inf, Inf)
37+
Polynomials.domain(::Type{<:Poly}) = Polynomials.Interval(-Inf, Inf)
3638
Polynomials.mapdomain(::Type{<:Poly}, x::AbstractArray) = x
3739

3840
function (p::Poly{T})(x::S) where {T,S}
@@ -159,8 +161,9 @@ Polynomials.showterm(io::IO, ::Type{Poly{T}}, pj::T, var, j, first::Bool, mimety
159161

160162
## Compat
161163
poly(r, var = :x) = fromroots(Poly, r; var = var)
162-
polyval(p::Poly, x::Number) = p(x)
163-
polyval(p::Poly, x) = p.(x)
164+
165+
Polynomials.polyval(p::Poly, x::Number) = p(x)
166+
Polynomials.polyval(p::Poly, x) = p.(x)
164167

165168
function Base.getproperty(p::Poly, nm::Symbol)
166169
if nm == :a
@@ -169,17 +172,8 @@ function Base.getproperty(p::Poly, nm::Symbol)
169172
return getfield(p, nm)
170173
end
171174

172-
polyint(p::Poly, C = 0) = integrate(p, C)
173-
polyint(p::Poly, a, b) = integrate(p, a, b)
174-
polyder(p::Poly, ord = 1) = derivative(p, ord)
175-
polyfit(x, y, n = length(x) - 1, sym=:x) = fit(Poly, x, y, n; var = sym)
176-
polyfit(x, y, sym::Symbol) = fit(Poly, x, y, var = sym)
177-
178-
export poly, polyval, polyint, polyder, polyfit
175+
Polynomials.polyint(p::Poly, C = 0) = integrate(p, C)
176+
Polynomials.polyint(p::Poly, a, b) = integrate(p, a, b)
177+
Polynomials.polyder(p::Poly, ord = 1) = derivative(p, ord)
179178

180179
end
181-
182-
## Ensure compatability for now
183-
using .PolyCompat
184-
export Poly
185-
export poly, polyval, polyint, polyder, polyfit, padeval

0 commit comments

Comments
 (0)