Class Fft

java.lang.Object
ai.beestream.jitnn.Fft

public final class Fft extends Object
Fourier transforms after torch.fft, and the short-time transforms torch.stft and torch.istft. Complex tensors are real tensors with a trailing axis of 2 (re, im), as torch.view_as_real gives them; dim counts the complex axes only. All transforms are differentiable.

The transforms are direct sums, O(n^2) per row (see FftKernels): right for the lengths found in models (window sizes, sequence mixing), not for very long signals.

  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static enum 
    Scaling, torch's norm: BACKWARD scales the inverse by 1/n, ORTHO both by 1/sqrt(n), FORWARD the forward by 1/n.
  • Method Summary

    Modifier and Type
    Method
    Description
    static Tensor
    torch.fft.fft of complex x along the last axis, full length, BACKWARD scaling.
    static Tensor
    fft(Tensor x, int n, int dim, Fft.Norm norm)
    torch.fft.fft of complex x [..., 2]; n > 0 crops or zero-pads axis dim to n.
    static Tensor
    torch.fft.fft2: the transform over the last two complex axes.
    static Tensor
    torch.fft.ifft of complex x along the last axis, full length, BACKWARD scaling (1/n).
    static Tensor
    ifft(Tensor x, int n, int dim, Fft.Norm norm)
    torch.fft.ifft.
    static Tensor
    torch.fft.ifft2.
    static Tensor
    torch.fft.irfft along the last axis: a real signal of length 2 (m - 1), BACKWARD scaling (1/n).
    static Tensor
    irfft(Tensor x, int n, int dim, Fft.Norm norm)
    torch.fft.irfft: the real signal of length n (default 2 (m - 1)) whose spectrum's non-negative half is x [..., m, 2]; the imaginary parts at frequency 0 and n / 2 are ignored.
    static Tensor
    istft(Tensor x, int nFft, int hop, Tensor window, boolean center, boolean normalized, int length)
    torch.istft(x, nFft, hop, window=window, center, normalized, onesided=True, length): x [(B,) nFft / 2 + 1, frames, 2] back to [(B,) length] (length <= 0: as long as the frames reach, less the centre padding), by overlap-add divided by the summed squared window.
    static Tensor
    torch.fft.rfft of real x along the last axis, full length, BACKWARD scaling.
    static Tensor
    rfft(Tensor x, int n, int dim, Fft.Norm norm)
    torch.fft.rfft of real x: the n / 2 + 1 non-negative frequencies, complex [..., n / 2 + 1, 2].
    static Tensor
    torch.fft.rfft2: rfft over the last axis, then fft over the one before.
    static Tensor
    stft(Tensor x, int nFft, int hop, Tensor window, boolean center, boolean normalized)
    torch.stft(x, nFft, hop, window=window, center, pad_mode="reflect", normalized, onesided=True, return_complex=True) as real pairs: x [L] or [B, L] gives [(B,) nFft / 2 + 1, frames, 2].

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • fft

      public static Tensor fft(Tensor x, int n, int dim, Fft.Norm norm)
      torch.fft.fft of complex x [..., 2]; n > 0 crops or zero-pads axis dim to n.
    • fft

      public static Tensor fft(Tensor x)
      torch.fft.fft of complex x along the last axis, full length, BACKWARD scaling.
    • ifft

      public static Tensor ifft(Tensor x, int n, int dim, Fft.Norm norm)
      torch.fft.ifft.
    • ifft

      public static Tensor ifft(Tensor x)
      torch.fft.ifft of complex x along the last axis, full length, BACKWARD scaling (1/n).
    • rfft

      public static Tensor rfft(Tensor x, int n, int dim, Fft.Norm norm)
      torch.fft.rfft of real x: the n / 2 + 1 non-negative frequencies, complex [..., n / 2 + 1, 2].
    • rfft

      public static Tensor rfft(Tensor x)
      torch.fft.rfft of real x along the last axis, full length, BACKWARD scaling.
    • irfft

      public static Tensor irfft(Tensor x, int n, int dim, Fft.Norm norm)
      torch.fft.irfft: the real signal of length n (default 2 (m - 1)) whose spectrum's non-negative half is x [..., m, 2]; the imaginary parts at frequency 0 and n / 2 are ignored.
    • irfft

      public static Tensor irfft(Tensor x)
      torch.fft.irfft along the last axis: a real signal of length 2 (m - 1), BACKWARD scaling (1/n).
    • fft2

      public static Tensor fft2(Tensor x)
      torch.fft.fft2: the transform over the last two complex axes.
    • ifft2

      public static Tensor ifft2(Tensor x)
      torch.fft.ifft2.
    • rfft2

      public static Tensor rfft2(Tensor x)
      torch.fft.rfft2: rfft over the last axis, then fft over the one before.
    • stft

      public static Tensor stft(Tensor x, int nFft, int hop, Tensor window, boolean center, boolean normalized)
      torch.stft(x, nFft, hop, window=window, center, pad_mode="reflect", normalized, onesided=True, return_complex=True) as real pairs: x [L] or [B, L] gives [(B,) nFft / 2 + 1, frames, 2]. The window has nFft entries (null for a rectangular one).
    • istft

      public static Tensor istft(Tensor x, int nFft, int hop, Tensor window, boolean center, boolean normalized, int length)
      torch.istft(x, nFft, hop, window=window, center, normalized, onesided=True, length): x [(B,) nFft / 2 + 1, frames, 2] back to [(B,) length] (length <= 0: as long as the frames reach, less the centre padding), by overlap-add divided by the summed squared window.