vyre 0.4.0

GPU compute intermediate representation with a standard operation library
Documentation


//! WGSL lowering source for `stats.arithmetic_mean`.

/// Dispatchable WGSL kernel for arithmetic mean over packed byte input.
pub const WGSL: &str = concat!(
    include_str!("../wgsl_byte_primitives/bytes.wgsl"),
    "\n",
    include_str!("wgsl/arithmetic_mean.wgsl"),
);

/// Compute the population arithmetic mean of byte values.
///
/// Empty input returns `0.0`.
#[must_use]
pub fn arithmetic_mean(input: &[u8]) -> f32 {
    if input.is_empty() {
        return 0.0;
    }
    let sum: u64 = input.iter().map(|&byte| u64::from(byte)).sum();
    sum as f32 / input.len() as f32
}

/// Compute the mean and return its IEEE-754 binary32 bit pattern.
#[must_use]
pub fn arithmetic_mean_bits(input: &[u8]) -> u32 {
    arithmetic_mean(input).to_bits()
}