Skip to main content

vortex_array/scalar_fn/fns/not/
kernel.rs

1// SPDX-License-Identifier: Apache-2.0
2// SPDX-FileCopyrightText: Copyright the Vortex contributors
3
4use vortex_error::VortexResult;
5
6use crate::ArrayRef;
7use crate::array::ArrayView;
8use crate::array::VTable;
9use crate::arrays::scalar_fn::ExactScalarFn;
10use crate::arrays::scalar_fn::ScalarFnArrayView;
11use crate::optimizer::rules::ArrayParentReduceRule;
12use crate::scalar_fn::fns::not::Not as NotExpr;
13
14/// Invert a boolean array without reading buffers.
15///
16/// This trait is for invert implementations that can operate purely on array metadata
17/// and structure without needing to read or execute on the underlying buffers.
18/// Implementations should return `None` if the operation requires buffer access.
19pub trait NotReduce: VTable {
20    fn invert(array: ArrayView<'_, Self>) -> VortexResult<Option<ArrayRef>>;
21}
22
23/// Adaptor that wraps a [`NotReduce`] impl as an [`ArrayParentReduceRule`].
24#[derive(Default, Debug)]
25pub struct NotReduceAdaptor<V>(pub V);
26
27impl<V> ArrayParentReduceRule<V> for NotReduceAdaptor<V>
28where
29    V: NotReduce,
30{
31    type Parent = ExactScalarFn<NotExpr>;
32
33    fn reduce_parent(
34        &self,
35        array: ArrayView<'_, V>,
36        _parent: ScalarFnArrayView<'_, NotExpr>,
37        _child_idx: usize,
38    ) -> VortexResult<Option<ArrayRef>> {
39        <V as NotReduce>::invert(array)
40    }
41}