pow_simd

Function pow_simd 

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

Compute the element-wise power with array exponents (SIMD-accelerated).

Computes base[i]^exp[i] for each pair of elements.

§Arguments

  • base - Input 1D array of base values
  • exp - Input 1D array of exponent values (must match base length)

§Returns

Array1<F> with the same length as inputs, with power values.

§Performance

  • Auto-vectorization: Compiler optimizations provide excellent performance
  • Speedup: 2-4x on large arrays via auto-vectorization

§Mathematical Definition

pow(base, exp)[i] = base[i]^exp[i]

§Examples

use scirs2_core::ndarray::array;
use scirs2_core::ndarray_ext::elementwise::pow_simd;

let base = array![2.0_f64, 3.0, 4.0, 5.0];
let exp = array![2.0, 3.0, 2.0, 1.0];
let result = pow_simd(&base.view(), &exp.view());

// [4.0, 27.0, 16.0, 5.0]

§Edge Cases

  • Empty arrays: Returns empty array
  • Mismatched lengths: Panics (arrays must have same length)
  • x^0: Returns 1 for any x
  • 0^0: Returns 1 by convention
  • 0^negative: Returns infinity
  • negative^non-integer: Returns NaN
  • NaN: Returns NaN (preserves NaN)

§Applications

  • Machine Learning: Custom activation functions, attention mechanisms
  • Statistics: Generalized power transformations
  • Optimization: Power-law scaling, Pareto distributions
  • Signal Processing: Non-linear transformations, compression
  • Physics: Variable exponent models, fractal dimensions