pub trait SumFromStorage: Sized {
// Required method
fn sum_from_storage(storage: &Storage) -> Self;
}Expand description
Types that can be computed as the result of a reduction over Storage.
This lets callers write let s: T = tensor.sum(); without matching on
the storage variant. Implemented for f64, Complex64, f32, and
Complex32; every reduction widens compact payload values to the requested
accumulator, so a narrow payload can be summed without changing its stored
dtype.
§Examples
use tensor4all_tensorbackend::{Storage, SumFromStorage};
let s = Storage::from_dense_col_major(vec![1.0_f64, 2.0, 3.0], &[3]).unwrap();
let total: f64 = f64::sum_from_storage(&s);
assert!((total - 6.0).abs() < 1e-10);
let narrow = Storage::from_dense_col_major(vec![1.0_f32, 2.0], &[2]).unwrap();
assert_eq!(f32::sum_from_storage(&narrow), 3.0_f32);
assert_eq!(f64::sum_from_storage(&narrow), 3.0_f64);Required Methods§
Sourcefn sum_from_storage(storage: &Storage) -> Self
fn sum_from_storage(storage: &Storage) -> Self
Compute the sum of all elements in the storage.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".