Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
98 changes: 36 additions & 62 deletions encodings/alp/src/alp_rd/array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ use vortex_array::ExecutionCtx;
use vortex_array::ExecutionResult;
use vortex_array::IntoArray;
use vortex_array::TypedArrayRef;
use vortex_array::array_slots;
use vortex_array::arrays::Primitive;
use vortex_array::arrays::PrimitiveArray;
use vortex_array::buffer::BufferHandle;
Expand Down Expand Up @@ -105,12 +106,15 @@ impl VTable for ALPRD {
len: usize,
slots: &[Option<ArrayRef>],
) -> VortexResult<()> {
let slots_view = ALPRDSlotsView::from_slots(slots);
let patches =
PatchesData::patches_from_slots(data.patches_data.as_ref(), len, slots, LP_PATCH_SLOTS);
validate_parts(
dtype,
len,
left_parts_from_slots(slots),
right_parts_from_slots(slots),
patches_from_slots(slots, data.patches_data.as_ref(), len).as_ref(),
slots_view.left_parts,
slots_view.right_parts,
patches.as_ref(),
)
}

Expand Down Expand Up @@ -230,17 +234,18 @@ impl VTable for ALPRD {
}

fn slot_name(_array: ArrayView<'_, Self>, idx: usize) -> String {
SLOT_NAMES[idx].to_string()
ALPRDSlots::NAMES[idx].to_string()
}

fn execute(array: Array<Self>, ctx: &mut ExecutionCtx) -> VortexResult<ExecutionResult> {
let array = require_child!(array, array.left_parts(), 0 => Primitive);
let array = require_child!(array, array.right_parts(), 1 => Primitive);
let array = require_child!(array, array.left_parts(), ALPRDSlots::LEFT_PARTS => Primitive);
let array =
require_child!(array, array.right_parts(), ALPRDSlots::RIGHT_PARTS => Primitive);
require_patches!(
array,
LP_PATCH_INDICES_SLOT,
LP_PATCH_VALUES_SLOT,
LP_PATCH_CHUNK_OFFSETS_SLOT
ALPRDSlots::PATCH_INDICES,
ALPRDSlots::PATCH_VALUES,
ALPRDSlots::PATCH_CHUNK_OFFSETS
);

let dtype = array.dtype().clone();
Expand Down Expand Up @@ -307,29 +312,25 @@ impl VTable for ALPRD {
}
}

/// The left (most significant) parts of the real-double encoded values.
pub(super) const LEFT_PARTS_SLOT: usize = 0;
/// The right (least significant) parts of the real-double encoded values.
pub(super) const RIGHT_PARTS_SLOT: usize = 1;
/// The indices of left-parts exception values that could not be dictionary-encoded.
pub(super) const LP_PATCH_SLOTS: PatchSlotIndices = PatchSlotIndices {
indices: LP_PATCH_INDICES_SLOT,
values: LP_PATCH_VALUES_SLOT,
chunk_offsets: LP_PATCH_CHUNK_OFFSETS_SLOT,
#[array_slots(ALPRD)]
pub struct ALPRDSlots {
/// The left (most significant) parts of the real-double encoded values.
pub left_parts: ArrayRef,
/// The right (least significant) parts of the real-double encoded values.
pub right_parts: ArrayRef,
/// The indices of left-parts exception values that could not be dictionary-encoded.
pub patch_indices: Option<ArrayRef>,
/// The exception values for left-parts that could not be dictionary-encoded.
pub patch_values: Option<ArrayRef>,
/// Chunk offsets for the left-parts patch indices/values.
pub patch_chunk_offsets: Option<ArrayRef>,
}

const LP_PATCH_SLOTS: PatchSlotIndices = PatchSlotIndices {
indices: ALPRDSlots::PATCH_INDICES,
values: ALPRDSlots::PATCH_VALUES,
chunk_offsets: ALPRDSlots::PATCH_CHUNK_OFFSETS,
};
pub(super) const LP_PATCH_INDICES_SLOT: usize = 2;
/// The exception values for left-parts that could not be dictionary-encoded.
pub(super) const LP_PATCH_VALUES_SLOT: usize = 3;
/// Chunk offsets for the left-parts patch indices/values.
pub(super) const LP_PATCH_CHUNK_OFFSETS_SLOT: usize = 4;
pub(super) const NUM_SLOTS: usize = 5;
pub(super) const SLOT_NAMES: [&str; NUM_SLOTS] = [
"left_parts",
"right_parts",
"patch_indices",
"patch_values",
"patch_chunk_offsets",
];

#[derive(Clone, Debug)]
pub struct ALPRDData {
Expand Down Expand Up @@ -451,26 +452,6 @@ impl ALPRDData {
}
}

fn left_parts_from_slots(slots: &[Option<ArrayRef>]) -> &ArrayRef {
slots[LEFT_PARTS_SLOT]
.as_ref()
.vortex_expect("ALPRDArray left_parts slot")
}

fn right_parts_from_slots(slots: &[Option<ArrayRef>]) -> &ArrayRef {
slots[RIGHT_PARTS_SLOT]
.as_ref()
.vortex_expect("ALPRDArray right_parts slot")
}

fn patches_from_slots(
slots: &[Option<ArrayRef>],
patches_data: Option<&PatchesData>,
len: usize,
) -> Option<Patches> {
PatchesData::patches_from_slots(patches_data, len, slots, LP_PATCH_SLOTS)
}

#[allow(clippy::disallowed_methods)]
fn validate_parts(
dtype: &DType,
Expand Down Expand Up @@ -539,24 +520,17 @@ fn validate_parts(
Ok(())
}

pub trait ALPRDArrayExt: TypedArrayRef<ALPRD> {
fn left_parts(&self) -> &ArrayRef {
left_parts_from_slots(self.as_ref().slots())
}

fn right_parts(&self) -> &ArrayRef {
right_parts_from_slots(self.as_ref().slots())
}

pub trait ALPRDArrayExt: ALPRDArraySlotsExt {
fn right_bit_width(&self) -> u8 {
ALPRDData::right_bit_width(self)
}

fn left_parts_patches(&self) -> Option<Patches> {
patches_from_slots(
self.as_ref().slots(),
PatchesData::patches_from_slots(
self.patches_data.as_ref(),
self.as_ref().len(),
self.as_ref().slots(),
LP_PATCH_SLOTS,
)
}

Expand Down
1 change: 1 addition & 0 deletions encodings/alp/src/alp_rd/compute/cast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use vortex_array::scalar_fn::fns::cast::CastReduce;
use vortex_error::VortexResult;

use crate::ALPRDArrayExt;
use crate::ALPRDArraySlotsExt;
use crate::alp_rd::ALPRD;

impl CastReduce for ALPRD {
Expand Down
1 change: 1 addition & 0 deletions encodings/alp/src/alp_rd/compute/filter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use vortex_mask::Mask;

use crate::ALPRD;
use crate::ALPRDArrayExt;
use crate::ALPRDArraySlotsExt;

impl FilterKernel for ALPRD {
fn filter(
Expand Down
1 change: 1 addition & 0 deletions encodings/alp/src/alp_rd/compute/mask.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use vortex_error::VortexResult;

use crate::ALPRD;
use crate::ALPRDArrayExt;
use crate::ALPRDArraySlotsExt;

impl MaskReduce for ALPRD {
#[allow(clippy::disallowed_methods)]
Expand Down
1 change: 1 addition & 0 deletions encodings/alp/src/alp_rd/compute/take.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use vortex_error::VortexResult;

use crate::ALPRD;
use crate::ALPRDArrayExt;
use crate::ALPRDArraySlotsExt;

impl TakeExecute for ALPRD {
fn take(
Expand Down
1 change: 1 addition & 0 deletions encodings/alp/src/alp_rd/ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use vortex_error::VortexResult;

use crate::ALPRD;
use crate::ALPRDArrayExt;
use crate::ALPRDArraySlotsExt;

impl OperationsVTable<ALPRD> for ALPRD {
fn scalar_at(
Expand Down
1 change: 1 addition & 0 deletions encodings/alp/src/alp_rd/slice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use vortex_array::arrays::slice::SliceKernel;
use vortex_error::VortexResult;

use crate::ALPRDArrayExt;
use crate::ALPRDArraySlotsExt;
use crate::alp_rd::ALPRD;

impl SliceKernel for ALPRD {
Expand Down
1 change: 1 addition & 0 deletions encodings/fastlanes/src/delta/array/delta_decompress.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ use vortex_error::VortexResult;
use crate::DeltaArray;
use crate::bit_transpose::untranspose_validity;
use crate::delta::array::DeltaArrayExt;
use crate::delta::array::DeltaArraySlotsExt;

pub fn delta_decompress(
array: &DeltaArray,
Expand Down
29 changes: 9 additions & 20 deletions encodings/fastlanes/src/delta/array/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,22 @@ use std::fmt::Formatter;
use fastlanes::FastLanes;
use vortex_array::ArrayRef;
use vortex_array::TypedArrayRef;
use vortex_array::array_slots;
use vortex_array::dtype::PType;
use vortex_array::match_each_unsigned_integer_ptype;
use vortex_error::VortexExpect;
use vortex_error::VortexResult;
use vortex_error::vortex_ensure;

pub mod delta_compress;
pub mod delta_decompress;

/// The base values for each block of deltas.
pub(super) const BASES_SLOT: usize = 0;
/// The delta-encoded values relative to the base values.
pub(super) const DELTAS_SLOT: usize = 1;
pub(super) const NUM_SLOTS: usize = 2;
pub(super) const SLOT_NAMES: [&str; NUM_SLOTS] = ["bases", "deltas"];
#[array_slots(crate::Delta)]
pub struct DeltaSlots {
/// The base values for each block of deltas.
pub bases: ArrayRef,
/// The delta-encoded values relative to the base values.
pub deltas: ArrayRef,
}

/// A FastLanes-style delta-encoded array of primitive values.
///
Expand Down Expand Up @@ -88,19 +89,7 @@ impl Display for DeltaData {
}
}

pub trait DeltaArrayExt: TypedArrayRef<crate::Delta> {
fn bases(&self) -> &ArrayRef {
self.as_ref().slots()[BASES_SLOT]
.as_ref()
.vortex_expect("DeltaArray bases slot")
}

fn deltas(&self) -> &ArrayRef {
self.as_ref().slots()[DELTAS_SLOT]
.as_ref()
.vortex_expect("DeltaArray deltas slot")
}

pub trait DeltaArrayExt: DeltaArraySlotsExt {
fn offset(&self) -> usize {
self.offset
}
Expand Down
1 change: 1 addition & 0 deletions encodings/fastlanes/src/delta/compute/cast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use vortex_error::VortexResult;

use crate::delta::Delta;
use crate::delta::array::DeltaArrayExt;
use crate::delta::array::DeltaArraySlotsExt;

impl CastReduce for Delta {
fn cast(array: ArrayView<'_, Self>, dtype: &DType) -> VortexResult<Option<ArrayRef>> {
Expand Down
3 changes: 3 additions & 0 deletions encodings/fastlanes/src/delta/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@
// SPDX-FileCopyrightText: Copyright the Vortex contributors

mod array;
pub use array::DeltaArraySlotsExt;
pub use array::DeltaData;
pub use array::DeltaSlots;
pub use array::DeltaSlotsView;
pub use array::delta_compress::delta_compress;

mod compute;
Expand Down
21 changes: 7 additions & 14 deletions encodings/fastlanes/src/delta/vtable/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,7 @@ use vortex_array::buffer::BufferHandle;
use vortex_array::dtype::DType;
use vortex_array::dtype::PType;
use vortex_array::serde::ArrayChildren;
use vortex_array::smallvec::smallvec;
use vortex_array::vtable::VTable;
use vortex_error::VortexExpect;
use vortex_error::VortexResult;
use vortex_error::vortex_ensure;
use vortex_error::vortex_err;
Expand All @@ -32,10 +30,10 @@ use vortex_session::VortexSession;
use vortex_session::registry::CachedId;

use crate::DeltaData;
use crate::delta::array::BASES_SLOT;
use crate::delta::array::DELTAS_SLOT;
use crate::delta::array::DeltaArrayExt;
use crate::delta::array::SLOT_NAMES;
use crate::delta::array::DeltaArraySlotsExt;
use crate::delta::array::DeltaSlots;
use crate::delta::array::DeltaSlotsView;
use crate::delta::array::delta_decompress::delta_decompress;
use crate::delta::array::lane_count;
use crate::delta_compress;
Expand Down Expand Up @@ -87,12 +85,7 @@ impl VTable for Delta {
len: usize,
slots: &[Option<ArrayRef>],
) -> VortexResult<()> {
let bases = slots[BASES_SLOT]
.as_ref()
.vortex_expect("DeltaArray bases slot");
let deltas = slots[DELTAS_SLOT]
.as_ref()
.vortex_expect("DeltaArray deltas slot");
let DeltaSlotsView { bases, deltas } = DeltaSlotsView::from_slots(slots);
validate_parts(bases, deltas, data.offset, dtype, len)
}

Expand Down Expand Up @@ -125,7 +118,7 @@ impl VTable for Delta {
}

fn slot_name(_array: ArrayView<'_, Self>, idx: usize) -> String {
SLOT_NAMES[idx].to_string()
DeltaSlots::NAMES[idx].to_string()
}

fn serialize(
Expand Down Expand Up @@ -175,7 +168,7 @@ impl VTable for Delta {
let deltas = children.get(1, dtype, deltas_len)?;

let data = DeltaData::try_new(metadata.offset as usize)?;
let slots = smallvec![Some(bases), Some(deltas)];
let slots = DeltaSlots { bases, deltas }.into_slots();
Ok(ArrayParts::new(self.clone(), dtype.clone(), len, data).with_slots(slots))
}

Expand All @@ -198,7 +191,7 @@ impl Delta {
) -> VortexResult<DeltaArray> {
let dtype = bases.dtype().with_nullability(deltas.dtype().nullability());
let data = DeltaData::try_new(offset)?;
let slots = smallvec![Some(bases), Some(deltas)];
let slots = DeltaSlots { bases, deltas }.into_slots();
Array::try_from_parts(ArrayParts::new(Delta, dtype, len, data).with_slots(slots))
}

Expand Down
1 change: 1 addition & 0 deletions encodings/fastlanes/src/delta/vtable/slice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use vortex_array::arrays::slice::SliceReduce;
use vortex_error::VortexResult;

use crate::delta::array::DeltaArrayExt;
use crate::delta::array::DeltaArraySlotsExt;
use crate::delta::array::lane_count;
use crate::delta::vtable::Delta;

Expand Down
1 change: 1 addition & 0 deletions encodings/fastlanes/src/delta/vtable/validity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use vortex_error::VortexResult;
use crate::Delta;
use crate::bit_transpose::untranspose_validity;
use crate::delta::array::DeltaArrayExt;
use crate::delta::array::DeltaArraySlotsExt;

impl ValidityVTable<Delta> for Delta {
#[allow(clippy::disallowed_methods)]
Expand Down
Loading
Loading