Skip to content

Commit

Permalink
Support planning Chebyshev via specifying type and size
Browse files Browse the repository at this point in the history
  • Loading branch information
dlfivefifty committed Nov 15, 2023
1 parent 90d1dae commit 77efdb0
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 13 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name = "FastTransforms"
uuid = "057dd010-8810-581a-b7be-e3fc3b93f78c"
version = "0.15.12"
version = "0.15.13"

[deps]
AbstractFFTs = "621f4979-c628-5d54-868e-fcf4e3e8185c"
Expand Down
23 changes: 11 additions & 12 deletions src/chebyshevtransform.jl
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,6 @@ function plan_chebyshevtransform(x::AbstractArray{T,N}, ::Val{2}, dims...; kws..
ChebyshevTransformPlan{T,2}(FFTW.plan_r2r(x, SECONDKIND, dims...; kws...))
end

plan_chebyshevtransform!(x::AbstractArray, dims...; kws...) = plan_chebyshevtransform!(x, Val(1), dims...; kws...)
plan_chebyshevtransform(x::AbstractArray, dims...; kws...) = plan_chebyshevtransform(x, Val(1), dims...; kws...)


# convert x if necessary
@inline _plan_mul!(y::AbstractArray{T}, P::Plan{T}, x::StridedArray{T}) where T = mul!(y, P, x)
Expand Down Expand Up @@ -275,9 +272,6 @@ function plan_ichebyshevtransform(x::AbstractArray{T}, ::Val{2}, dims...; kws...
inv(plan_chebyshevtransform(x, Val(2), dims...; kws...))
end

plan_ichebyshevtransform!(x::AbstractArray, dims...; kws...) = plan_ichebyshevtransform!(x, Val(1), dims...; kws...)
plan_ichebyshevtransform(x::AbstractArray, dims...; kws...) = plan_ichebyshevtransform(x, Val(1), dims...; kws...)

@inline function _icheb1_prescale!(d::Number, x::AbstractArray)
lmul_dim_begin!(2, d, x)
x
Expand Down Expand Up @@ -423,9 +417,6 @@ function plan_chebyshevutransform(x::AbstractArray{T,N}, ::Val{2}, dims...; kws.
ChebyshevUTransformPlan{T,2}(FFTW.plan_r2r(x, USECONDKIND, dims...; kws...))
end

plan_chebyshevutransform!(x::AbstractArray, dims...; kws...) = plan_chebyshevutransform!(x, Val(1), dims...; kws...)
plan_chebyshevutransform(x::AbstractArray, dims...; kws...) = plan_chebyshevutransform(x, Val(1), dims...; kws...)


_permfirst(d, N) = [d; 1:d-1; d+1:N]

Expand Down Expand Up @@ -580,9 +571,6 @@ function plan_ichebyshevutransform(x::AbstractArray{T,N}, ::Val{2}, dims...; kws
end


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

# second kind Chebyshev transforms share a plan with their inverse
# so we support this via inv
inv(P::ChebyshevUTransformPlan{T,2}) where {T} = IChebyshevUTransformPlan{T,2}(P.plan)
Expand Down Expand Up @@ -798,3 +786,14 @@ end
copyto!(x, IChebyshevTransformPlan{T,1,Nothing,false,N,R}() * x)
# *(P::IChebyshevTransformPlan{T,SECONDKIND,false,Nothing}, x::AbstractVector{T}) where T =
# IChebyshevTransformPlan{T,SECONDKIND,true,Nothing}() * copy(x)


for pln in (:plan_chebyshevtransform!, :plan_chebyshevtransform,
:plan_chebyshevutransform!, :plan_chebyshevutransform,
:plan_ichebyshevutransform, :plan_ichebyshevutransform!,
:plan_ichebyshevtransform, :plan_ichebyshevtransform!)
@eval begin
$pln(x::AbstractArray, dims...; kws...) = $pln(x, Val(1), dims...; kws...)
$pln(::Type{T}, szs, dims...; kwds...) where T = $pln(Array{T}(undef, szs...), dims...; kwds...)
end
end
6 changes: 6 additions & 0 deletions test/chebyshevtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -467,4 +467,10 @@ using FastTransforms, Test
@test_throws ErrorException plan_chebyshevtransform(randn(5)) * randn(5,5)
@test_throws ErrorException plan_ichebyshevtransform(randn(5)) * randn(5,5)
end

@testset "plan via size" begin
X = randn(3,4)
p = plan_chebyshevtransform(Float64, (3,4))
@test p * X == chebyshevtransform(X)
end
end

0 comments on commit 77efdb0

Please sign in to comment.