Skip to content
Merged
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
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion encodings/alp/src/alp/array/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ pub struct ALPSlots {
pub patch_chunk_offsets: Option<ArrayRef>,
}

const PATCH_SLOTS: PatchSlotIndices = PatchSlotIndices {
pub(crate) const PATCH_SLOTS: PatchSlotIndices = PatchSlotIndices {
indices: ALPSlots::PATCH_INDICES,
values: ALPSlots::PATCH_VALUES,
chunk_offsets: ALPSlots::PATCH_CHUNK_OFFSETS,
Expand Down
3 changes: 2 additions & 1 deletion encodings/alp/src/alp/ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ use crate::ALP;
use crate::ALPArrayExt;
use crate::ALPFloat;
use crate::ALPSlots;
use crate::alp::array::PATCH_SLOTS;
use crate::match_each_alp_float_ptype;

impl OperationsVTable<ALP> for ALP {
Expand All @@ -29,7 +30,7 @@ impl OperationsVTable<ALP> for ALP {
}
let array = state.array();
if let Some(patches) = array.patches()
&& let Some(patch) = patches.get_patched(index, ctx)?
&& let Some(patch) = patches.probe_patched(state, PATCH_SLOTS, index, ctx)?
{
return patch.cast(array.dtype());
}
Expand Down
2 changes: 1 addition & 1 deletion encodings/alp/src/alp_rd/array/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ pub struct ALPRDSlots {
pub patch_chunk_offsets: Option<ArrayRef>,
}

const LP_PATCH_SLOTS: PatchSlotIndices = PatchSlotIndices {
pub(crate) const LP_PATCH_SLOTS: PatchSlotIndices = PatchSlotIndices {
indices: ALPRDSlots::PATCH_INDICES,
values: ALPRDSlots::PATCH_VALUES,
chunk_offsets: ALPRDSlots::PATCH_CHUNK_OFFSETS,
Expand Down
112 changes: 68 additions & 44 deletions encodings/alp/src/alp_rd/ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

use vortex_array::ArrayView;
use vortex_array::ExecutionCtx;
use vortex_array::ProbeState;
use vortex_array::dtype::PType;
use vortex_array::scalar::Scalar;
use vortex_array::vtable::OperationsVTable;
Expand All @@ -12,62 +13,85 @@ use vortex_error::VortexResult;
use crate::ALPRD;
use crate::ALPRDArrayExt;
use crate::ALPRDArraySlotsExt;
use crate::alp_rd::array::LP_PATCH_SLOTS;
use crate::alp_rd::code_not_in_dictionary;

impl OperationsVTable<ALPRD> for ALPRD {
type ProbeState = ();

fn probe_scalar(
state: &mut ProbeState<'_, ALPRD>,
index: usize,
ctx: &mut ExecutionCtx,
) -> VortexResult<Scalar> {
if !state.is_valid(index, ctx)? {
return Ok(Scalar::null(state.array().dtype().clone()));
}
read_valid(state, index, ctx)
}

fn scalar_at(
array: ArrayView<'_, ALPRD>,
index: usize,
ctx: &mut ExecutionCtx,
) -> VortexResult<Scalar> {
// The left value can either be a direct value, or an exception.
// The exceptions array represents exception positions with non-null values.
let maybe_patched_value = match array.left_parts_patches() {
Some(patches) => patches.get_patched(index, ctx)?,
None => None,
};
let left = match maybe_patched_value {
Some(patched_value) => patched_value
.as_primitive()
.as_::<u16>()
.vortex_expect("patched values must be non-null"),
_ => {
let left_code: u16 = array
.left_parts()
.execute_scalar(index, ctx)?
.as_primitive()
.as_::<u16>()
.vortex_expect("left_code must be non-null");
let dictionary = array.left_parts_dictionary();
*dictionary
.get(usize::from(left_code))
.ok_or_else(|| code_not_in_dictionary(left_code, dictionary.len()))?
}
};

// combine left and right values
Ok(if array.dtype().as_ptype() == PType::F32 {
let right: u32 = array
.right_parts()
.execute_scalar(index, ctx)?
.as_primitive()
.as_::<u32>()
.vortex_expect("non-null");
let packed = f32::from_bits((left as u32) << array.right_bit_width() | right);
Scalar::primitive(packed, array.dtype().nullability())
} else {
let right: u64 = array
.right_parts()
read_valid(&mut ProbeState::once(array), index, ctx)
}
}

/// Read the valid row at `index`, joining its left part, patched or from the dictionary, with
/// its right part.
fn read_valid(
state: &mut ProbeState<'_, ALPRD>,
index: usize,
ctx: &mut ExecutionCtx,
) -> VortexResult<Scalar> {
let array = state.array();
// The left value can either be a direct value, or an exception.
// The exceptions array represents exception positions with non-null values.
let maybe_patched_value = match array.left_parts_patches() {
Some(patches) => patches.probe_patched(state, LP_PATCH_SLOTS, index, ctx)?,
None => None,
};
let left = match maybe_patched_value {
Some(patched_value) => patched_value
.as_primitive()
.as_::<u16>()
.vortex_expect("patched values must be non-null"),
_ => {
let left_code: u16 = array
.left_parts()
.execute_scalar(index, ctx)?
.as_primitive()
.as_::<u64>()
.vortex_expect("non-null");
let packed = f64::from_bits(((left as u64) << array.right_bit_width()) | right);
Scalar::primitive(packed, array.dtype().nullability())
})
}
.as_::<u16>()
.vortex_expect("left_code must be non-null");
let dictionary = array.left_parts_dictionary();
*dictionary
.get(usize::from(left_code))
.ok_or_else(|| code_not_in_dictionary(left_code, dictionary.len()))?
}
};

// combine left and right values
Ok(if array.dtype().as_ptype() == PType::F32 {
let right: u32 = array
.right_parts()
.execute_scalar(index, ctx)?
.as_primitive()
.as_::<u32>()
.vortex_expect("non-null");
let packed = f32::from_bits((left as u32) << array.right_bit_width() | right);
Scalar::primitive(packed, array.dtype().nullability())
} else {
let right: u64 = array
.right_parts()
.execute_scalar(index, ctx)?
.as_primitive()
.as_::<u64>()
.vortex_expect("non-null");
let packed = f64::from_bits(((left as u64) << array.right_bit_width()) | right);
Scalar::primitive(packed, array.dtype().nullability())
})
}

#[cfg(test)]
Expand Down
5 changes: 5 additions & 0 deletions encodings/fastlanes/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ vortex-alp = { path = "../alp" }
vortex-array = { workspace = true, features = ["_test-harness"] }
vortex-bench-support = { workspace = true }
vortex-fastlanes = { path = ".", features = ["_test-harness"] }
vortex-sparse = { workspace = true }

[features]
_test-harness = ["dep:rand"]
Expand Down Expand Up @@ -98,3 +99,7 @@ harness = false
[[bench]]
name = "for_decode"
harness = false

[[bench]]
name = "patched_search"
harness = false
Loading
Loading