vortex_array/arrays/bool/compute/
sum.rs1use std::ops::BitAnd;
5
6use vortex_error::VortexResult;
7use vortex_mask::AllOr;
8use vortex_scalar::Scalar;
9
10use crate::arrays::{BoolArray, BoolVTable};
11use crate::compute::{SumKernel, SumKernelAdapter};
12use crate::register_kernel;
13
14impl SumKernel for BoolVTable {
15 fn sum(&self, array: &BoolArray) -> VortexResult<Scalar> {
16 let true_count: Option<u64> = match array.validity_mask()?.boolean_buffer() {
17 AllOr::All => {
18 Some(array.boolean_buffer().count_set_bits() as u64)
20 }
21 AllOr::None => {
22 unreachable!("All-invalid boolean array should have been handled by entry-point")
24 }
25 AllOr::Some(validity_mask) => Some(
26 array
27 .boolean_buffer()
28 .bitand(validity_mask)
29 .count_set_bits() as u64,
30 ),
31 };
32 Ok(Scalar::from(true_count))
33 }
34}
35
36register_kernel!(SumKernelAdapter(BoolVTable).lift());