Skip to main content

R2rSolver

Struct R2rSolver 

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

Real-to-Real transform solver.

Implementations§

Source§

impl<T: Float> R2rSolver<T>

Source

pub fn new(kind: R2rKind) -> Self

Create a new R2R solver with specified kind.

Source

pub fn name(&self) -> &'static str

Get the solver name.

Source

pub fn applicable(&self, n: usize) -> bool

Check if this solver is applicable for the given size.

Source

pub fn execute_dct2_direct(&self, input: &[T], output: &mut [T])

Execute DCT-II (REDFT10) using direct O(n²) computation.

Formula: X[k] = sum_{n=0}^{N-1} x[n] * cos(π * (2n + 1) * k / (2N))

Source

pub fn execute_dct2_fast(&self, input: &[T], output: &mut [T])

Execute DCT-II using FFT-based O(n log n) algorithm.

Algorithm (2N-point FFT, even reflection): v[i] = x[i] for i = 0..N-1 v[i] = x[2N-1-i] for i = N..2N-1 Y = FFT_{2N}(v) DCT_II[k] = (c_k * Y[k].re - s_k * Y[k].im) / 2 where c_k = cos(-πk/(2N)), s_k = sin(-πk/(2N))

Source

pub fn execute_dct2(&self, input: &[T], output: &mut [T])

Execute DCT-II transform (dispatches to fast for n >= 16, direct otherwise).

Source

pub fn execute_dct3_direct(&self, input: &[T], output: &mut [T])

Execute DCT-III (REDFT01) using direct O(n²) computation.

Formula: x[n] = X[0]/2 + sum_{k=1}^{N-1} X[k] * cos(π * k * (2n + 1) / (2N))

Source

pub fn execute_dct3_fast(&self, input: &[T], output: &mut [T])

Execute DCT-III using FFT-based O(n log n) algorithm.

DCT-III is the transpose/inverse of DCT-II. We use the conj-FFT-conj trick: IFFT_{2N}(Z) = conj(FFT_{2N}(conj(Z))) / (2N)

Build Z of length 2N: Z[0] = 2X[0], Z[N] = 0 Z[k] = 2X[k]exp(iπ*k/(2N)) for k = 1..N-1 Z[2N-k] = conj(Z[k]) for k = 1..N-1

Then DCT_III[n] = Re(IFFT_{2N}(Z)[n]) = Re(conj(FFT_{2N}(conj(Z)))[n]) / (2N)

Source

pub fn execute_dct3(&self, input: &[T], output: &mut [T])

Execute DCT-III transform (dispatches to fast for n >= 16, direct otherwise).

Source

pub fn execute_dct1_direct(&self, input: &[T], output: &mut [T])

Execute DCT-I (REDFT00) using direct O(n²) computation.

Formula: X[k] = x[0] + (-1)^k * x[N-1] + 2 * sum_{n=1}^{N-2} x[n] * cos(π * n * k / (N-1))

Source

pub fn execute_dct1_fast(&self, input: &[T], output: &mut [T])

Execute DCT-I using FFT-based O(n log n) algorithm.

Even extension of length 2(N-1): v[i] = x[i] for i = 0..N-1 v[i] = x[2(N-1)-i] for i = N..2(N-1)-1

DCT_I[k] = Re(FFT_{2(N-1)}(v))[k]

Source

pub fn execute_dct1(&self, input: &[T], output: &mut [T])

Execute DCT-I transform (dispatches to fast for n >= 16, direct otherwise).

Source

pub fn execute_dct4_direct(&self, input: &[T], output: &mut [T])

Execute DCT-IV (REDFT11) using direct O(n²) computation.

Formula: X[k] = sum_{n=0}^{N-1} x[n] * cos(π * (2n + 1) * (2k + 1) / (4N))

Source

pub fn execute_dct4_fast(&self, input: &[T], output: &mut [T])

Execute DCT-IV using FFT-based O(n log n) algorithm.

Algorithm using 4N-point FFT: Pad x to length 4N (zeros for indices N..4N-1) Y = FFT_{4N}(x_padded) DCT_IV[k] = Re(exp(-iπ(2k+1)/(4N)) * Y[2k+1])

Derivation: DCT_IV[k] = Re(sum_n x[n]exp(iπ*(2n+1)(2k+1)/(4N))) = Re(exp(-iπ*(2k+1)/(4N)) * sum_n x[n]exp(-2πin*(2k+1)/(4N))) = Re(exp(-iπ(2k+1)/(4N)) * FFT_{4N}(x_padded)[2k+1])

Source

pub fn execute_dct4(&self, input: &[T], output: &mut [T])

Execute DCT-IV transform (dispatches to fast for n >= 16, direct otherwise).

Source

pub fn execute_dst1_direct(&self, input: &[T], output: &mut [T])

Execute DST-I (RODFT00) transform.

Formula: X[k] = sum_{n=0}^{N-1} x[n] * sin(π * (n+1) * (k+1) / (N+1))

Note: DST-I is always computed directly (no FFT fast path for all sizes). For n >= 16, we use an odd-extension FFT approach.

Source

pub fn execute_dst1_fast(&self, input: &[T], output: &mut [T])

Execute DST-I using FFT-based O(n log n) algorithm.

DST-I of length N via 2(N+1)-point odd extension: Build v of length 2(N+1): v[0] = 0, v[n+1] = x[n] for n=0..N-1, v[N+1] = 0, v[N+2+n] = -x[N-1-n] for n=0..N-1 Y = FFT_{2(N+1)}(v) DST_I[k] = -Im(Y[k+1]) for k=0..N-1

Source

pub fn execute_dst1(&self, input: &[T], output: &mut [T])

Execute DST-I transform (dispatches to fast for n >= 16, direct otherwise).

Source

pub fn execute_dst2_direct(&self, input: &[T], output: &mut [T])

Execute DST-II (RODFT10) using direct O(n²) computation.

Formula: X[k] = sum_{n=0}^{N-1} x[n] * sin(π * (2n+1) * (k+1) / (2N))

Source

pub fn execute_dst2_fast(&self, input: &[T], output: &mut [T])

Execute DST-II using FFT-based O(n log n) algorithm.

Relationship: DST_II(x)[k] = DCT_II(y)[N-1-k] where y[n] = (-1)^n * x[n] (sign-alternate input)

Source

pub fn execute_dst2(&self, input: &[T], output: &mut [T])

Execute DST-II transform (dispatches to fast for n >= 16, direct otherwise).

Source

pub fn execute_dst3_direct(&self, input: &[T], output: &mut [T])

Execute DST-III (RODFT01) using direct O(n²) computation.

Formula: X[k] = (-1)^k * x[N-1]/2 + sum_{n=0}^{N-2} x[n] * sin(π * (n+1) * (2k+1) / (2N))

Source

pub fn execute_dst3_fast(&self, input: &[T], output: &mut [T])

Execute DST-III using FFT-based O(n log n) algorithm.

Relationship: DST_III(f)[n] = (-1)^n * DCT_III(f_reversed)[n] where f_reversed[k] = f[N-1-k]

Source

pub fn execute_dst3(&self, input: &[T], output: &mut [T])

Execute DST-III transform (dispatches to fast for n >= 16, direct otherwise).

Source

pub fn execute_dst4_direct(&self, input: &[T], output: &mut [T])

Execute DST-IV (RODFT11) using direct O(n²) computation.

Formula: X[k] = sum_{n=0}^{N-1} x[n] * sin(π * (2n+1) * (2k+1) / (4N))

Source

pub fn execute_dst4_fast(&self, input: &[T], output: &mut [T])

Execute DST-IV using FFT-based O(n log n) algorithm.

Relationship: DST_IV(x)[k] = (-1)^k * DCT_IV(x_reversed)[k] where x_reversed[n] = x[N-1-n]

Source

pub fn execute_dst4(&self, input: &[T], output: &mut [T])

Execute DST-IV transform (dispatches to fast for n >= 16, direct otherwise).

Source

pub fn execute_dht_direct(&self, input: &[T], output: &mut [T])

Execute Discrete Hartley Transform (DHT) using direct O(n²) computation.

Formula: H[k] = sum_{n=0}^{N-1} x[n] * cas(2πnk/N)

where cas(θ) = cos(θ) + sin(θ)

Source

pub fn execute_dht_fast(&self, input: &[T], output: &mut [T])

Execute DHT using FFT-based O(n log n) algorithm.

For real input x: Y = FFT(x) (complex FFT with zero imaginary parts) DHT[k] = Y[k].re - Y[k].im

This works because the DFT with negative exponential gives: Y[k] = sum x[n] * exp(-2πink/N) = sum x[n] * (cos - i*sin)(2πnk/N) Y[k].re - Y[k].im = sum x[n] * (cos + sin)(2πnk/N) = DHT[k]

Source

pub fn execute_dht(&self, input: &[T], output: &mut [T])

Execute Discrete Hartley Transform (dispatches to fast for n >= 16, direct otherwise).

The DHT is its own inverse (up to scaling by N), making it particularly elegant for real-valued signals.

Source

pub fn execute(&self, input: &[T], output: &mut [T])

Execute the transform based on the configured kind.

Trait Implementations§

Source§

impl<T: Float> Default for R2rSolver<T>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl<T> Freeze for R2rSolver<T>

§

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

§

impl<T> Send for R2rSolver<T>

§

impl<T> Sync for R2rSolver<T>

§

impl<T> Unpin for R2rSolver<T>
where T: Unpin,

§

impl<T> UnsafeUnpin for R2rSolver<T>

§

impl<T> UnwindSafe for R2rSolver<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.