Skip to content

Add internal planners #67

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 18 additions & 5 deletions src/plan.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import Base: *
import LinearAlgebra: mul!
using AbstractFFTs: to1, plan_fft, plan_bfft, plan_ifft, plan_rfft

abstract type FFTAPlan{T,N} <: Plan{T} end

Expand All @@ -20,7 +21,7 @@ struct FFTAPlan_re{T,N} <: FFTAPlan{T,N}
flen::Int
end

function AbstractFFTs.plan_fft(x::AbstractArray{T}, region; kwargs...)::FFTAPlan_cx{T} where {T <: Complex}
function __FFTA_plan_fft(x::AbstractArray{T}, region = 1:ndims(x); kwargs...)::FFTAPlan_cx{T} where {T <: Complex}
N = length(region)
@assert N <= 2 "Only supports vectors and matrices"
if N == 1
Expand All @@ -36,7 +37,7 @@ function AbstractFFTs.plan_fft(x::AbstractArray{T}, region; kwargs...)::FFTAPlan
end
end

function AbstractFFTs.plan_bfft(x::AbstractArray{T}, region; kwargs...)::FFTAPlan_cx{T} where {T <: Complex}
function __FFTA_plan_bfft(x::AbstractArray{T}, region = 1:ndims(x); kwargs...)::FFTAPlan_cx{T} where {T <: Complex}
N = length(region)
@assert N <= 2 "Only supports vectors and matrices"
if N == 1
Expand All @@ -52,7 +53,7 @@ function AbstractFFTs.plan_bfft(x::AbstractArray{T}, region; kwargs...)::FFTAPla
end
end

function AbstractFFTs.plan_rfft(x::AbstractArray{T}, region; kwargs...)::FFTAPlan_re{Complex{T}} where {T <: Real}
function __FFTA_plan_rfft(x::AbstractArray{T}, region = 1:ndims(x); kwargs...)::FFTAPlan_re{Complex{T}} where {T <: Real}
N = length(region)
@assert N <= 2 "Only supports vectors and matrices"
if N == 1
Expand All @@ -68,7 +69,7 @@ function AbstractFFTs.plan_rfft(x::AbstractArray{T}, region; kwargs...)::FFTAPla
end
end

function AbstractFFTs.plan_brfft(x::AbstractArray{T}, len, region; kwargs...)::FFTAPlan_re{T} where {T}
function __FFTA_plan_brfft(x::AbstractArray{T}, len, region = 1:ndims(x); kwargs...)::FFTAPlan_re{T} where {T}
N = length(region)
@assert N <= 2 "Only supports vectors and matrices"
if N == 1
Expand Down Expand Up @@ -184,4 +185,16 @@ function *(p::FFTAPlan_re{T,N}, x::AbstractArray{T,2}) where {T<:Union{Real, Com
LinearAlgebra.mul!(y, p, x_tmp)
return y
end
end
end

# Implement AbstractFFTs overloading
for f in (:fft, :bfft, :rfft, :brfft)
pf = Symbol("__FFTA_plan_", f)
abstract_pf = Symbol("plan_", f)
T_super = f == :rfft ? Real : Complex
@eval begin
@inline function AbstractFFTs.$abstract_pf(x::AbstractArray{T}, args...; kws...) where {T<:$T_super}
$pf(x, args...; kws...)
end
end
end
Loading