Skip to content

Commit 17adac8

Browse files
committed
Clarify documentation, rename _output_size -> output_size
1 parent 00eef4f commit 17adac8

File tree

3 files changed

+64
-25
lines changed

3 files changed

+64
-25
lines changed

docs/src/api.md

+18-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# Public Interface
22

3+
## FFT and FFT planning functions
4+
35
```@docs
46
AbstractFFTs.fft
57
AbstractFFTs.fft!
@@ -20,15 +22,26 @@ AbstractFFTs.plan_rfft
2022
AbstractFFTs.plan_brfft
2123
AbstractFFTs.plan_irfft
2224
AbstractFFTs.fftdims
23-
Base.adjoint
24-
AbstractFFTs.FFTAdjointStyle
25-
AbstractFFTs.RFFTAdjointStyle
26-
AbstractFFTs.IRFFTAdjointStyle
27-
AbstractFFTs.UnitaryAdjointStyle
2825
AbstractFFTs.fftshift
2926
AbstractFFTs.fftshift!
3027
AbstractFFTs.ifftshift
3128
AbstractFFTs.ifftshift!
3229
AbstractFFTs.fftfreq
3330
AbstractFFTs.rfftfreq
31+
Base.size
32+
```
33+
34+
## Adjoint functionality
35+
36+
The following API is supported by plans that support adjoint functionality.
37+
It is also relevant to implementers of FFT plans that wish to support adjoints.
38+
```@docs
39+
Base.adjoint
40+
AbstractFFTs.AdjointStyle
41+
AbstractFFTs.output_size
42+
AbstractFFTs.adjoint_mul
43+
AbstractFFTs.FFTAdjointStyle
44+
AbstractFFTs.RFFTAdjointStyle
45+
AbstractFFTs.IRFFTAdjointStyle
46+
AbstractFFTs.UnitaryAdjointStyle
3447
```

docs/src/implementations.md

+4-5
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,10 @@ To define a new FFT implementation in your own module, you should
3232

3333
* You can also define similar methods of `plan_rfft` and `plan_brfft` for real-input FFTs.
3434

35-
* We offer an experimental `AdjointStyle` trait to enable automatic computation of adjoint plans via [`Base.adjoint`](@ref).
36-
To support adjoints in a new plan, define the trait `AbstractFFTs.AdjointStyle(::MyPlan)`. This should return a subtype of `AS <: AbstractFFTs.AdjointStyle` supporting `AbstractFFTs.adjoint_mul(::Plan, ::AbstractArray, ::AS)` and
37-
`AbstractFFTs._output_size(::Plan, ::AS)`.
38-
39-
`AbstractFFTs` pre-implements the following adjoint styles: [`AbstractFFTs.FFTAdjointStyle`](@ref), [`AbstractFFTs.RFFTAdjointStyle`](@ref), [`AbstractFFTs.IRFFTAdjointStyle`](@ref), and [`AbstractFFTs.UnitaryAdjointStyle`](@ref).
35+
* To support adjoints in a new plan, define the trait [`AbstractFFTs.AdjointStyle`](@ref).
36+
`AbstractFFTs` implements the following adjoint styles: [`AbstractFFTs.FFTAdjointStyle`](@ref), [`AbstractFFTs.RFFTAdjointStyle`](@ref), [`AbstractFFTs.IRFFTAdjointStyle`](@ref), and [`AbstractFFTs.UnitaryAdjointStyle`](@ref).
37+
To define a new adjoint style of type `AS <: AbstractFFTs.AdjointStyle`, define the methods
38+
[`AbstractFFTs.adjoint_mul`](@ref) and [`AbstractFFTs.output_size`](@ref).
4039

4140
The normalization convention for your FFT should be that it computes ``y_k = \sum_j x_j \exp(-2\pi i j k/n)`` for a transform of
4241
length ``n``, and the "backwards" (unnormalized inverse) transform computes the same thing but with ``\exp(+2\pi i jk/n)``.

src/definitions.jl

+42-15
Original file line numberDiff line numberDiff line change
@@ -583,12 +583,19 @@ plan_brfft
583583

584584
##############################################################################
585585

586+
"""
587+
AbstractFFTs.AdjointStyle(::Plan)
588+
589+
Return the adjoint style of a plan, enabling automatic computation of adjoint plans via
590+
[`Base.adjoint`](@ref). Instructions for supporting adjoint styles are provided in the
591+
[implementation instructions](implementations.md#Defining-a-new-implementation).
592+
"""
586593
abstract type AdjointStyle end
587594

588595
"""
589596
FFTAdjointStyle()
590597
591-
Projection style for complex to complex discrete Fourier transforms that normalize
598+
Adjoint style for complex to complex discrete Fourier transforms that normalize
592599
the output analogously to [`fft`](@ref).
593600
594601
Since the Fourier transform is unitary up to a scaling, the adjoint simply applies
@@ -599,8 +606,8 @@ struct FFTAdjointStyle <: AdjointStyle end
599606
"""
600607
RFFTAdjointStyle()
601608
602-
Projection style for real to complex discrete Fourier transforms that halve
603-
one of the output's dimensions and normalize the output analogously to [`rfft`](@ref).
609+
Adjoint style for real to complex discrete Fourier transforms that halve one of
610+
the output's dimensions and normalize the output, analogously to [`rfft`](@ref).
604611
605612
Since the Fourier transform is unitary up to a scaling, the adjoint applies the transform's
606613
inverse, but with additional logic to handle the fact that the output is projected
@@ -611,8 +618,8 @@ struct RFFTAdjointStyle <: AdjointStyle end
611618
"""
612619
IRFFTAdjointStyle(d::Dim)
613620
614-
Projection style for complex to real discrete Fourier transforms that expect
615-
an input with a halved dimension and normalize the output analogously to [`irfft`](@ref),
621+
Adjoint style for complex to real discrete Fourier transforms that expect an input
622+
with a halved dimension and normalize the output, analogously to [`irfft`](@ref),
616623
where `d` is the original length of the dimension.
617624
618625
Since the Fourier transform is unitary up to a scaling, the adjoint applies the transform's
@@ -626,15 +633,22 @@ end
626633
"""
627634
UnitaryAdjointStyle()
628635
629-
Projection style for unitary transforms, whose adjoint equals their inverse.
636+
Adjoint style for unitary transforms, whose adjoint equals their inverse.
630637
"""
631638
struct UnitaryAdjointStyle <: AdjointStyle end
632639

633-
output_size(p::Plan) = _output_size(p, AdjointStyle(p))
634-
_output_size(p::Plan, ::FFTAdjointStyle) = size(p)
635-
_output_size(p::Plan, ::RFFTAdjointStyle) = rfft_output_size(size(p), fftdims(p))
636-
_output_size(p::Plan, s::IRFFTAdjointStyle) = brfft_output_size(size(p), s.dim, fftdims(p))
637-
_output_size(p::Plan, ::UnitaryAdjointStyle) = size(p)
640+
"""
641+
output_size(p::Plan)
642+
643+
Return the size of the output of a plan `p`.
644+
645+
Implementations of a new adjoint style `AS <: AbstractFFTs.AdjointStyle` should define `output_size(::Plan, ::AS)`.
646+
"""
647+
output_size(p::Plan) = output_size(p, AdjointStyle(p))
648+
output_size(p::Plan, ::FFTAdjointStyle) = size(p)
649+
output_size(p::Plan, ::RFFTAdjointStyle) = rfft_output_size(size(p), fftdims(p))
650+
output_size(p::Plan, s::IRFFTAdjointStyle) = brfft_output_size(size(p), s.dim, fftdims(p))
651+
output_size(p::Plan, ::UnitaryAdjointStyle) = size(p)
638652

639653
struct AdjointPlan{T,P<:Plan} <: Plan{T}
640654
p::P
@@ -645,9 +659,7 @@ end
645659
(p::Plan)'
646660
adjoint(p::Plan)
647661
648-
Form the adjoint operator of an FFT plan. Returns a plan that performs the adjoint operation of
649-
the original plan. Note that this differs from the corresponding backwards plan in the case of real
650-
FFTs due to the halving of one of the dimensions of the FFT output, as described in [`rfft`](@ref).
662+
Return a plan that performs the adjoint operation of the original plan.
651663
652664
!!! note
653665
Adjoint plans do not currently support `LinearAlgebra.mul!`. Further, as a new addition to `AbstractFFTs`,
@@ -658,10 +670,25 @@ Base.adjoint(p::AdjointPlan) = p.p
658670
# always have AdjointPlan inside ScaledPlan.
659671
Base.adjoint(p::ScaledPlan) = ScaledPlan(p.p', p.scale)
660672

673+
"""
674+
size(p::Plan)
675+
676+
Return the size of the input of a plan `p`.
677+
"""
661678
size(p::AdjointPlan) = output_size(p.p)
662679
output_size(p::AdjointPlan) = size(p.p)
663680

664-
Base.:*(p::AdjointPlan, x::AbstractArray) = adjoint_mul(p.p, x, AdjointStyle(p.p))
681+
Base.:*(p::AdjointPlan, x::AbstractArray) = adjoint_mul(p.p, x)
682+
683+
"""
684+
adjoint_mul(p::Plan, x::AbstractArray)
685+
686+
Multiply an array `x` by the adjoint of a plan `p`. This is equivalent to `p' * x`.
687+
688+
Implementations of a new adjoint style `AS <: AbstractFFTs.AdjointStyle` should define
689+
`adjoint_mul(::Plan, ::AbstractArray, ::AS)`.
690+
"""
691+
adjoint_mul(p::Plan, x::AbstractArray) = adjoint_mul(p, x, AdjointStyle(p))
665692

666693
function adjoint_mul(p::Plan{T}, x::AbstractArray, ::FFTAdjointStyle) where {T}
667694
dims = fftdims(p)

0 commit comments

Comments
 (0)