helena 0.1.0

Core types and component interfaces for helena, a latent data-to-waveform generation platform.
Documentation
use crate::{Error, Result, Tensor};

/// Map `-0.0` to `+0.0` so equal artifacts serialize identically.
pub(super) fn canonical_zero(x: f32) -> f32 {
    if x == 0.0 { 0.0 } else { x }
}

/// `ca * a + cb * b`, elementwise, requiring matching shapes.
///
/// Returns [`Error::Shape`] (carrying both shape vectors) when the operands
/// disagree, so a `[2, 3]`-vs-`[6]` mismatch is reported by structure, not by
/// an equal element count.
pub(super) fn combine(a: &Tensor, b: &Tensor, ca: f32, cb: f32) -> Result<Tensor> {
    if a.shape() != b.shape() {
        return Err(Error::shape(a.shape().to_vec(), b.shape().to_vec()));
    }
    let data: Vec<f32> = a
        .data()
        .iter()
        .zip(b.data())
        .map(|(&x, &y)| ca * x + cb * y)
        .collect();
    Tensor::new(a.shape().to_vec(), data)
}