native_neural_network 0.3.1

Lib no_std Rust for native neural network (.rnn)
Documentation
use super::errors::RopeError;

pub fn apply_rope_in_place_f32(
    x: &mut [f32],
    position: usize,
    theta: f32,
) -> Result<(), RopeError> {
    if x.is_empty() || !x.len().is_multiple_of(2) || !theta.is_finite() || theta <= 0.0 {
        return Err(RopeError::InvalidShape);
    }

    for i in (0..x.len()).step_by(2) {
        let pair_idx = i / 2;
        let angle = crate::rope::frequencies::rope_angle_f32(position, pair_idx, x.len(), theta);
        let c = crate::math::cosf(angle);
        let s = crate::math::sinf(angle);

        let a = x[i];
        let b = x[i + 1];
        x[i] = a * c - b * s;
        x[i + 1] = a * s + b * c;
    }

    Ok(())
}

pub fn apply_rope_in_place_f64(
    x: &mut [f64],
    position: usize,
    theta: f64,
) -> Result<(), RopeError> {
    if x.is_empty() || !x.len().is_multiple_of(2) || !theta.is_finite() || theta <= 0.0 {
        return Err(RopeError::InvalidShape);
    }

    for i in (0..x.len()).step_by(2) {
        let pair_idx = i / 2;
        let angle = crate::rope::frequencies::rope_angle_f64(position, pair_idx, x.len(), theta);
        let c = crate::math::cosd(angle);
        let s = crate::math::sind(angle);

        let a = x[i];
        let b = x[i + 1];
        x[i] = a * c - b * s;
        x[i + 1] = a * s + b * c;
    }

    Ok(())
}