pub trait ReduceAcc: Element + Copy {
type Acc: Element + Copy + Add<Output = Self::Acc> + Mul<Output = Self::Acc>;
// Required method
fn widen(self) -> Self::Acc;
}Expand description
Maps an element type T to the type NumPy uses to accumulate (and
return) sum / prod / cumsum / cumprod over it.
NumPy promotes any integer dtype of less precision than the default platform integer before reducing, so a narrow-int reduction can never overflow and the result dtype is the platform integer:
“The dtype of
ais used by default unlessahas an integer dtype of less precision than the default platform integer. In that case, ifais signed then the platform integer is used while ifais unsigned then an unsigned integer of the same precision as the platform integer is used.” —numpy/_core/fromnumeric.py:2321-2327(sum),:3306-3312(prod)
The reduction itself is umr_sum = um.add.reduce /
umr_prod = um.multiply.reduce (numpy/_core/_methods.py:20-21), i.e. the
add/multiply ufunc whose loop dtype is the promoted accumulator.
The mapping (platform integer = 64-bit, matching ferray’s intp/int64):
i8 / i16 / i32 → i64,i64 → i64,i128 → i128u8 / u16 / u32 → u64,u64 → u64,u128 → u128bool → i64(NumPy reduces bool as the platform integer, countingtrue)f32 → f32,f64 → f64, complex stays itself (no promotion)
Wider-or-equal dtypes map to themselves, so existing f64/i64/complex
reductions are unchanged — only narrow-int callers observe the promoted
return type.
Required Associated Types§
Required Methods§
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".