Skip to main content

vortex_array/arrays/null/compute/
take.rs

1// SPDX-License-Identifier: Apache-2.0
2// SPDX-FileCopyrightText: Copyright the Vortex contributors
3
4use vortex_error::VortexResult;
5use vortex_error::vortex_bail;
6
7use crate::ArrayRef;
8use crate::IntoArray;
9use crate::ToCanonical;
10use crate::arrays::NullArray;
11use crate::arrays::NullVTable;
12use crate::arrays::TakeReduce;
13use crate::arrays::TakeReduceAdaptor;
14use crate::match_each_integer_ptype;
15use crate::optimizer::rules::ParentRuleSet;
16
17impl TakeReduce for NullVTable {
18    #[allow(clippy::cast_possible_truncation)]
19    fn take(array: &NullArray, indices: &ArrayRef) -> VortexResult<Option<ArrayRef>> {
20        let indices = indices.to_primitive();
21
22        // Enforce all indices are valid
23        match_each_integer_ptype!(indices.ptype(), |T| {
24            for index in indices.as_slice::<T>() {
25                if (*index as usize) >= array.len() {
26                    vortex_bail!(OutOfBounds: *index as usize, 0, array.len());
27                }
28            }
29        });
30
31        Ok(Some(NullArray::new(indices.len()).into_array()))
32    }
33}
34
35impl NullVTable {
36    pub const TAKE_RULES: ParentRuleSet<Self> =
37        ParentRuleSet::new(&[ParentRuleSet::lift(&TakeReduceAdaptor::<Self>(Self))]);
38}