native_neural_network 0.1.6

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

pub fn apply_rope_in_place(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 = rope_angle(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(())
}