TorchLean API

NN.Runtime.Autograd.Model.Fno

Fourier Neural Operators over Arbitrary Spatial Rank #

This module implements a Fourier layer over any finite collection of spatial axes. The transform uses separable per-axis FFTs or an explicit dense reference. Its phase is the sum of per-axis phases, so this is the tensor-product multidimensional DFT rather than a one-dimensional DFT of flattened storage. Real and imaginary parts are represented by separate tensors, allowing the model to run over ordinary real scalar backends. The spectral linear map is applied independently at every retained frequency.

def Runtime.Autograd.Model.Layers.FNO.linear (grid inChannels outChannels : ℕ) (weightSeed : ℕ := 0) :
Layer [grid, inChannels] [grid, outChannels]

Pointwise affine channel map over a flattened spatial grid.

Instances For
    @[reducible, inline]

    Tensor shape spatial... × channels.

    Instances For

      Number of spatial grid points.

      Instances For
        @[reducible, inline]

        Matrix view that flattens the spatial axes and preserves the channel axis.

        Instances For
          @[reducible, inline]

          Learned frequency-wise channel maps, one channels × channels matrix per grid frequency.

          Instances For

            Decode a row-major flat index into coordinates for the given axis extents.

            Instances For

              Sum inputᵢ * frequencyᵢ / extentᵢ over matching spatial coordinates.

              Instances For
                def Runtime.Autograd.Model.Layers.FNO.Internal.phase {α : Type} [TorchLean.Storage α] [Context α] (extents : List ℕ) (input frequency : ℕ) :
                α

                Tensor-product DFT phase for two flattened spatial coordinates.

                Instances For

                  Cosine part of the dense multidimensional DFT matrix.

                  Instances For

                    Negative-sine part of the dense multidimensional DFT matrix.

                    Instances For

                      Normalized cosine part of the dense multidimensional inverse DFT matrix.

                      Instances For

                        Normalized sine part of the dense multidimensional inverse DFT matrix.

                        Instances For

                          Whether one coordinate lies in the retained low- or high-frequency bands.

                          Instances For

                            Test membership in the rectangular frequency set selected by modes.

                            The flat index is decoded in the same outermost-first row-major order used by Shape.ofList.

                            Instances For

                              Pointwise mask for the retained multidimensional Fourier modes.

                              Instances For
                                def Runtime.Autograd.Model.Layers.FNO.Internal.flattenSpatial {d channels : ℕ} (spatial : TorchLean.Tensor ℕ [d]) :
                                Layer (fieldShape spatial channels) (flatFieldShape spatial channels)

                                Reshape a spatial field to its matrix view.

                                Instances For
                                  def Runtime.Autograd.Model.Layers.FNO.Internal.restoreSpatial {d channels : ℕ} (spatial : TorchLean.Tensor ℕ [d]) :
                                  Layer (flatFieldShape spatial channels) (fieldShape spatial channels)

                                  Restore a matrix view to its spatial axes.

                                  Instances For
                                    def Runtime.Autograd.Model.Layers.FNO.block {d : ℕ} (spatial modes : TorchLean.Tensor ℕ [d]) (width : ℕ) (activation : Activation.Kind := Activation.Kind.tanh) (spectralRealSeed spectralImagSeed skipWeightSeed : ℕ := 0) (path : F.SpectralPath := F.SpectralPath.automatic) :
                                    Layer (fieldShape spatial width) (fieldShape spatial width)

                                    One multidimensional FNO block.

                                    The first d axes are transformed. A learned channel map is applied at every retained frequency, the discarded frequencies are multiplied by a zero mask, and a pointwise affine skip is added after the inverse transform. The mask removes finite values; it does not suppress NaN or infinity.

                                    Instances For