Skip to main content

vortex_sparse/
rules.rs

1// SPDX-License-Identifier: Apache-2.0
2// SPDX-FileCopyrightText: Copyright the Vortex contributors
3
4use vortex_array::ArrayRef;
5use vortex_array::IntoArray;
6use vortex_array::builtins::ArrayBuiltins;
7use vortex_array::compute::CastReduceAdaptor;
8use vortex_array::expr::NotReduce;
9use vortex_array::expr::NotReduceAdaptor;
10use vortex_array::optimizer::rules::ParentRuleSet;
11use vortex_error::VortexResult;
12
13use crate::SparseArray;
14use crate::SparseVTable;
15
16pub(crate) static RULES: ParentRuleSet<SparseVTable> = ParentRuleSet::new(&[
17    ParentRuleSet::lift(&CastReduceAdaptor(SparseVTable)),
18    ParentRuleSet::lift(&NotReduceAdaptor(SparseVTable)),
19]);
20
21impl NotReduce for SparseVTable {
22    fn invert(array: &SparseArray) -> VortexResult<Option<ArrayRef>> {
23        let inverted_fill = array.fill_scalar().as_bool().invert().into_scalar();
24        let inverted_patches = array.patches().clone().map_values(|values| values.not())?;
25        Ok(Some(
26            SparseArray::try_new_from_patches(inverted_patches, inverted_fill)?.into_array(),
27        ))
28    }
29}