hardsigmoid_simd

Function hardsigmoid_simd 

Source
pub fn hardsigmoid_simd<F>(x: &ArrayView1<'_, F>) -> Array1<F>
where F: Float + SimdUnifiedOps,
Expand description

Apply Hardsigmoid activation using SIMD operations

Hardsigmoid is defined as:

  • f(x) = 0, if x <= -3
  • f(x) = 1, if x >= 3
  • f(x) = (x + 3) / 6, otherwise

Hardsigmoid is a piecewise linear approximation of sigmoid:

  • Used in MobileNetV3 for efficient mobile inference
  • Avoids expensive exp() computation
  • Output always in range [0, 1]

§Arguments

  • x - Input array

§Returns

  • Array with Hardsigmoid applied elementwise

§Example

use scirs2_core::ndarray_ext::elementwise::hardsigmoid_simd;
use ndarray::{array, ArrayView1};

let x = array![-4.0_f32, -3.0, 0.0, 3.0, 4.0];
let result = hardsigmoid_simd(&x.view());
assert!((result[0] - 0.0).abs() < 1e-6);   // Saturated at 0
assert!((result[1] - 0.0).abs() < 1e-6);   // Boundary
assert!((result[2] - 0.5).abs() < 1e-6);   // Linear region: (0+3)/6 = 0.5
assert!((result[3] - 1.0).abs() < 1e-6);   // Boundary
assert!((result[4] - 1.0).abs() < 1e-6);   // Saturated at 1