rsqrt_simd

Function rsqrt_simd 

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

SIMD-accelerated inverse square root: 1/sqrt(x)

Computes the reciprocal of the square root for each element. This operation is fundamental in graphics and physics simulations.

§Arguments

  • a - Input values (should be positive)

§Returns

Array of 1/sqrt(x) values

  • Returns INFINITY for x = 0
  • Returns NaN for x < 0

§Examples

use scirs2_core::ndarray::{array, Array1};
use scirs2_core::ndarray_ext::elementwise::rsqrt_simd;

let x = array![1.0_f64, 4.0, 9.0, 16.0];

let result = rsqrt_simd::<f64>(&x.view());
assert!((result[0] - 1.0).abs() < 1e-14);     // 1/sqrt(1) = 1
assert!((result[1] - 0.5).abs() < 1e-14);     // 1/sqrt(4) = 0.5
assert!((result[2] - 1.0/3.0).abs() < 1e-14); // 1/sqrt(9) = 1/3
assert!((result[3] - 0.25).abs() < 1e-14);    // 1/sqrt(16) = 0.25

§Use Cases

  • Vector normalization: v_normalized = v * rsqrt(dot(v, v))
  • Quaternion normalization in 3D graphics
  • Inverse distance weighting
  • Fast approximate physics simulations