Skip to content

Commit 45a1f9f

Browse files
authored
Add inv for 1st kind Chebyshev transforms (#190)
* and inv for 1st kind Chebyshev transforms * v0.14.9 * add tests * add tests * test on 1
1 parent 32a6a0b commit 45a1f9f

File tree

5 files changed

+42
-3
lines changed

5 files changed

+42
-3
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ jobs:
1010
matrix:
1111
version:
1212
- '1.7'
13+
- '1'
1314
os:
1415
- ubuntu-latest
1516
- macOS-latest

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name = "FastTransforms"
22
uuid = "057dd010-8810-581a-b7be-e3fc3b93f78c"
3-
version = "0.14.8"
3+
version = "0.14.9"
44

55
[deps]
66
AbstractFFTs = "621f4979-c628-5d54-868e-fcf4e3e8185c"

src/FastTransforms.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import AbstractFFTs: Plan, ScaledPlan,
1717
plan_fft, plan_ifft, plan_bfft, plan_fft!, plan_ifft!,
1818
plan_bfft!, plan_rfft, plan_irfft, plan_brfft,
1919
fftshift, ifftshift, rfft_output_size, brfft_output_size,
20-
plan_inv, normalization
20+
normalization
2121

2222
import FFTW: dct, dct!, idct, idct!, plan_dct!, plan_idct!,
2323
plan_dct, plan_idct, fftwNumber

src/chebyshevtransform.jl

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,10 @@ IChebyshevTransformPlan{T,kind,K}(F::FFTW.r2rFFTWPlan{T,K,inplace,N,R}) where {T
239239
inv(P::ChebyshevTransformPlan{T,2,K}) where {T,K} = IChebyshevTransformPlan{T,2,K}(P.plan)
240240
inv(P::IChebyshevTransformPlan{T,2,K}) where {T,K} = ChebyshevTransformPlan{T,2,K}(P.plan)
241241

242+
inv(P::ChebyshevTransformPlan{T,1,K,inplace,N}) where {T,K,inplace,N} = IChebyshevTransformPlan{T,1,kindtuple(IFIRSTKIND,N,P.plan.region...)}(inv(P.plan).p)
243+
inv(P::IChebyshevTransformPlan{T,1,K,inplace,N}) where {T,K,inplace,N} = ChebyshevTransformPlan{T,1,kindtuple(FIRSTKIND,N,P.plan.region...)}(inv(P.plan).p)
244+
245+
242246

243247
\(P::ChebyshevTransformPlan, x::AbstractArray) = inv(P) * x
244248
\(P::IChebyshevTransformPlan, x::AbstractArray) = inv(P) * x
@@ -526,13 +530,22 @@ function plan_ichebyshevutransform(x::AbstractArray{T,N}, ::Val{1}, dims...; kws
526530
end
527531
function plan_ichebyshevutransform(x::AbstractArray{T,N}, ::Val{2}, dims...; kws...) where {T<:fftwNumber,N}
528532
any((1),size(x)) && throw(ArgumentError("Array must contain at least 2 entries"))
529-
IChebyshevUTransformPlan{T,2,kindtuple(USECONDKIND,N,dims...)}(FFTW.plan_r2r(x, USECONDKIND))
533+
IChebyshevUTransformPlan{T,2,kindtuple(USECONDKIND,N,dims...)}(FFTW.plan_r2r(x, USECONDKIND, dims...; kws...))
530534
end
531535

532536

533537
plan_ichebyshevutransform!(x::AbstractArray, dims...; kws...) = plan_ichebyshevutransform!(x, Val(1), dims...; kws...)
534538
plan_ichebyshevutransform(x::AbstractArray, dims...; kws...) = plan_ichebyshevutransform(x, Val(1), dims...; kws...)
535539

540+
# second kind Chebyshev transforms share a plan with their inverse
541+
# so we support this via inv
542+
inv(P::ChebyshevUTransformPlan{T,2,K}) where {T,K} = IChebyshevUTransformPlan{T,2,K}(P.plan)
543+
inv(P::IChebyshevUTransformPlan{T,2,K}) where {T,K} = ChebyshevUTransformPlan{T,2,K}(P.plan)
544+
545+
inv(P::ChebyshevUTransformPlan{T,1,K,inplace,N}) where {T,K,inplace,N} = IChebyshevUTransformPlan{T,1,kindtuple(IUFIRSTKIND,N,P.plan.region...)}(inv(P.plan).p)
546+
inv(P::IChebyshevUTransformPlan{T,1,K,inplace,N}) where {T,K,inplace,N} = ChebyshevUTransformPlan{T,1,kindtuple(UFIRSTKIND,N,P.plan.region...)}(inv(P.plan).p)
547+
548+
536549
function _ichebyu1_postscale!(_, x::AbstractVector{T}) where T
537550
n = length(x)
538551
@inbounds for k=1:n # sqrt(1-x_j^2) weight

test/chebyshevtests.jl

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,4 +278,29 @@ using FastTransforms, Test
278278
F = plan_chebyshevtransform([1.,2,3])
279279
@test chebyshevtransform(1.0:3) == F * (1:3)
280280
end
281+
282+
@testset "inv" begin
283+
x = randn(5)
284+
for F in (plan_chebyshevtransform(x), plan_chebyshevtransform(x, Val(2)),
285+
plan_chebyshevutransform(x), plan_chebyshevutransform(x, Val(2)),
286+
plan_ichebyshevtransform(x), plan_ichebyshevtransform(x, Val(2)),
287+
plan_ichebyshevutransform(x), plan_ichebyshevutransform(x, Val(2)))
288+
@test F \ (F*x) F * (F\x) x
289+
end
290+
291+
X = randn(5,4)
292+
for F in (plan_chebyshevtransform(X,Val(1),1), plan_chebyshevtransform(X, Val(2),1),
293+
plan_chebyshevtransform(X,Val(1),2), plan_chebyshevtransform(X, Val(2),2),
294+
plan_ichebyshevtransform(X,Val(1),1), plan_ichebyshevtransform(X, Val(2),1),
295+
plan_ichebyshevtransform(X,Val(1),2), plan_ichebyshevtransform(X, Val(2),2))
296+
@test F \ (F*X) F * (F\X) X
297+
end
298+
# Matrix isn't implemented for chebyshevu
299+
for F in (plan_chebyshevutransform(X,Val(1),1), plan_chebyshevutransform(X, Val(2),1),
300+
plan_chebyshevutransform(X,Val(1),2), plan_chebyshevutransform(X, Val(2),2),
301+
plan_ichebyshevutransform(X,Val(1),1), plan_ichebyshevutransform(X, Val(2),1),
302+
plan_ichebyshevutransform(X,Val(1),2), plan_ichebyshevutransform(X, Val(2),2))
303+
@test_broken F \ (F*X) F * (F\X) X
304+
end
305+
end
281306
end

0 commit comments

Comments
 (0)