Skip to content
Open
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 CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
* If you encounter clippy errors in tests that should only pertain to production code (e.g., prohibiting panic/unwrap,
possible numerical truncation, etc.), then consider allowing those lints at the test module level.
* Prefer naming test modules `tests`, not `test`.
* Prefer having test return VortexResult<_> and use ? over unwrap.
* Prefer module-scoped imports over function-scoped imports. Only use function-scoped imports in situations where it is
either (a) required, or (b) would be exceptionally verbose otherwise. An example where function-scoped imports is good
is when writing an exhaustive match statement with a branch that matches many cases.
Expand Down
2 changes: 2 additions & 0 deletions Cargo.lock

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

2 changes: 2 additions & 0 deletions encodings/sequence/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ vortex-dtype = { workspace = true }
vortex-error = { workspace = true }
vortex-mask = { workspace = true }
vortex-proto = { workspace = true }
vortex-runend = { workspace = true }
vortex-scalar = { workspace = true }
vortex-vector = { workspace = true }

Expand All @@ -32,6 +33,7 @@ tokio = { workspace = true, features = ["full"] }
vortex-array = { path = "../../vortex-array", features = ["test-harness"] }
vortex-file = { path = "../../vortex-file", features = ["tokio"] }
vortex-layout = { path = "../../vortex-layout" }
vortex-session = { workspace = true }

[lints]
workspace = true
11 changes: 9 additions & 2 deletions encodings/sequence/src/array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ use vortex_vector::VectorMut;
use vortex_vector::VectorMutOps;
use vortex_vector::primitive::PVector;

use crate::kernel::PARENT_KERNELS;

vtable!(Sequence);

#[derive(Clone, prost::Message)]
Expand Down Expand Up @@ -296,9 +298,14 @@ impl VTable for SequenceVTable {
fn execute_parent(
array: &Self::Array,
parent: &ArrayRef,
_child_idx: usize,
_ctx: &mut ExecutionCtx,
child_idx: usize,
ctx: &mut ExecutionCtx,
) -> VortexResult<Option<Vector>> {
// Try parent kernels first (e.g., comparison fusion)
if let Some(result) = PARENT_KERNELS.execute(array, parent, child_idx, ctx)? {
return Ok(Some(result));
}

// Special-case filtered execution.
let Some(filter) = parent.as_opt::<FilterVTable>() else {
return Ok(None);
Expand Down
44 changes: 35 additions & 9 deletions encodings/sequence/src/compute/compare.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,12 @@ impl CompareKernel for SequenceVTable {
}
}

/// Find the index where `base + idx * multiplier == intercept`, if one exists.
///
/// Returns `None` if:
/// - `len` is 0
/// - `intercept` is outside the range of the sequence
/// - `intercept` doesn't fall exactly on a sequence value
pub(crate) fn find_intersection_scalar(
base: PValue,
multiplier: PValue,
Expand All @@ -78,10 +84,8 @@ pub(crate) fn find_intersection_scalar(
) -> Option<usize> {
match_each_integer_ptype!(base.ptype(), |P| {
let intercept = intercept.cast::<P>();

let base = base.cast::<P>();
let multiplier = multiplier.cast::<P>();

find_intersection(base, multiplier, len, intercept)
})
}
Expand All @@ -92,16 +96,38 @@ fn find_intersection<P: NativePType>(
len: usize,
intercept: P,
) -> Option<usize> {
// Array is non-empty here.
let count = <P>::from_usize(len - 1).vortex_expect("idx must fit into type");
if len == 0 {
return None;
}

let count = P::from_usize(len - 1).vortex_expect("idx must fit into type");
let end_element = base + (multiplier * count);

(intercept.is_ge(base)
&& intercept.is_le(end_element)
&& (intercept - base) % multiplier == P::zero())
.then(|| ((intercept - base) / multiplier).to_usize())
.flatten()
// Handle ascending vs descending sequences
let (min_val, max_val) = if multiplier.is_ge(P::zero()) {
(base, end_element)
} else {
(end_element, base)
};

// Check if intercept is in range
if !intercept.is_ge(min_val) || !intercept.is_le(max_val) {
return None;
}

// Handle zero multiplier (constant sequence)
if multiplier == P::zero() {
return (intercept == base).then_some(0);
}

// Check if (intercept - base) is evenly divisible by multiplier
let diff = intercept - base;
if diff % multiplier != P::zero() {
return None;
}

let idx = diff / multiplier;
idx.to_usize()
}

#[cfg(test)]
Expand Down
2 changes: 1 addition & 1 deletion encodings/sequence/src/compute/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// SPDX-FileCopyrightText: Copyright the Vortex contributors

mod cast;
mod compare;
pub(crate) mod compare;
mod filter;
mod is_sorted;
mod list_contains;
Expand Down
Loading
Loading