• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

vortex-data / vortex / 16595455362

29 Jul 2025 12:00PM UTC coverage: 82.182% (+0.4%) from 81.796%
16595455362

Pull #4036

github

web-flow
Merge 28b120788 into 261aabd6a
Pull Request #4036: varbinview builder buffer deduplication

147 of 155 new or added lines in 2 files covered. (94.84%)

404 existing lines in 34 files now uncovered.

44415 of 54045 relevant lines covered (82.18%)

167869.47 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

77.94
/vortex-array/src/compute/invert.rs
1
// SPDX-License-Identifier: Apache-2.0
2
// SPDX-FileCopyrightText: Copyright the Vortex contributors
3

4
use std::sync::LazyLock;
5

6
use arcref::ArcRef;
7
use vortex_dtype::DType;
8
use vortex_error::{VortexError, VortexResult, vortex_bail, vortex_err, vortex_panic};
9

10
use crate::compute::{ComputeFn, ComputeFnVTable, InvocationArgs, Kernel, Output, UnaryArgs};
11
use crate::vtable::VTable;
12
use crate::{Array, ArrayRef, IntoArray, ToCanonical};
13

14
static INVERT_FN: LazyLock<ComputeFn> = LazyLock::new(|| {
115✔
15
    let compute = ComputeFn::new("invert".into(), ArcRef::new_ref(&Invert));
115✔
16
    for kernel in inventory::iter::<InvertKernelRef> {
536✔
17
        compute.register_kernel(kernel.0.clone());
421✔
18
    }
421✔
19
    compute
115✔
20
});
115✔
21

22
/// Logically invert a boolean array, preserving its validity.
23
pub fn invert(array: &dyn Array) -> VortexResult<ArrayRef> {
116✔
24
    INVERT_FN
116✔
25
        .invoke(&InvocationArgs {
116✔
26
            inputs: &[array.into()],
116✔
27
            options: &(),
116✔
28
        })?
116✔
29
        .unwrap_array()
116✔
30
}
116✔
31

32
struct Invert;
33

34
impl ComputeFnVTable for Invert {
35
    fn invoke(
116✔
36
        &self,
116✔
37
        args: &InvocationArgs,
116✔
38
        kernels: &[ArcRef<dyn Kernel>],
116✔
39
    ) -> VortexResult<Output> {
116✔
40
        let UnaryArgs { array, .. } = UnaryArgs::<()>::try_from(args)?;
116✔
41

42
        for kernel in kernels {
346✔
43
            if let Some(output) = kernel.invoke(args)? {
346✔
44
                return Ok(output);
116✔
45
            }
230✔
46
        }
UNCOV
47
        if let Some(output) = array.invoke(&INVERT_FN, args)? {
×
48
            return Ok(output);
×
49
        }
×
50

51
        // Otherwise, we canonicalize into a boolean array and invert.
UNCOV
52
        log::debug!(
×
UNCOV
53
            "No invert implementation found for encoding {}",
×
UNCOV
54
            array.encoding_id(),
×
55
        );
UNCOV
56
        if array.is_canonical() {
×
UNCOV
57
            vortex_panic!("Canonical bool array does not implement invert");
×
58
        }
×
UNCOV
59
        Ok(invert(&array.to_bool()?.into_array())?.into())
×
60
    }
116✔
61

62
    fn return_dtype(&self, args: &InvocationArgs) -> VortexResult<DType> {
116✔
63
        let UnaryArgs { array, .. } = UnaryArgs::<()>::try_from(args)?;
116✔
64

65
        if !matches!(array.dtype(), DType::Bool(..)) {
116✔
UNCOV
66
            vortex_bail!("Expected boolean array, got {}", array.dtype());
×
67
        }
116✔
68
        Ok(array.dtype().clone())
116✔
69
    }
116✔
70

71
    fn return_len(&self, args: &InvocationArgs) -> VortexResult<usize> {
116✔
72
        let UnaryArgs { array, .. } = UnaryArgs::<()>::try_from(args)?;
116✔
73
        Ok(array.len())
116✔
74
    }
116✔
75

76
    fn is_elementwise(&self) -> bool {
116✔
77
        true
116✔
78
    }
116✔
79
}
80

81
struct InvertArgs<'a> {
82
    array: &'a dyn Array,
83
}
84

85
impl<'a> TryFrom<&InvocationArgs<'a>> for InvertArgs<'a> {
86
    type Error = VortexError;
87

88
    fn try_from(value: &InvocationArgs<'a>) -> Result<Self, Self::Error> {
346✔
89
        if value.inputs.len() != 1 {
346✔
UNCOV
90
            vortex_bail!("Invert expects exactly one argument",);
×
91
        }
346✔
92
        let array = value.inputs[0]
346✔
93
            .array()
346✔
94
            .ok_or_else(|| vortex_err!("Invert expects an array argument"))?;
346✔
95
        Ok(InvertArgs { array })
346✔
96
    }
346✔
97
}
98

99
pub struct InvertKernelRef(ArcRef<dyn Kernel>);
100
inventory::collect!(InvertKernelRef);
101

102
pub trait InvertKernel: VTable {
103
    /// Logically invert a boolean array. Converts true -> false, false -> true, null -> null.
104
    fn invert(&self, array: &Self::Array) -> VortexResult<ArrayRef>;
105
}
106

107
#[derive(Debug)]
108
pub struct InvertKernelAdapter<V: VTable>(pub V);
109

110
impl<V: VTable + InvertKernel> InvertKernelAdapter<V> {
UNCOV
111
    pub const fn lift(&'static self) -> InvertKernelRef {
×
112
        InvertKernelRef(ArcRef::new_ref(self))
×
UNCOV
113
    }
×
114
}
115

116
impl<V: VTable + InvertKernel> Kernel for InvertKernelAdapter<V> {
117
    fn invoke(&self, args: &InvocationArgs) -> VortexResult<Option<Output>> {
346✔
118
        let args = InvertArgs::try_from(args)?;
346✔
119
        let Some(array) = args.array.as_opt::<V>() else {
346✔
120
            return Ok(None);
230✔
121
        };
122
        Ok(Some(V::invert(&self.0, array)?.into()))
116✔
123
    }
346✔
124
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc