Skip to content

Commit

Permalink
ChebyshevGrid in points (#216)
Browse files Browse the repository at this point in the history
* ChebyshevGrid in points

* scaled Chebyshev grid

* Add tests
  • Loading branch information
jishnub authored Mar 11, 2023
1 parent 87a909b commit 2832519
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name = "ApproxFunOrthogonalPolynomials"
uuid = "b70543e2-c0d9-56b8-a290-0d4d6d4de211"
version = "0.6.17"
version = "0.6.18"

[deps]
ApproxFunBase = "fbd15aa5-315a-5a7d-a8a4-24992e37be05"
Expand Down
25 changes: 24 additions & 1 deletion src/ApproxFunOrthogonalPolynomials.jl
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,30 @@ using StaticArrays: SVector
import LinearAlgebra: isdiag

points(d::IntervalOrSegmentDomain{T},n::Integer) where {T} =
fromcanonical.(Ref(d), chebyshevpoints(float(real(eltype(T))), n)) # eltype to handle point
_maybefromcanonical(d, chebyshevpoints(float(real(eltype(T))), n)) # eltype to handle point
_maybefromcanonical(d, pts) = fromcanonical.(Ref(d), pts)
_maybefromcanonical(::ChebyshevInterval, pts::FastTransforms.ChebyshevGrid) = pts
function _maybefromcanonical(d::IntervalOrSegment{<:Union{Number, SVector}}, pts::FastTransforms.ChebyshevGrid)
shift = mean(d)
scale = complexlength(d) / 2
ShiftedChebyshevGrid(pts, shift, scale)
end

struct ShiftedChebyshevGrid{T, S, C<:FastTransforms.ChebyshevGrid} <: AbstractVector{T}
grid :: C
shift :: S
scale :: S
end
function ShiftedChebyshevGrid(grid::G, shift::S, scale::S) where {G,S}
T = typeof(zero(eltype(G)) * zero(S))
ShiftedChebyshevGrid{T,S,G}(grid, shift, scale)
end
Base.size(S::ShiftedChebyshevGrid) = size(S.grid)
Base.@propagate_inbounds Base.getindex(S::ShiftedChebyshevGrid, i::Int) = S.shift + S.grid[i] * S.scale
function Base.showarg(io::IO, S::ShiftedChebyshevGrid, toplevel::Bool)
print(io, "ShiftedChebyshevGrid{", eltype(S), "}")
end

bary(v::AbstractVector{Float64},d::IntervalOrSegmentDomain,x::Float64) = bary(v,tocanonical(d,x))

strictconvert(T::Type, x) = convert(T, x)::T
Expand Down
14 changes: 11 additions & 3 deletions src/roots.jl
Original file line number Diff line number Diff line change
Expand Up @@ -217,10 +217,18 @@ function rootsunit_coeffs(c::Vector{T}, htol::Float64,clplan::ClenshawPlan{S,T})
# Find the roots of the polynomial on each piece and then concatenate. Recurse if necessary.

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

v1 = isa(c,Vector{Float64}) ? clenshaw!( c, points(-1..splitPoint,n),clplan) : clenshaw( c, points(-1..splitPoint,n),clplan)
v2 = isa(c,Vector{Float64}) ? clenshaw!( c, points(splitPoint..1 ,n),clplan) : clenshaw( c, points(splitPoint..1 ,n),clplan)
v1 = if isa(c, Vector{Float64})
clenshaw!(c, convert(Vector, points(-1..splitPoint,n)), clplan)
else
clenshaw(c, points(-1..splitPoint,n),clplan)
end
v2 = if isa(c, Vector{Float64})
clenshaw!(c, convert(Vector, points(splitPoint..1 ,n)), clplan)
else
clenshaw(c, points(splitPoint..1 ,n),clplan)
end

# Recurse (and map roots back to original interval):
p = plan_chebyshevtransform( v1 )
Expand Down
6 changes: 6 additions & 0 deletions test/ChebyshevTest.jl
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@ using ApproxFunOrthogonalPolynomials: forwardrecurrence
@test y == 2Fun()
end

@testset "points" begin
p = points(Chebyshev(-1..1), 4)
@test points(Chebyshev(), 4) p
@test contains(summary(p), "ShiftedChebyshevGrid{Float64}")
end

@testset "inference in Space(::Interval)" begin
S = @inferred Space(0..1)
f = Fun(S)
Expand Down

2 comments on commit 2832519

@jishnub
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/79398

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 v0.6.18 -m "<description of version>" 2832519863702d0cd87cd510f71a0e6135aa47e8
git push origin v0.6.18

Please sign in to comment.