Expand description
Pure-Rust CPU implementations of common raster element-wise operations.
These are used as CPU fallback kernels when the GPU is unavailable.
All functions operate on &[f32] slices and return owned Vec<f32>.
When the input slices have different lengths the shorter slice determines
how many elements are processed (same semantics as Iterator::zip).
Functionsยง
- abs
- Absolute value:
result[i] = data[i].abs(). - add_
scalar - Scalar addition:
result[i] = data[i] + scalar. - add_
slices - Element-wise addition:
result[i] = a[i] + b[i]. - clamp
- Clamp all elements to
[lo, hi]:result[i] = data[i].clamp(lo, hi). - div_
scalar - Scalar division:
result[i] = data[i] / scalar. - div_
slices - Element-wise division:
result[i] = a[i] / b[i]. - max_
slices - Element-wise maximum:
result[i] = a[i].max(b[i]). - max_
value - Maximum element value. Returns
f32::MINfor empty slices. - mean
- Arithmetic mean of all elements. Returns
0.0for empty slices. - min_
slices - Element-wise minimum:
result[i] = a[i].min(b[i]). - min_
value - Minimum element value. Returns
f32::MAXfor empty slices. - mul_
scalar - Scalar multiplication:
result[i] = data[i] * scalar. - mul_
slices - Element-wise multiplication:
result[i] = a[i] * b[i]. - ndvi
- Normalised Difference Vegetation Index:
(nir - red) / (nir + red). - powf
- Power:
result[i] = data[i].powf(exponent). - sqrt
- Square root:
result[i] = data[i].sqrt(). - std_dev
- Population standard deviation. Returns
0.0for slices with fewer than two elements. - sub_
scalar - Scalar subtraction:
result[i] = data[i] - scalar. - sub_
slices - Element-wise subtraction:
result[i] = a[i] - b[i]. - sum
- Sum of all elements. Returns
0.0for empty slices. - variance
- Population variance of all elements. Returns
0.0for slices with fewer than two elements.