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

vortex-data / vortex / 16051309759

03 Jul 2025 01:08PM UTC coverage: 77.861% (-0.004%) from 77.865%
16051309759

push

github

web-flow
chore[benchmark]: support scale factors other than 1 in tpch (#3746)

Signed-off-by: Joe Isaacs <joe.isaacs@live.co.uk>

Signed-off-by: Joe Isaacs <joe.isaacs@live.co.uk>

43322 of 55640 relevant lines covered (77.86%)

55768.26 hits per line

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

72.86
/vortex-array/src/compute/invert.rs
1
use std::sync::LazyLock;
2

3
use arcref::ArcRef;
4
use vortex_dtype::DType;
5
use vortex_error::{VortexError, VortexResult, vortex_bail, vortex_err, vortex_panic};
6

7
use crate::compute::{ComputeFn, ComputeFnVTable, InvocationArgs, Kernel, Output, UnaryArgs};
8
use crate::vtable::VTable;
9
use crate::{Array, ArrayRef, IntoArray, ToCanonical};
10

11
/// Logically invert a boolean array, preserving its validity.
12
pub fn invert(array: &dyn Array) -> VortexResult<ArrayRef> {
113✔
13
    INVERT_FN
113✔
14
        .invoke(&InvocationArgs {
113✔
15
            inputs: &[array.into()],
113✔
16
            options: &(),
113✔
17
        })?
113✔
18
        .unwrap_array()
113✔
19
}
113✔
20

21
struct Invert;
22

23
impl ComputeFnVTable for Invert {
24
    fn invoke(
113✔
25
        &self,
113✔
26
        args: &InvocationArgs,
113✔
27
        kernels: &[ArcRef<dyn Kernel>],
113✔
28
    ) -> VortexResult<Output> {
113✔
29
        let UnaryArgs { array, .. } = UnaryArgs::<()>::try_from(args)?;
113✔
30

31
        for kernel in kernels {
113✔
32
            if let Some(output) = kernel.invoke(args)? {
113✔
33
                return Ok(output);
113✔
34
            }
×
35
        }
36
        if let Some(output) = array.invoke(&INVERT_FN, args)? {
×
37
            return Ok(output);
×
38
        }
×
39

×
40
        // Otherwise, we canonicalize into a boolean array and invert.
×
41
        log::debug!(
×
42
            "No invert implementation found for encoding {}",
×
43
            array.encoding_id(),
×
44
        );
45
        if array.is_canonical() {
×
46
            vortex_panic!("Canonical bool array does not implement invert");
×
47
        }
×
48
        Ok(invert(&array.to_bool()?.into_array())?.into())
×
49
    }
113✔
50

51
    fn return_dtype(&self, args: &InvocationArgs) -> VortexResult<DType> {
113✔
52
        let UnaryArgs { array, .. } = UnaryArgs::<()>::try_from(args)?;
113✔
53

54
        if !matches!(array.dtype(), DType::Bool(..)) {
113✔
55
            vortex_bail!("Expected boolean array, got {}", array.dtype());
×
56
        }
113✔
57
        Ok(array.dtype().clone())
113✔
58
    }
113✔
59

60
    fn return_len(&self, args: &InvocationArgs) -> VortexResult<usize> {
113✔
61
        let UnaryArgs { array, .. } = UnaryArgs::<()>::try_from(args)?;
113✔
62
        Ok(array.len())
113✔
63
    }
113✔
64

65
    fn is_elementwise(&self) -> bool {
113✔
66
        true
113✔
67
    }
113✔
68
}
69

70
struct InvertArgs<'a> {
71
    array: &'a dyn Array,
72
}
73

74
impl<'a> TryFrom<&InvocationArgs<'a>> for InvertArgs<'a> {
75
    type Error = VortexError;
76

77
    fn try_from(value: &InvocationArgs<'a>) -> Result<Self, Self::Error> {
113✔
78
        if value.inputs.len() != 1 {
113✔
79
            vortex_bail!("Invert expects exactly one argument",);
×
80
        }
113✔
81
        let array = value.inputs[0]
113✔
82
            .array()
113✔
83
            .ok_or_else(|| vortex_err!("Invert expects an array argument"))?;
113✔
84
        Ok(InvertArgs { array })
113✔
85
    }
113✔
86
}
87

88
pub struct InvertKernelRef(ArcRef<dyn Kernel>);
89
inventory::collect!(InvertKernelRef);
90

91
pub trait InvertKernel: VTable {
92
    /// Logically invert a boolean array. Converts true -> false, false -> true, null -> null.
93
    fn invert(&self, array: &Self::Array) -> VortexResult<ArrayRef>;
94
}
95

96
#[derive(Debug)]
97
pub struct InvertKernelAdapter<V: VTable>(pub V);
98

99
impl<V: VTable + InvertKernel> InvertKernelAdapter<V> {
100
    pub const fn lift(&'static self) -> InvertKernelRef {
×
101
        InvertKernelRef(ArcRef::new_ref(self))
×
102
    }
×
103
}
104

105
impl<V: VTable + InvertKernel> Kernel for InvertKernelAdapter<V> {
106
    fn invoke(&self, args: &InvocationArgs) -> VortexResult<Option<Output>> {
113✔
107
        let args = InvertArgs::try_from(args)?;
113✔
108
        let Some(array) = args.array.as_opt::<V>() else {
113✔
109
            return Ok(None);
×
110
        };
111
        Ok(Some(V::invert(&self.0, array)?.into()))
113✔
112
    }
113✔
113
}
114

115
pub static INVERT_FN: LazyLock<ComputeFn> = LazyLock::new(|| {
112✔
116
    let compute = ComputeFn::new("invert".into(), ArcRef::new_ref(&Invert));
112✔
117
    for kernel in inventory::iter::<InvertKernelRef> {
522✔
118
        compute.register_kernel(kernel.0.clone());
410✔
119
    }
410✔
120
    compute
112✔
121
});
112✔
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