Skip to main content

MeanAcc

Trait MeanAcc 

Source
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 (f32f32, f64f64), and complex stays itself.

The mapping:

  • bool / i8.. / u8.. → f64
  • f32 → f32, f64 → f64 (unchanged — Mean == Self)
  • Complex<f32> → Complex<f32>, Complex<f64> → Complex<f64>

Required Associated Types§

Source

type Mean: Element + Copy + Add<Output = Self::Mean> + Div<Output = Self::Mean>

The accumulator-and-result element type for mean over Self.

Required Methods§

Source

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).

Source

fn count(n: usize) -> Self::Mean

Construct the divisor (element count n) in the accumulator type.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementations on Foreign Types§

Source§

impl MeanAcc for Complex<f32>

Source§

type Mean = Complex<f32>

Source§

fn widen_mean(self) -> Self

Source§

fn count(n: usize) -> Self

Source§

impl MeanAcc for Complex<f64>

Source§

type Mean = Complex<f64>

Source§

fn widen_mean(self) -> Self

Source§

fn count(n: usize) -> Self

Source§

impl MeanAcc for bool

Source§

impl MeanAcc for f32

Source§

impl MeanAcc for f64

Source§

impl MeanAcc for i8

Source§

impl MeanAcc for i16

Source§

impl MeanAcc for i32

Source§

impl MeanAcc for i64

Source§

impl MeanAcc for i128

Source§

impl MeanAcc for u8

Source§

impl MeanAcc for u16

Source§

impl MeanAcc for u32

Source§

impl MeanAcc for u64

Source§

impl MeanAcc for u128

Implementors§