vortex_array/arrays/bool/compute/
mask.rs

1// SPDX-License-Identifier: Apache-2.0
2// SPDX-FileCopyrightText: Copyright the Vortex contributors
3
4use vortex_error::VortexResult;
5use vortex_mask::Mask;
6
7use crate::ArrayRef;
8use crate::IntoArray;
9use crate::arrays::BoolArray;
10use crate::arrays::BoolVTable;
11use crate::compute::MaskKernel;
12use crate::compute::MaskKernelAdapter;
13use crate::register_kernel;
14use crate::vtable::ValidityHelper;
15
16impl MaskKernel for BoolVTable {
17    fn mask(&self, array: &BoolArray, mask: &Mask) -> VortexResult<ArrayRef> {
18        Ok(
19            BoolArray::from_bit_buffer(array.bit_buffer().clone(), array.validity().mask(mask))
20                .into_array(),
21        )
22    }
23}
24
25register_kernel!(MaskKernelAdapter(BoolVTable).lift());
26
27#[cfg(test)]
28mod test {
29    use rstest::rstest;
30
31    use crate::arrays::BoolArray;
32    use crate::compute::conformance::mask::test_mask_conformance;
33
34    #[rstest]
35    #[case(BoolArray::from_iter([true, false, true, true, false]))]
36    #[case(BoolArray::from_iter([Some(true), None, Some(false), Some(true), None]))]
37    #[case(BoolArray::from_iter([true]))]
38    #[case(BoolArray::from_iter([false, false]))]
39    #[case(BoolArray::from_iter((0..100).map(|i| i % 2 == 0)))]
40    fn test_mask_bool_conformance(#[case] array: BoolArray) {
41        test_mask_conformance(array.as_ref());
42    }
43}