TorchLean API

NN.Runtime.Autograd.Model.Fft

Fourier transforms along a selected axis #

TorchLean’s layer/model definitions are scalar-polymorphic: a model runs over whatever scalar type $\alpha$ you instantiate it with (for example Float, ExecFloat.Binary 8 23, or $\mathbb{R}$). A “real FFT” would normally change the scalar type (real $\to$ complex), but TorchLean’s Layer does not support changing the scalar type mid-model.

This module provides DFT and inverse DFT matrices, and a forward dft layer that assumes $\alpha$ already behaves like a complex field (for example TorchLean.Complex (FloatLib.Floats.ExecFloat.Binary 8 23)).

The layer multiplies by an explicit DFT matrix using const and matmul, so the existing autograd rules apply. This is a dense transform, not a fast FFT algorithm; it is not intended for large n. The inverse matrix does not currently have a corresponding layer constructor here.

Numerics note:

We build twiddle factors using only the Context interface: $I=\sqrt{-1}$ and $e^{-i\theta}=\cos\theta-I\sin\theta$.

This is intended to be instantiated with TorchLean’s own complex scalar TorchLean.Complex β (for some base scalar $\beta$). For real-only scalar backends, the formulas are not meaningful.

The imaginary unit, represented as sqrt(-1) in the ambient scalar type.

Instances For

    Twiddle factor $e^{-2\pi i jk/n}$ written as $\cos\theta-i\sin\theta$.

    Instances For

      Twiddle factor $e^{2\pi i jk/n}$ written as $\cos\theta+i\sin\theta$.

      Instances For

        DFT matrix $F\in\mathbb{C}^{n\times n}$ with entries $F_{k,j}=e^{-2\pi i jk/n}$.

        Instances For

          Inverse DFT matrix $F^{-1}\in\mathbb{C}^{n\times n}$ with entries $(F^{-1})_{j,k}=e^{2\pi i jk/n}/n$.

          Instances For

            Dense Fourier transform along the outermost axis of a tensor.

            This applies the DFT to the leading dimension n of a shape dim n rest by:

            1. reshaping to a matrix n × (numel rest),
            2. left-multiplying by the n×n DFT matrix, then
            3. reshaping back.

            The public dft operation moves the selected axis here and restores the original axis order.

            Instances For

              Dense Fourier transform along axis, numbered from zero.

              This is implemented by swapping the target axis outward (one adjacent swap per step) until it reaches axis 0, applying the outer-axis implementation, then swapping back.

              If $\mathtt{axis}\ge\operatorname{rank}(s)$, this layer is the identity.

              Instances For