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

vortex-data / vortex / 16970635821

14 Aug 2025 04:13PM UTC coverage: 85.882% (-1.8%) from 87.693%
16970635821

Pull #4215

github

web-flow
Merge 5182504a6 into f547cbca5
Pull Request #4215: Ji/vectors

80 of 1729 new or added lines in 38 files covered. (4.63%)

117 existing lines in 25 files now uncovered.

56994 of 66363 relevant lines covered (85.88%)

609331.7 hits per line

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

0.0
/vortex-array/src/pipeline/operators/constant.rs
1
use std::any::Any;
2
use std::hash::{Hash, Hasher};
3
use std::sync::Arc;
4
use std::task::Poll;
5

6
use vortex_dtype::{DType, NativePType, match_each_native_ptype};
7
use vortex_error::{VortexExpect, VortexResult};
8
use vortex_scalar::Scalar;
9

10
use crate::pipeline::bits::BitView;
11
use crate::pipeline::operators::{BindContext, Operator};
12
use crate::pipeline::types::{Element, VType};
13
use crate::pipeline::view::ViewMut;
14
use crate::pipeline::{Kernel, KernelContext};
15

16
#[derive(Debug)]
17
pub struct ConstantOperator {
18
    pub(crate) scalar: Scalar,
19
}
20

21
impl ConstantOperator {
NEW
22
    pub fn new(scalar: Scalar) -> Self {
×
NEW
23
        Self { scalar }
×
NEW
24
    }
×
25
}
26

27
impl Hash for ConstantOperator {
NEW
28
    fn hash<H: Hasher>(&self, state: &mut H) {
×
NEW
29
        self.scalar.as_ref().hash(state);
×
NEW
30
    }
×
31
}
32

33
impl Operator for ConstantOperator {
NEW
34
    fn as_any(&self) -> &dyn Any {
×
NEW
35
        self
×
NEW
36
    }
×
37

NEW
38
    fn vtype(&self) -> VType {
×
NEW
39
        match self.scalar.dtype() {
×
NEW
40
            DType::Bool(_) => VType::Bool,
×
NEW
41
            DType::Primitive(p, _) => VType::Primitive(*p),
×
NEW
42
            DType::Binary(_) => VType::Binary,
×
NEW
43
            _ => todo!(),
×
44
        }
NEW
45
    }
×
46

NEW
47
    fn children(&self) -> &[Arc<dyn Operator>] {
×
NEW
48
        &[]
×
NEW
49
    }
×
50

NEW
51
    fn with_children(&self, children: Vec<Arc<dyn Operator>>) -> Arc<dyn Operator> {
×
NEW
52
        Arc::new(ConstantOperator::new(self.scalar.clone()))
×
NEW
53
    }
×
54

NEW
55
    fn bind(&self, ctx: &dyn BindContext) -> VortexResult<Box<dyn Kernel>> {
×
NEW
56
        Ok(match_each_native_ptype!(
×
NEW
57
            self.scalar.as_primitive().ptype(),
×
58
            |T| {
NEW
59
                Box::new(ConstantKernel::<T> {
×
NEW
60
                    value: self
×
NEW
61
                        .scalar
×
NEW
62
                        .as_primitive()
×
NEW
63
                        .typed_value::<T>()
×
NEW
64
                        .vortex_expect("scalar value not of type T"),
×
NEW
65
                })
×
66
            }
67
        ))
NEW
68
    }
×
69
}
70

71
pub struct ConstantKernel<T: NativePType> {
72
    value: T,
73
}
74

75
impl<T: Element + NativePType> Kernel for ConstantKernel<T> {
NEW
76
    fn seek(&mut self, chunk_idx: usize) -> VortexResult<()> {
×
NEW
77
        Ok(())
×
NEW
78
    }
×
79

NEW
80
    fn step(
×
NEW
81
        &mut self,
×
NEW
82
        ctx: &dyn KernelContext,
×
NEW
83
        selected: BitView,
×
NEW
84
        out: &mut ViewMut,
×
NEW
85
    ) -> Poll<VortexResult<()>> {
×
NEW
86
        let out_slice = out.as_slice_mut::<T>();
×
NEW
87
        for i in 0..selected.true_count() {
×
NEW
88
            out_slice[i] = self.value;
×
NEW
89
        }
×
NEW
90
        Poll::Ready(Ok(()))
×
NEW
91
    }
×
92
}
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