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::arrays::{BoolArray, BoolVTable};
8use crate::compute::{MaskKernel, MaskKernelAdapter};
9use crate::vtable::ValidityHelper;
10use crate::{ArrayRef, IntoArray, register_kernel};
11
12impl MaskKernel for BoolVTable {
13    fn mask(&self, array: &BoolArray, mask: &Mask) -> VortexResult<ArrayRef> {
14        Ok(
15            BoolArray::from_bool_buffer(
16                array.boolean_buffer().clone(),
17                array.validity().mask(mask),
18            )
19            .into_array(),
20        )
21    }
22}
23
24register_kernel!(MaskKernelAdapter(BoolVTable).lift());
25
26#[cfg(test)]
27mod test {
28    use rstest::rstest;
29
30    use crate::arrays::BoolArray;
31    use crate::compute::conformance::mask::test_mask_conformance;
32
33    #[rstest]
34    #[case(BoolArray::from_iter([true, false, true, true, false]))]
35    #[case(BoolArray::from_iter([Some(true), None, Some(false), Some(true), None]))]
36    #[case(BoolArray::from_iter([true]))]
37    #[case(BoolArray::from_iter([false, false]))]
38    #[case(BoolArray::from_iter((0..100).map(|i| i % 2 == 0)))]
39    fn test_mask_bool_conformance(#[case] array: BoolArray) {
40        test_mask_conformance(array.as_ref());
41    }
42}