polars_ops/chunked_array/
sum.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
use arrow::types::NativeType;
use polars_core::export::num::{NumCast, ToPrimitive};

pub(super) fn sum_slice<T, S>(values: &[T]) -> S
where
    T: NativeType + ToPrimitive,
    S: NumCast + std::iter::Sum,
{
    values
        .iter()
        .copied()
        .map(|t| unsafe {
            let s: S = NumCast::from(t).unwrap_unchecked();
            s
        })
        .sum()
}