Transforms along dimensions
Every function takes a region: the dimensions to transform, as an integer or a collection of integers. The default is all dimensions. Dimensions that are not in the region are batch dimensions: each slice along them is an independent transform.
using FFTL, LinearAlgebra, Random
Random.seed!(4)
A = randn(ComplexF64, 32, 20, 6)
size(fft(A)), size(fft(A, 2))((32, 20, 6), (32, 20, 6))Transforming along dimension 2 gives the same result as transforming each slice A[:, :, k] along its second dimension:
B = fft(A, 2)
slices = [fft(A[:, :, k], 2) for k in 1:size(A, 3)]
all(B[:, :, k] ≈ slices[k] for k in 1:size(A, 3))trueRegions can be several dimensions. The transform is separable, so transforming along 1 and then 3 equals transforming along both at once:
fft(A, (1, 3)) ≈ fft(fft(A, 1), 3)truePlans for a region
The plan is made for one size and one region; plan_fft(A, (1, 3)) is the plan for that combination. Dimensions that share the length and the stride class share a kernel, so a plan for a 3D array costs little more than one for a 1D line.
Passes: one dimension of a strided array
FFTL.plan_pass transforms along one dimension of a strided view, applied to all lines at once. It is the building block of the transforms above, and the entry point for libraries that build special variants of the transform themselves, such as NFFT.jl on its oversampled grid. The plan is made for the size and strides of the view, and applied with mul! or apply!.
Passes are single-threaded by default. A caller that already threads over many arrays keeps threads = 1; see Threads.
Passes for real data
FFTL.plan_r2c_pass(v, d) transforms real lines into half spectra; FFTL.plan_c2r_pass(v, d; n) transforms them back without normalisation. Give the real length n explicitly for odd lengths. These plans fix the input and output sizes, but read each operand's strides on every mul!. The strides may differ between input and output and change between calls, including stepped views along the transformed dimension. With threads = 1 (the default), warmed mul! execution is allocation-free.
source = randn(21, 6)
x = view(source, 2:2:18, 2:5) # nine real samples per line
spectra = zeros(ComplexF64, 7, 8)
X = view(spectra, 2:6, 3:6) # five half-spectrum values per line
pf = FFTL.plan_r2c_pass(x, 1)
mul!(X, pf, x)
pb = FFTL.plan_c2r_pass(X, 1; n = 9)
y = zeros(size(x))
mul!(y, pb, X)
y ./ 9 ≈ xtrueOnly the output view is written; padding in its parent and the input are preserved. The same plans can also execute with dense operands of these sizes.
Passes for real-to-real kinds
FFTL.plan_r2r_pass(v, d, kind) is the same for one real-to-real kind along one dimension (see Cosine, sine and Hartley transforms).