hypot_simd

Function hypot_simd 

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

SIMD-accelerated hypotenuse calculation

Computes element-wise hypotenuse: hypot(x, y) = sqrt(x² + y²) Uses the standard library implementation which handles overflow/underflow correctly.

§Arguments

  • x - First coordinate values
  • y - Second coordinate values

§Returns

Array of hypotenuse values

§Examples

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

let x = array![3.0_f64, 5.0, 8.0];
let y = array![4.0_f64, 12.0, 15.0];

let result = hypot_simd::<f64>(&x.view(), &y.view());
assert!((result[0] - 5.0).abs() < 1e-14);   // 3-4-5 triangle
assert!((result[1] - 13.0).abs() < 1e-14);  // 5-12-13 triangle
assert!((result[2] - 17.0).abs() < 1e-14);  // 8-15-17 triangle

§Use Cases

  • Distance calculations in 2D
  • Computing vector magnitudes
  • Complex number modulus: |a+bi| = hypot(a, b)
  • Graphics and physics simulations