Expand description
Element-wise mathematical operations with SIMD acceleration (abs, sqrt, etc.) SIMD-accelerated element-wise mathematical operations
This module provides high-performance implementations of common element-wise mathematical functions that are fundamental for scientific computing, numerical analysis, and data processing.
§Operations
§Basic Operations
- Absolute Value (
abs_simd): Computes |x| for each element - Sign (
sign_simd): Computes sign(x) = +1, 0, or -1 for each element - Square Root (
sqrt_simd): Computes √x for each element
§Exponential and Logarithmic
- Exponential (
exp_simd): Computes e^x for each element - Natural Logarithm (
ln_simd): Computes ln(x) for each element
§Trigonometric Functions
- Sine (
sin_simd): Computes sin(x) for each element - Cosine (
cos_simd): Computes cos(x) for each element - Tangent (
tan_simd): Computes tan(x) for each element
§Hyperbolic Functions
- Hyperbolic Sine (
sinh_simd): Computes sinh(x) for each element - Hyperbolic Cosine (
cosh_simd): Computes cosh(x) for each element - Hyperbolic Tangent (
tanh_simd): Computes tanh(x) for each element
§Power Functions
- Power (scalar) (
powf_simd): Computes base^exp with scalar exponent - Power (array) (
pow_simd): Computesbase[i]^exp[i]element-wise
§Rounding Functions
- Floor (
floor_simd): Rounds down to largest integer <= x - Ceiling (
ceil_simd): Rounds up to smallest integer >= x - Round (
round_simd): Rounds to nearest integer (ties to even) - Fractional Part (
fract_simd): Returns fractional part (x - floor(x))
§Inverse Trigonometric Functions
- Arctangent (
atan_simd): Computes atan(x) for each element - Arcsine (
asin_simd): Computes asin(x) for each element - Arccosine (
acos_simd): Computes acos(x) for each element - Two-argument arctangent (
atan2_simd): Computes atan2(y, x) element-wise
§Logarithm Variants
- Base-10 Logarithm (
log10_simd): Computes log₁₀(x) for each element - Base-2 Logarithm (
log2_simd): Computes log₂(x) for each element
§Clamping Operations
- Clamp (
clamp_simd): Constrains each element to [min, max] range
§Performance
All operations automatically use SIMD acceleration when:
- Platform supports AVX2 (x86_64) or NEON (ARM)
- Array size is large enough to benefit from vectorization
- Array memory layout is contiguous
Falls back to scalar implementations for small arrays or unsupported platforms.
§Examples
use scirs2_core::ndarray::array;
use scirs2_core::ndarray_ext::elementwise::{abs_simd, sign_simd, sqrt_simd, sinh_simd, tanh_simd, floor_simd, atan2_simd, log10_simd, clamp_simd};
// Absolute value
let x = array![-3.0, -1.0, 0.0, 1.0, 3.0];
let abs_x = abs_simd(&x.view());
// Result: [3.0, 1.0, 0.0, 1.0, 3.0]
// Sign function (signum)
let signs = sign_simd(&x.view());
// Result: [-1.0, -1.0, 0.0, 1.0, 1.0]
// Square root
let y = array![1.0, 4.0, 9.0, 16.0, 25.0];
let sqrt_y = sqrt_simd(&y.view());
// Result: [1.0, 2.0, 3.0, 4.0, 5.0]
// Hyperbolic tangent (neural network activation)
let z = array![-1.0, 0.0, 1.0];
let tanh_z = tanh_simd(&z.view());
// Result: [-0.762, 0.0, 0.762]
// Floor (rounding down)
let w = array![1.2, 2.7, -1.3, -2.9];
let floor_w = floor_simd(&w.view());
// Result: [1.0, 2.0, -2.0, -3.0]
// Arctangent 2 (angle from coordinates)
let y_coords = array![1.0, 1.0, -1.0, -1.0];
let x_coords = array![1.0, -1.0, -1.0, 1.0];
let angles = atan2_simd(&y_coords.view(), &x_coords.view());
// Result: [π/4, 3π/4, -3π/4, -π/4]
// Base-10 logarithm (decibels, pH scale)
let powers = array![1.0, 10.0, 100.0, 1000.0];
let log10_powers = log10_simd(&powers.view());
// Result: [0.0, 1.0, 2.0, 3.0]
// Clamp values to range (pixel normalization)
let pixels = array![-0.5, 0.3, 0.7, 1.2, 1.8];
let normalized = clamp_simd(&pixels.view(), 0.0, 1.0);
// Result: [0.0, 0.3, 0.7, 1.0, 1.0]Functions§
- abs_
simd - Compute the absolute value of each element (SIMD-accelerated).
- acos_
simd - Compute the arccosine of each element (SIMD-accelerated).
- acosh_
simd - Apply inverse hyperbolic cosine (acosh) using SIMD operations
- add_
simd - SIMD-accelerated element-wise addition
- argmax_
simd - SIMD-accelerated argmax (index of maximum)
- argmin_
simd - SIMD-accelerated argmin (index of minimum)
- asin_
simd - Compute the arcsine of each element (SIMD-accelerated).
- asinh_
simd - Apply inverse hyperbolic sine (asinh) using SIMD operations
- atan2_
simd - Compute the two-argument arctangent element-wise (SIMD-accelerated).
- atan_
simd - Compute the arctangent of each element (SIMD-accelerated).
- atanh_
simd - Apply inverse hyperbolic tangent (atanh) using SIMD operations
- beta_
simd - Compute the Beta function B(a, b) using SIMD operations
- cbrt_
simd - Compute the cube root of each element (SIMD-accelerated).
- ceil_
simd - Compute the ceiling (round up) of each element (SIMD-accelerated).
- clamp_
simd - Clamp each element to a specified range [min, max] (SIMD-accelerated).
- clip_
simd - SIMD-accelerated element-wise clipping (clamping)
- copysign_
simd - SIMD-accelerated copysign operation
- cos_
simd - Compute the cosine of each element (SIMD-accelerated).
- cosh_
simd - Compute the hyperbolic cosine of each element (SIMD-accelerated).
- cosine_
similarity_ simd - SIMD-accelerated cosine similarity
- cumprod_
simd - SIMD-accelerated cumulative product
- cumsum_
simd - SIMD-accelerated cumulative sum (prefix sum)
- diff_
simd - SIMD-accelerated first-order difference
- digamma_
simd - Computes the element-wise digamma function ψ(x) = d/dx ln(Γ(x)) using SIMD acceleration.
- distance_
chebyshev_ simd - SIMD-accelerated Chebyshev distance
- distance_
cosine_ simd - SIMD-accelerated cosine distance
- distance_
euclidean_ simd - SIMD-accelerated Euclidean distance
- distance_
manhattan_ simd - SIMD-accelerated Manhattan distance
- div_
simd - SIMD-accelerated element-wise division
- dot_
simd - SIMD-accelerated dot product
- elu_
simd - Apply ELU (Exponential Linear Unit) activation using SIMD operations
- erf_
simd - Element-wise error function erf(x) = (2/√π) ∫₀ˣ e^(-t²) dt
- erfc_
simd - Element-wise complementary error function erfc(x) = 1 - erf(x)
- erfcinv_
simd - Element-wise inverse complementary error function erfcinv(y) = x such that erfc(x) = y
- erfinv_
simd - Element-wise inverse error function erfinv(y) = x such that erf(x) = y
- exp2_
simd - Compute 2^x for each element (SIMD-accelerated).
- exp_
m1_ simd - Compute exp(x)-1 for each element (SIMD-accelerated, numerically stable).
- exp_
simd - Compute the exponential (e^x) of each element (SIMD-accelerated).
- expm1_
simd - SIMD-accelerated numerically stable exp(x) - 1
- floor_
simd - Compute the floor (round down) of each element (SIMD-accelerated).
- fma_
simd - SIMD-accelerated fused multiply-add
- fract_
simd - Compute the fractional part of each element (SIMD-accelerated).
- gamma_
simd - Compute the gamma function Γ(x) for each element (SIMD-accelerated).
- gelu_
simd - Compute the element-wise GELU (Gaussian Error Linear Unit) of an array.
- hardsigmoid_
simd - Apply Hardsigmoid activation using SIMD operations
- hardswish_
simd - Apply Hardswish activation using SIMD operations
- hypot_
simd - SIMD-accelerated hypotenuse calculation
- leaky_
relu_ simd - Apply Leaky ReLU / PReLU activation using SIMD operations
- lerp_
simd - SIMD-accelerated linear interpolation
- ln_
1p_ simd - Compute ln(1+x) for each element (SIMD-accelerated, numerically stable).
- ln_
beta_ simd - Compute the Log-Beta function ln(B(a, b)) using SIMD operations
- ln_
gamma_ simd - Computes the element-wise log-gamma function ln(Γ(x)) using SIMD acceleration.
- ln_simd
- Compute the natural logarithm (ln(x)) of each element (SIMD-accelerated).
- log1p_
simd - SIMD-accelerated numerically stable ln(1 + x)
- log2_
simd - Compute the base-2 logarithm of each element (SIMD-accelerated).
- log10_
simd - Compute the base-10 logarithm of each element (SIMD-accelerated).
- log_
softmax_ simd - Apply Log-Softmax function using SIMD operations
- log_
sum_ exp_ simd - SIMD-accelerated log-sum-exp
- logaddexp_
simd - SIMD-accelerated logaddexp: log(exp(a) + exp(b))
- logit_
simd - SIMD-accelerated logit function: log(p / (1-p))
- max_
element_ simd - SIMD-accelerated maximum element
- max_
simd - SIMD-accelerated element-wise maximum
- mean_
simd - SIMD-accelerated array mean
- min_
element_ simd - SIMD-accelerated minimum element
- min_
simd - SIMD-accelerated element-wise minimum
- mish_
simd - SIMD-accelerated Mish activation function
- mul_
simd - SIMD-accelerated element-wise multiplication
- norm_
l1_ simd - SIMD-accelerated L1 norm (Manhattan norm)
- norm_
linf_ simd - SIMD-accelerated L-infinity norm (Chebyshev/max norm)
- norm_
simd - SIMD-accelerated L2 norm (Euclidean norm)
- normalize_
simd - SIMD-accelerated L2 normalization
- pow_
simd - Compute the element-wise power with array exponents (SIMD-accelerated).
- powf_
simd - Compute the power of each element with a scalar exponent (SIMD-accelerated).
- powi_
simd - Compute integer power (base^n) for each element (SIMD-accelerated).
- prelu_
simd - Alias for leaky_relu_simd - PReLU (Parametric ReLU)
- recip_
simd - Compute the reciprocal (multiplicative inverse) of each element (SIMD-accelerated).
- relu_
simd - SIMD-accelerated ReLU (Rectified Linear Unit)
- round_
simd - Compute the rounding to nearest integer of each element (SIMD-accelerated).
- rsqrt_
simd - SIMD-accelerated inverse square root: 1/sqrt(x)
- scalar_
mul_ simd - SIMD-accelerated scalar multiplication
- selu_
simd - Apply SELU (Scaled Exponential Linear Unit) activation using SIMD operations
- sigmoid_
simd - Compute the element-wise sigmoid (logistic) function of an array.
- sign_
simd - Compute the sign (signum) of each element (SIMD-accelerated).
- sin_
simd - Compute the sine of each element (SIMD-accelerated).
- sinc_
simd - Apply Sinc function using SIMD operations
- sincos_
simd - SIMD-accelerated simultaneous sin and cos computation
- sinh_
simd - Compute the hyperbolic sine of each element (SIMD-accelerated).
- smootherstep_
simd - SIMD-accelerated smootherstep interpolation (Ken Perlin’s improved version)
- smoothstep_
simd - SIMD-accelerated smoothstep interpolation
- softmax_
simd - SIMD-accelerated softmax
- softplus_
simd - SIMD-accelerated Softplus activation function
- sqrt_
simd - Compute the square root of each element (SIMD-accelerated).
- square_
simd - SIMD-accelerated element-wise square: x²
- standardize_
simd - SIMD-accelerated standardization (z-score normalization)
- std_
simd - SIMD-accelerated standard deviation computation
- sub_
simd - SIMD-accelerated element-wise subtraction
- sum_
cubes_ simd - SIMD-accelerated sum of cubes
- sum_
simd - SIMD-accelerated array sum
- sum_
squares_ simd - SIMD-accelerated sum of squares
- swish_
simd - SIMD-accelerated Swish (SiLU - Sigmoid Linear Unit) activation function
- tan_
simd - Compute the tangent of each element (SIMD-accelerated).
- tanh_
simd - Compute the hyperbolic tangent of each element (SIMD-accelerated).
- to_
degrees_ simd - Convert radians to degrees for each element (SIMD-accelerated).
- to_
radians_ simd - Convert degrees to radians for each element (SIMD-accelerated).
- trigamma_
simd - Computes the element-wise trigamma function ψ’(x) = d²/dx² ln(Γ(x)) using SIMD acceleration.
- trunc_
simd - SIMD-accelerated truncation (round towards zero)
- variance_
simd - SIMD-accelerated variance computation
- weighted_
mean_ simd - SIMD-accelerated weighted mean
- weighted_
sum_ simd - SIMD-accelerated weighted sum