| 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_simdrust-analyzer cargo fearless_simd 0.4.1 crate/::{Levelrust-analyzer cargo fearless_simd 0.4.1 Level#, dispatchrust-analyzer cargo fearless_simd 0.4.1 macros/dispatch!, preluderust-analyzer cargo fearless_simd 0.4.1 prelude/::*}; |
| 10 | |
| 11 | #[inline(always)] |
| 12 | fn sigmoidrust-analyzer cargo fearless_simd 0.4.1 sigmoid().<S: Simdrust-analyzer cargo fearless_simd 0.4.1 generated/simd_trait/Simd#>(simd: S, x: &[f32], out: &mut [f32]) { |
| 13 | let n = S::f32srust-analyzer cargo fearless_simd 0.4.1 generated/simd_trait/Simd#f32s#::Nrust-analyzer cargo fearless_simd 0.4.1 generated/simd_trait/SimdBase#N.; |
| 14 | for (x, y) in x.chunks_exactrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]chunks_exact().(n).ziprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#zip().(out.chunks_exact_mutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]chunks_exact_mut().(n)) { |
| 15 | let a = S::f32srust-analyzer cargo fearless_simd 0.4.1 generated/simd_trait/Simd#f32s#::from_slicerust-analyzer cargo fearless_simd 0.4.1 generated/simd_trait/SimdBase#from_slice().(simd, x); |
| 16 | let b = a rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Div#div()./rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Div#div(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Div#div().(a rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Mul#mul().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Mul#mul(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Mul#mul().a rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Add#add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Add#add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Add#add().1.0).sqrtrust-analyzer cargo fearless_simd 0.4.1 generated/simd_trait/SimdFloat#sqrt().(); |
| 17 | y.copy_from_slicerust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]copy_from_slice().(b.as_slicerust-analyzer cargo fearless_simd 0.4.1 generated/simd_trait/SimdBase#as_slice().()); |
| 18 | } |
| 19 | } |
| 20 | |
| 21 | fn mainrust-analyzer cargo fearless_simd 0.4.1 main().() { |
| 22 | let level = Levelrust-analyzer cargo fearless_simd 0.4.1 Level#::newrust-analyzer cargo fearless_simd 0.4.1 impl#[Level]new().(); |
| 23 | let inp = [0.1, -rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f32][Neg]neg().0.2, 0.001, 0.4, 1., 2., 3., 4.]; |
| 24 | let mut out = [0.; 8]; |
| 25 | dispatchrust-analyzer cargo fearless_simd 0.4.1 macros/dispatch!!(level, simd => sigmoidrust-analyzer cargo fearless_simd 0.4.1 sigmoid().(simd, &inp, &mut out)); |
| 26 | |
| 27 | printlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/println!!("{out:?}"); |
| 28 | } |