vortex_fastlanes/for/array/
mod.rs1use std::fmt::Display;
5use std::fmt::Formatter;
6
7use vortex_array::ArrayRef;
8use vortex_array::TypedArrayRef;
9use vortex_array::array_slots;
10use vortex_array::dtype::PType;
11use vortex_array::scalar::Scalar;
12use vortex_error::VortexResult;
13use vortex_error::vortex_ensure;
14
15pub mod for_compress;
16pub mod for_decompress;
17
18#[array_slots(crate::FoR)]
19pub struct FoRSlots {
20 pub encoded: ArrayRef,
22}
23
24#[derive(Clone, Debug)]
29pub struct FoRData {
30 pub(super) reference: Scalar,
31}
32
33pub trait FoRArrayExt: FoRArraySlotsExt {
34 fn reference_scalar(&self) -> &Scalar {
35 &self.reference
36 }
37}
38
39impl<T: TypedArrayRef<crate::FoR>> FoRArrayExt for T {}
40
41impl Display for FoRData {
42 fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
43 write!(f, "reference: {}", self.reference)
44 }
45}
46
47impl FoRData {
48 pub(crate) fn try_new(reference: Scalar) -> VortexResult<Self> {
49 vortex_ensure!(!reference.is_null(), "Reference value cannot be null");
50 vortex_ensure!(
51 reference.dtype().is_int(),
52 "FoR requires an integer reference dtype, got {}",
53 reference.dtype()
54 );
55 Ok(Self { reference })
56 }
57
58 #[inline]
59 pub fn ptype(&self) -> PType {
60 self.reference.dtype().as_ptype()
61 }
62}