| 1 | // Copyright 2024 the Fearless_SIMD Authors |
| 2 | // SPDX-License-Identifier: Apache-2.0 OR MIT |
| 3 | |
| 4 | #![expect( |
| 5 | missing_docs, |
| 6 | reason = "TODO: https://github.com/linebender/fearless_simd/issues/40" |
| 7 | )] |
| 8 | |
| 9 | use fearless_simd::{Level, dispatch, prelude::*}; |
| 10 | |
| 11 | #[inline(always)] |
| 12 | fn sigmoid<S: Simd>(simd: S, x: &[f32], out: &mut [f32]) { |
| 13 | let n = S::f32s::N; |
| 14 | for (x, y) in x.chunks_exact(n).zip(out.chunks_exact_mut(n)) { |
| 15 | let a = S::f32s::from_slice(simd, x); |
| 16 | let b = a / (a * a + 1.0).sqrt(); |
| 17 | y.copy_from_slice(b.as_slice()); |
| 18 | } |
| 19 | } |
| 20 | |
| 21 | fn main() { |
| 22 | let level = Level::new(); |
| 23 | let inp = [0.1, -0.2, 0.001, 0.4, 1., 2., 3., 4.]; |
| 24 | let mut out = [0.; 8]; |
| 25 | dispatch!(level, simd => sigmoid(simd, &inp, &mut out)); |
| 26 | |
| 27 | println!("{out:?}"); |
| 28 | } |