pub trait MeanAcc: Element + Copy {
type Mean: Element + Copy + Add<Output = Self::Mean> + Div<Output = Self::Mean>;
// Required methods
fn widen_mean(self) -> Self::Mean;
fn count(n: usize) -> Self::Mean;
}Expand description
Maps an element type T to the type NumPy uses to accumulate (and
return) mean over it.
NumPy casts a bool / unsigned-int / signed-int input to float64 before
averaging:
“Cast bool, unsigned int, and int to float64 by default …
dtype = mu.dtype('f8')” —numpy/_core/_methods.py:124-127
so np.mean(np.array([1, 2, 3], np.int32)) is float64 2.0 and
np.mean([True, False, True]) is float64 0.6666…. Floating-point inputs
keep their own dtype (f32→f32, f64→f64), and complex stays itself.
The mapping:
bool / i8.. / u8.. → f64f32 → f32,f64 → f64(unchanged —Mean == Self)Complex<f32> → Complex<f32>,Complex<f64> → Complex<f64>
Required Associated Types§
Required Methods§
Sourcefn widen_mean(self) -> Self::Mean
fn widen_mean(self) -> Self::Mean
Widen one element into the mean accumulator type, matching NumPy’s
pre-average cast (true → 1.0, false → 0.0 for bool).
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".