Skip to content

Commit c35ccd1

Browse files
committed
Just use applyTN for now
1 parent 943b781 commit c35ccd1

File tree

7 files changed

+98
-12
lines changed

7 files changed

+98
-12
lines changed

src/FastTransforms.jl

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ using ToeplitzMatrices, HierarchicalMatrices, LowRankApprox, ProgressMeter, Comp
77
if VERSION < v"0.7-"
88
using Base.FFTW
99
import Base.FFTW: r2rFFTWPlan, unsafe_execute!, fftwSingle, fftwDouble, fftwNumber
10-
import Base.FFTW: libfftw, libfftwf, PlanPtr, r2rFFTWPlan
10+
import Base.FFTW: libfftw, libfftwf, PlanPtr, r2rFFTWPlan, plan_r2r!,
11+
REDFT00, REDFT01, REDFT10, REDFT11,
12+
RODFT00, RODFT01, RODFT10, RODFT11
1113
const LAmul! = Base.A_mul_B!
1214
import Base: Factorization
1315
rmul!(A::AbstractArray, c::Number) = scale!(A,c)
@@ -17,7 +19,9 @@ if VERSION < v"0.7-"
1719
else
1820
using FFTW, LinearAlgebra, DSP
1921
import FFTW: r2rFFTWPlan, unsafe_execute!, fftwSingle, fftwDouble, fftwNumber
20-
import FFTW: libfftw3, libfftw3f, PlanPtr, r2rFFTWPlan
22+
import FFTW: libfftw3, libfftw3f, PlanPtr, r2rFFTWPlan, plan_r2r!,
23+
REDFT00, REDFT01, REDFT10, REDFT11,
24+
RODFT00, RODFT01, RODFT10, RODFT11
2125
const LAmul! = LinearAlgebra.mul!
2226
const libfftw = libfftw3
2327
const libfftwf = libfftw3f
@@ -26,7 +30,7 @@ else
2630
end
2731

2832

29-
import Base: *, \, size, view
33+
import Base: *, \, inv, size, view
3034
import Base: getindex, setindex!, length
3135
import Compat.LinearAlgebra: BlasFloat, BlasInt
3236
import HierarchicalMatrices: HierarchicalMatrix, unsafe_broadcasttimes!

src/chebyshevtransform.jl

Lines changed: 37 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
export plan_chebyshevtransform, plan_ichebyshevtransform, chebyshevtransform, ichebyshevtransform, chebyshevpoints,
2-
plan_chebyshevutransform, plan_ichebyshevutransform, chebyshevutransform, ichebyshevutransform
1+
export plan_chebyshevtransform, plan_ichebyshevtransform, plan_chebyshevtransform!, plan_ichebyshevtransform!,
2+
chebyshevtransform, ichebyshevtransform, chebyshevpoints,
3+
plan_chebyshevutransform, plan_ichebyshevutransform, plan_chebyshevutransform!, plan_ichebyshevutransform!,
4+
chebyshevutransform, ichebyshevutransform
35

46
## Transforms take values at Chebyshev points of the first and second kinds and produce Chebyshev coefficients
57

@@ -63,7 +65,10 @@ chebyshevtransform!(x::AbstractVector{T};kind::Integer=1) where {T<:fftwNumber}
6365

6466
chebyshevtransform(x;kind::Integer=1) = chebyshevtransform!(copy(x);kind=kind)
6567

66-
*(P::ChebyshevTransformPlan{T,k,false},x::AbstractVector{T}) where {T,k} = P.plan*copy(x)
68+
*(P::ChebyshevTransformPlan{T,k,false}, x::AbstractVector{T}) where {T,k} = P.plan*copy(x)
69+
70+
71+
6772

6873
## Inverse transforms take Chebyshev coefficients and produce values at Chebyshev points of the first and second kinds
6974

@@ -72,6 +77,15 @@ struct IChebyshevTransformPlan{T,kind,inplace,P}
7277
plan::P
7378
end
7479

80+
# second kind Chebyshev transforms share a plan with their inverse
81+
# so we support this via inv
82+
inv(P::ChebyshevTransformPlan{T,2,true}) where T = IChebyshevTransformPlan{T,2,true,typeof(P)}(P)
83+
inv(P::IChebyshevTransformPlan{T,2,true}) where T = P.plan
84+
85+
\(P::ChebyshevTransformPlan, x::AbstractArray) = inv(P) * x
86+
\(P::IChebyshevTransformPlan, x::AbstractArray) = inv(P) * x
87+
88+
7589
function plan_ichebyshevtransform!(x::AbstractVector{T};kind::Integer=1) where T<:fftwNumber
7690
if kind == 1
7791
if length(x) == 0
@@ -83,8 +97,7 @@ function plan_ichebyshevtransform!(x::AbstractVector{T};kind::Integer=1) where T
8397
if length(x) 1
8498
error("Cannot create a length $(length(x)) inverse chebyshev transform")
8599
end
86-
plan = plan_chebyshevtransform!(x;kind=2)
87-
IChebyshevTransformPlan{T,2,true,typeof(plan)}(plan)
100+
inv(plan_chebyshevtransform!(x;kind=2))
88101
end
89102
end
90103

@@ -307,3 +320,22 @@ function chebyshevpoints(::Type{T}, n::Integer; kind::Int=1) where T<:Number
307320
end
308321
end
309322
chebyshevpoints(n::Integer; kind::Int=1) = chebyshevpoints(Float64, n; kind=kind)
323+
324+
325+
# sin(nθ) coefficients to values at Clenshaw-Curtis nodes except ±1
326+
327+
struct DSTPlan{T,kind,inplace,P} <: Plan{T}
328+
plan::P
329+
end
330+
331+
DSTPlan{k,inp}(plan) where {k,inp} =
332+
DSTPlan{eltype(plan),k,inp,typeof(plan)}(plan)
333+
334+
335+
plan_DSTI!(x) = length(x) > 0 ? DSTPlan{1,true}(FFTW.plan_r2r!(x, FFTW.RODFT00)) :
336+
ones(x)'
337+
338+
function *(P::DSTPlan{T,1}, x::AbstractArray) where {T}
339+
x = P.plan*x
340+
rmul!(x,half(T))
341+
end

src/clenshawcurtis.jl

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,46 @@ function clenshawcurtisweights!(μ::Vector{T}, plan) where T
1717
μ[1] *= half(T); μ[N] *= half(T)
1818
return μ
1919
end
20+
21+
22+
23+
# Chebyshev-T coefficients to values at Clenshaw-Curtis nodes
24+
25+
applyTN_plan(x) = length(x) > 1 ? FFTW.plan_r2r!(x, FFTW.REDFT00) : fill!(similar(x),1)'
26+
27+
applyTN!(x::Vector{T}) where {T<:AbstractFloat} = applyTN!(x,applyTN_plan(x))
28+
29+
function applyTN!(x::Vector{T},plan) where T<:AbstractFloat
30+
x[1] *= 2; x[end] *=2
31+
plan*x
32+
rmul!(x,half(T))
33+
end
34+
applyTN(x::Vector{T},plan) where {T<:AbstractFloat} = applyTN!(copy(x),plan)
35+
applyTN(x::Vector{T}) where {T<:AbstractFloat} = applyTN!(copy(x))
36+
37+
# Values at Clenshaw-Curtis nodes to Chebyshev-T coefficients
38+
39+
applyTNinv_plan(x) = length(x) > 1 ? FFTW.plan_r2r!(x, FFTW.REDFT00) : ones(x)'
40+
41+
applyTNinv!(x::Vector{T}) where {T<:AbstractFloat} = applyTNinv!(x,applyTNinv_plan(x))
42+
43+
function applyTNinv!(x::Vector{T},plan) where T<:AbstractFloat
44+
plan*x
45+
x[1] /= 2;x[end] /= 2
46+
rmul!(x,inv(length(x)-one(T)))
47+
end
48+
applyTNinv(x::Vector{T},plan) where {T<:AbstractFloat} = applyTNinv!(copy(x),plan)
49+
applyTNinv(x::Vector{T}) where {T<:AbstractFloat} = applyTNinv!(copy(x))
50+
51+
# sin(nθ) coefficients to values at Clenshaw-Curtis nodes except ±1
52+
53+
applyUN_plan(x) = length(x) > 0 ? FFTW.plan_r2r!(x, FFTW.RODFT00) : fill!(similar(x),1)'
54+
55+
applyUN!(x::AbstractVector{T}) where {T<:AbstractFloat} = applyUN!(x,applyUN_plan(x))
56+
57+
function applyUN!(x::AbstractVector{T},plan) where T<:AbstractFloat
58+
plan*x
59+
rmul!(x,half(T))
60+
end
61+
applyUN(x::AbstractVector{T},plan) where {T<:AbstractFloat} = applyUN!(copy(x),plan)
62+
applyUN(x::AbstractVector{T}) where {T<:AbstractFloat} = applyUN!(copy(x))

test/chebyshevtests.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,11 @@ using FastTransforms, Compat, Compat.Test
2323
= x -> [cos(k*acos(x)) for k=0:n-1]' *
2424
@test (0.1) exp(T(0.1))
2525
@test ichebyshevtransform(f̌; kind=2) exp.(p_2)
26+
27+
P = plan_chebyshevtransform!(f; kind=2)
28+
Pi = plan_ichebyshevtransform!(f; kind=2)
29+
@test all((P \ copy(f)) .=== Pi * copy(f))
30+
@test f P \ (P*copy(f)) P * (P\copy(f))
2631
end
2732
end
2833

test/nuffttests.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@ using Compat.Test
33

44
if VERSION v"0.7-"
55
using FFTW
6+
FFTW.set_num_threads(Base.Sys.CPU_THREADS)
7+
else
8+
FFTW.set_num_threads(Base.Sys.CPU_CORES)
69
end
710

811
@testset "Nonuniform fast Fourier transforms" begin
9-
10-
FFTW.set_num_threads(Base.Sys.CPU_CORES)
11-
1212
function nudft1(c::AbstractVector, ω::AbstractVector{T}) where {T<:AbstractFloat}
1313
# Nonuniform discrete Fourier transform of type I
1414

test/runtests.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ srand(0)
55

66
include("basictests.jl")
77

8+
include("chebyshevtests.jl")
9+
810
include("nuffttests.jl")
911

1012
include("chebyshevjacobitests.jl")

test/toeplitztests.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
using FastTransforms, ToeplitzMatrices
22

3-
@testset "BigFloat TOeplitz" begin
3+
@testset "BigFloat Toeplitz" begin
44
T = Toeplitz(BigFloat[1,2,3,4,5], BigFloat[1,6,7,8,0])
55
@test T*ones(BigFloat,5) [22,24,19,16,15]
66

0 commit comments

Comments
 (0)