Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

helpers for half-complex #107

Open
derekdreery opened this issue Nov 19, 2020 · 1 comment
Open

helpers for half-complex #107

derekdreery opened this issue Nov 19, 2020 · 1 comment

Comments

@derekdreery
Copy link
Contributor

derekdreery commented Nov 19, 2020

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];
    }
}
@derekdreery
Copy link
Contributor Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant