fftw icon indicating copy to clipboard operation
fftw copied to clipboard

helpers for half-complex

Open richard-uk1 opened this issue 4 years ago • 1 comments

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) or abs(x)
  • arg(x) (or phase(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];
    }
}

richard-uk1 avatar Nov 19 '20 18:11 richard-uk1

These kinds of routines are fiddly to write and prone to errors. Centralising them improves robustness.

richard-uk1 avatar Nov 19 '20 18:11 richard-uk1