fftw
fftw copied to clipboard
helpers for half-complex
Would you accept a PR for helpers to handle half-complex arrays. I'm thinking for half-complex arrays x, y,
-
x * y
-
mod(x)
orabs(x)
-
arg(x)
(orphase(x)
if preferred)
the signature could be e.g.
/// contents of y are replaced with the result
fn half_complex_mult<X>(x: &[X], y: &mut [X])
where X: f32 or f64 // (either define a trait or 2 functions)
{
assert_eq!(x.len(), y.len());
let n = x.len();
y[0] = y[0] * x[0];
for i in 1..=(n - 1) / 2 {
let xre = x[i];
let yre = y[i];
let xim = x[n - i];
let yim = y[n - i];
y[i] = xre * yre - xim * yim;
y[n - i] = xre * yim + xre * yim;
}
if n % 2 == 0 {
let n2 = n / 2;
y[n2] = y[n2] * x[n2];
}
}
These kinds of routines are fiddly to write and prone to errors. Centralising them improves robustness.