pub fn scalar_fold<T, Op>(
op: &'static str,
source: &TypedTensor<T, DynRank, Host>,
init: T,
) -> Result<T, Error>Expand description
Ordinary CPU entry points that take a caller-provided destination and the
caller’s own arithmetic instead of the typed pool.
Fold every element of a caller-owned tensor with a named associative
operation, starting from init.
The accumulation order is the backend’s and is not part of the contract. The arithmetic is the caller’s, so an extended-precision scalar keeps its low components exactly as a preset scalar keeps its own.
§Examples
use tenferro_internal_cpu_kernels::scalar_ops::{scalar_fold, AddOp};
use tenferro_tensor::{DynRank, Host, TypedTensor};
let values = TypedTensor::<_, DynRank, Host>::from_host_vec_col_major(vec![3], vec![1.0_f64, 2.0, 3.0])?;
let total = scalar_fold::<f64, AddOp>("sum", &values, 0.0_f64)?;
assert_eq!(total, 6.0);§Errors
Returns [Error::BackendSource] when the strided reduction rejects the view, which
happens when the source’s shape has an invalid stride layout.