Skip to main content

DiffFftPlan

Struct DiffFftPlan 

Source
pub struct DiffFftPlan<T: Float> { /* private fields */ }
Expand description

Differentiable FFT plan for automatic differentiation.

Wraps a standard FFT plan and provides differentiation capabilities.

Implementations§

Source§

impl<T: Float> DiffFftPlan<T>

Source

pub fn new(size: usize) -> Option<Self>

Create a new differentiable FFT plan.

Source

pub fn forward(&self, input: &[Complex<T>], output: &mut [Complex<T>])

Execute forward FFT.

Source

pub fn inverse(&self, input: &[Complex<T>], output: &mut [Complex<T>])

Execute inverse FFT (normalized).

Source

pub fn forward_dual( &self, input: &[DualComplex<T>], ) -> (Vec<Complex<T>>, Vec<Complex<T>>)

Compute forward FFT with its Jacobian-vector product (forward mode AD).

Given input x and tangent dx, computes:

  • y = FFT(x)
  • dy = FFT(dx) (the directional derivative)
Source

pub fn backward(&self, grad_output: &[Complex<T>]) -> Vec<Complex<T>>

Compute gradient of a scalar loss with respect to FFT input (backward mode AD).

Given the gradient of loss w.r.t. FFT output (grad_output), computes the gradient w.r.t. FFT input.

For FFT: y = F·x where F is the DFT matrix F[k,n] = exp(-2πi·k·n/N) The adjoint F^H satisfies: <v, F·x> = <F^H·v, x> F^H = conj(F^T) = IFFT_unnormalized = N · IFFT Gradient: ∂L/∂x = F^H · ∂L/∂y = conj(FFT(conj(∂L/∂y)))

Source

pub fn backward_inverse(&self, grad_output: &[Complex<T>]) -> Vec<Complex<T>>

Compute gradient of a scalar loss with respect to IFFT input.

For normalized IFFT: y = (1/N)·Fᴴ·x The adjoint of (1/N)·Fᴴ is (1/N)·F Gradient: ∂L/∂x = (1/N)·F · ∂L/∂y = (1/N)·FFT(∂L/∂y)

Source

pub fn size(&self) -> usize

Get the transform size.

Auto Trait Implementations§

§

impl<T> Freeze for DiffFftPlan<T>

§

impl<T> RefUnwindSafe for DiffFftPlan<T>
where T: RefUnwindSafe,

§

impl<T> Send for DiffFftPlan<T>

§

impl<T> Sync for DiffFftPlan<T>

§

impl<T> Unpin for DiffFftPlan<T>

§

impl<T> UnwindSafe for DiffFftPlan<T>
where T: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.