use fearless_simd::{Level, dispatch, prelude::*};
#[inline(always)] fn sigmoid<S: Simd>(simd: S, x: &[f32], out: &mut [f32]) {
let n = S::f32s::LEN;
for (x, y) in x.chunks_exact(n).zip(out.chunks_exact_mut(n)) {
let a = S::f32s::from_slice(simd, x);
let b = a / (a * a + 1.0).sqrt();
b.store_slice(y);
}
let x_remainder = x.chunks_exact(n).remainder();
let y_remainder = out.chunks_exact_mut(n).into_remainder();
for (a, b) in x_remainder.iter().zip(y_remainder) {
*b = a / (a * a + 1.0).sqrt();
}
}
fn main() {
let level = Level::new();
let inp = [
0.1, -0.2, 0.001, 0.4, 1., 2., 3., 4., 5., 6., 7., 8., 9., 10., 11., 12., 13., 14.,
];
let mut out = [0.; 18];
dispatch!(level, simd => sigmoid(simd, &inp, &mut out));
println!("{out:?}");
}