Skip to main content

Module cpu

Module cpu 

Source
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::MIN for empty slices.
mean
Arithmetic mean of all elements. Returns 0.0 for empty slices.
min_slices
Element-wise minimum: result[i] = a[i].min(b[i]).
min_value
Minimum element value. Returns f32::MAX for 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.0 for 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.0 for empty slices.
variance
Population variance of all elements. Returns 0.0 for slices with fewer than two elements.