pub fn ln_simd<F>(x: &ArrayView1<'_, F>) -> Array1<F>where
F: Float + SimdUnifiedOps,Expand description
Compute the natural logarithm (ln(x)) of each element (SIMD-accelerated).
Computes ln(x) for each element in the array.
§Arguments
x- Input 1D array (must contain positive values)
§Returns
Array1<F> with the same length as input, with natural logarithm values.
§Performance
- Auto-vectorization: Compiler optimizations provide excellent performance
- Speedup: 2-4x on large arrays via auto-vectorization
§Mathematical Definition
ln(x) = log_e(x) = y such that e^y = x§Examples
use scirs2_core::ndarray::array;
use scirs2_core::ndarray_ext::elementwise::ln_simd;
let x = array![1.0_f64, 2.718281828, 7.389056099];
let result = ln_simd(&x.view());
assert!((result[0] - 0.0).abs() < 1e-10);
assert!((result[1] - 1.0).abs() < 1e-9);
assert!((result[2] - 2.0).abs() < 1e-9);§Edge Cases
- Empty array: Returns empty array
- One: ln(1) = 0
- Zero: Returns negative infinity
- Negative numbers: Returns NaN (undefined in reals)
- NaN: Returns NaN (preserves NaN)
- Positive infinity: Returns positive infinity
§Applications
- Machine Learning: Log-likelihood, cross-entropy loss
- Statistics: Log-normal distribution, Shannon entropy
- Optimization: Log-barrier methods, logarithmic objectives
- Automatic Differentiation: Logarithmic derivatives
- Information Theory: Mutual information, KL divergence
§Note on Negative Values
Natural logarithm of negative numbers is undefined in real arithmetic. The function will return NaN for negative inputs, following IEEE 754 standard.
use scirs2_core::ndarray::array;
use scirs2_core::ndarray_ext::elementwise::ln_simd;
let x = array![-1.0_f64];
let result = ln_simd(&x.view());
assert!(result[0].is_nan());