Skip to content

Commit 2832519

Browse files
authored
ChebyshevGrid in points (#216)
* ChebyshevGrid in points * scaled Chebyshev grid * Add tests
1 parent 87a909b commit 2832519

File tree

4 files changed

+42
-5
lines changed

4 files changed

+42
-5
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name = "ApproxFunOrthogonalPolynomials"
22
uuid = "b70543e2-c0d9-56b8-a290-0d4d6d4de211"
3-
version = "0.6.17"
3+
version = "0.6.18"
44

55
[deps]
66
ApproxFunBase = "fbd15aa5-315a-5a7d-a8a4-24992e37be05"

src/ApproxFunOrthogonalPolynomials.jl

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,30 @@ using StaticArrays: SVector
8282
import LinearAlgebra: isdiag
8383

8484
points(d::IntervalOrSegmentDomain{T},n::Integer) where {T} =
85-
fromcanonical.(Ref(d), chebyshevpoints(float(real(eltype(T))), n)) # eltype to handle point
85+
_maybefromcanonical(d, chebyshevpoints(float(real(eltype(T))), n)) # eltype to handle point
86+
_maybefromcanonical(d, pts) = fromcanonical.(Ref(d), pts)
87+
_maybefromcanonical(::ChebyshevInterval, pts::FastTransforms.ChebyshevGrid) = pts
88+
function _maybefromcanonical(d::IntervalOrSegment{<:Union{Number, SVector}}, pts::FastTransforms.ChebyshevGrid)
89+
shift = mean(d)
90+
scale = complexlength(d) / 2
91+
ShiftedChebyshevGrid(pts, shift, scale)
92+
end
93+
94+
struct ShiftedChebyshevGrid{T, S, C<:FastTransforms.ChebyshevGrid} <: AbstractVector{T}
95+
grid :: C
96+
shift :: S
97+
scale :: S
98+
end
99+
function ShiftedChebyshevGrid(grid::G, shift::S, scale::S) where {G,S}
100+
T = typeof(zero(eltype(G)) * zero(S))
101+
ShiftedChebyshevGrid{T,S,G}(grid, shift, scale)
102+
end
103+
Base.size(S::ShiftedChebyshevGrid) = size(S.grid)
104+
Base.@propagate_inbounds Base.getindex(S::ShiftedChebyshevGrid, i::Int) = S.shift + S.grid[i] * S.scale
105+
function Base.showarg(io::IO, S::ShiftedChebyshevGrid, toplevel::Bool)
106+
print(io, "ShiftedChebyshevGrid{", eltype(S), "}")
107+
end
108+
86109
bary(v::AbstractVector{Float64},d::IntervalOrSegmentDomain,x::Float64) = bary(v,tocanonical(d,x))
87110

88111
strictconvert(T::Type, x) = convert(T, x)::T

src/roots.jl

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -217,10 +217,18 @@ function rootsunit_coeffs(c::Vector{T}, htol::Float64,clplan::ClenshawPlan{S,T})
217217
# Find the roots of the polynomial on each piece and then concatenate. Recurse if necessary.
218218

219219
# Evaluate the polynomial at Chebyshev grids on both intervals:
220-
#(clenshaw! overwrites points, which only makes sence if c is real)
220+
#(clenshaw! overwrites points, which only makes sense if c is real)
221221

222-
v1 = isa(c,Vector{Float64}) ? clenshaw!( c, points(-1..splitPoint,n),clplan) : clenshaw( c, points(-1..splitPoint,n),clplan)
223-
v2 = isa(c,Vector{Float64}) ? clenshaw!( c, points(splitPoint..1 ,n),clplan) : clenshaw( c, points(splitPoint..1 ,n),clplan)
222+
v1 = if isa(c, Vector{Float64})
223+
clenshaw!(c, convert(Vector, points(-1..splitPoint,n)), clplan)
224+
else
225+
clenshaw(c, points(-1..splitPoint,n),clplan)
226+
end
227+
v2 = if isa(c, Vector{Float64})
228+
clenshaw!(c, convert(Vector, points(splitPoint..1 ,n)), clplan)
229+
else
230+
clenshaw(c, points(splitPoint..1 ,n),clplan)
231+
end
224232

225233
# Recurse (and map roots back to original interval):
226234
p = plan_chebyshevtransform( v1 )

test/ChebyshevTest.jl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,12 @@ using ApproxFunOrthogonalPolynomials: forwardrecurrence
3939
@test y == 2Fun()
4040
end
4141

42+
@testset "points" begin
43+
p = points(Chebyshev(-1..1), 4)
44+
@test points(Chebyshev(), 4) p
45+
@test contains(summary(p), "ShiftedChebyshevGrid{Float64}")
46+
end
47+
4248
@testset "inference in Space(::Interval)" begin
4349
S = @inferred Space(0..1)
4450
f = Fun(S)

0 commit comments

Comments
 (0)