Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dynamic compute fns #2639

Merged
merged 11 commits into from
Mar 10, 2025
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
3 changes: 2 additions & 1 deletion bench-vortex/src/bin/notimplemented.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use vortex::arrays::{
VarBinViewArray,
};
use vortex::buffer::buffer;
use vortex::compute::Filter;
use vortex::dtype::datetime::{TIME_ID, TemporalMetadata, TimeUnit};
use vortex::dtype::{DType, ExtDType, Nullability, PType};
use vortex::encodings::alp::{ALPArray, Exponents, RDEncoder};
Expand Down Expand Up @@ -170,7 +171,7 @@ fn compute_funcs(encodings: &[ArrayRef]) {
encoding.compare_fn().is_some(),
encoding.fill_forward_fn().is_some(),
encoding.fill_null_fn().is_some(),
encoding.filter_fn().is_some(),
arr.find_kernel(&Filter).is_some(),
encoding.scalar_at_fn().is_some(),
encoding.binary_numeric_fn().is_some(),
encoding.search_sorted_fn().is_some(),
Expand Down
15 changes: 7 additions & 8 deletions encodings/alp/src/alp/compute/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,22 @@ use std::fmt::Debug;

use vortex_array::arrays::ConstantArray;
use vortex_array::compute::{
BetweenFn, BetweenOptions, CompareFn, FilterFn, ScalarAtFn, SliceFn, StrictComparison, TakeFn,
between, filter, scalar_at, slice, take,
BetweenFn, BetweenOptions, CompareFn, FilterKernel, FilterKernelAdapter, KernelRef, ScalarAtFn,
SliceFn, StrictComparison, TakeFn, between, filter, scalar_at, slice, take,
};
use vortex_array::variants::PrimitiveArrayTrait;
use vortex_array::vtable::ComputeVTable;
use vortex_array::{Array, ArrayRef};
use vortex_array::{Array, ArrayComputeImpl, ArrayRef};
use vortex_dtype::NativePType;
use vortex_error::VortexResult;
use vortex_mask::Mask;
use vortex_scalar::{Scalar, ScalarType};

use crate::{ALPArray, ALPEncoding, ALPFloat, match_each_alp_float_ptype};

impl ArrayComputeImpl for ALPArray {
const FILTER: Option<KernelRef> = FilterKernelAdapter(ALPEncoding).some();
}
impl ComputeVTable for ALPEncoding {
fn between_fn(&self) -> Option<&dyn BetweenFn<&dyn Array>> {
Some(self)
Expand All @@ -26,10 +29,6 @@ impl ComputeVTable for ALPEncoding {
Some(self)
}

fn filter_fn(&self) -> Option<&dyn FilterFn<&dyn Array>> {
Some(self)
}

fn scalar_at_fn(&self) -> Option<&dyn ScalarAtFn<&dyn Array>> {
Some(self)
}
Expand Down Expand Up @@ -102,7 +101,7 @@ impl SliceFn<&ALPArray> for ALPEncoding {
}
}

impl FilterFn<&ALPArray> for ALPEncoding {
impl FilterKernel for ALPEncoding {
fn filter(&self, array: &ALPArray, mask: &Mask) -> VortexResult<ArrayRef> {
let patches = array
.patches()
Expand Down
4 changes: 2 additions & 2 deletions encodings/alp/src/alp_rd/compute/filter.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
use vortex_array::compute::{FilterFn, filter};
use vortex_array::compute::{FilterKernel, filter};
use vortex_array::{Array, ArrayRef};
use vortex_error::VortexResult;
use vortex_mask::Mask;

use crate::{ALPRDArray, ALPRDEncoding};

impl FilterFn<&ALPRDArray> for ALPRDEncoding {
impl FilterKernel for ALPRDEncoding {
fn filter(&self, array: &ALPRDArray, mask: &Mask) -> VortexResult<ArrayRef> {
let left_parts_exceptions = array
.left_parts_patches()
Expand Down
14 changes: 7 additions & 7 deletions encodings/alp/src/alp_rd/compute/mod.rs
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
use vortex_array::Array;
use vortex_array::compute::{FilterFn, MaskFn, ScalarAtFn, SliceFn, TakeFn};
use vortex_array::compute::{FilterKernelAdapter, KernelRef, MaskFn, ScalarAtFn, SliceFn, TakeFn};
use vortex_array::vtable::ComputeVTable;
use vortex_array::{Array, ArrayComputeImpl};

use crate::ALPRDEncoding;
use crate::{ALPRDArray, ALPRDEncoding};

mod filter;
mod mask;
mod scalar_at;
mod slice;
mod take;

impl ComputeVTable for ALPRDEncoding {
fn filter_fn(&self) -> Option<&dyn FilterFn<&dyn Array>> {
Some(self)
}
impl ArrayComputeImpl for ALPRDArray {
const FILTER: Option<KernelRef> = FilterKernelAdapter(ALPRDEncoding).some();
}

impl ComputeVTable for ALPRDEncoding {
fn mask_fn(&self) -> Option<&dyn MaskFn<&dyn Array>> {
Some(self)
}
Expand Down
4 changes: 3 additions & 1 deletion encodings/bytebool/src/compute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,16 @@ use vortex_array::compute::{FillForwardFn, MaskFn, ScalarAtFn, SliceFn, TakeFn};
use vortex_array::validity::Validity;
use vortex_array::variants::PrimitiveArrayTrait;
use vortex_array::vtable::ComputeVTable;
use vortex_array::{Array, ArrayRef, ToCanonical};
use vortex_array::{Array, ArrayComputeImpl, ArrayRef, ToCanonical};
use vortex_dtype::{Nullability, match_each_integer_ptype};
use vortex_error::{VortexResult, vortex_err};
use vortex_mask::Mask;
use vortex_scalar::Scalar;

use super::{ByteBoolArray, ByteBoolEncoding};

impl ArrayComputeImpl for ByteBoolArray {}

impl ComputeVTable for ByteBoolEncoding {
fn fill_forward_fn(&self) -> Option<&dyn FillForwardFn<&dyn Array>> {
None
Expand Down
4 changes: 2 additions & 2 deletions encodings/datetime-parts/src/compute/filter.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
use vortex_array::compute::{FilterFn, filter};
use vortex_array::compute::{FilterKernel, filter};
use vortex_array::{Array, ArrayRef};
use vortex_error::VortexResult;
use vortex_mask::Mask;

use crate::{DateTimePartsArray, DateTimePartsEncoding};

impl FilterFn<&DateTimePartsArray> for DateTimePartsEncoding {
impl FilterKernel for DateTimePartsEncoding {
fn filter(&self, array: &DateTimePartsArray, mask: &Mask) -> VortexResult<ArrayRef> {
Ok(DateTimePartsArray::try_new(
array.dtype().clone(),
Expand Down
13 changes: 7 additions & 6 deletions encodings/datetime-parts/src/compute/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@ mod is_constant;
mod take;

use vortex_array::compute::{
CastFn, CompareFn, FilterFn, IsConstantFn, ScalarAtFn, SliceFn, TakeFn, scalar_at, slice,
CastFn, CompareFn, FilterKernelAdapter, IsConstantFn, KernelRef, ScalarAtFn, SliceFn, TakeFn,
scalar_at, slice,
};
use vortex_array::vtable::ComputeVTable;
use vortex_array::{Array, ArrayRef};
use vortex_array::{Array, ArrayComputeImpl, ArrayRef};
use vortex_dtype::Nullability::{NonNullable, Nullable};
use vortex_dtype::datetime::TemporalMetadata;
use vortex_dtype::{DType, PType};
Expand All @@ -18,6 +19,10 @@ use vortex_scalar::Scalar;
use crate::timestamp::{self, TimestampParts};
use crate::{DateTimePartsArray, DateTimePartsEncoding};

impl ArrayComputeImpl for DateTimePartsArray {
const FILTER: Option<KernelRef> = FilterKernelAdapter(DateTimePartsEncoding).some();
}

impl ComputeVTable for DateTimePartsEncoding {
fn cast_fn(&self) -> Option<&dyn CastFn<&dyn Array>> {
Some(self)
Expand All @@ -27,10 +32,6 @@ impl ComputeVTable for DateTimePartsEncoding {
Some(self)
}

fn filter_fn(&self) -> Option<&dyn FilterFn<&dyn Array>> {
Some(self)
}

fn is_constant_fn(&self) -> Option<&dyn IsConstantFn<&dyn Array>> {
Some(self)
}
Expand Down
16 changes: 8 additions & 8 deletions encodings/dict/src/compute/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,21 @@ mod is_sorted;
mod like;

use vortex_array::compute::{
BinaryNumericFn, CompareFn, FilterFn, IsConstantFn, IsSortedFn, LikeFn, ScalarAtFn, SliceFn,
TakeFn, filter, scalar_at, slice, take,
BinaryNumericFn, CompareFn, FilterKernel, FilterKernelAdapter, IsConstantFn, IsSortedFn,
KernelRef, LikeFn, ScalarAtFn, SliceFn, TakeFn, filter, scalar_at, slice, take,
};
use vortex_array::vtable::ComputeVTable;
use vortex_array::{Array, ArrayRef};
use vortex_array::{Array, ArrayComputeImpl, ArrayRef};
use vortex_error::VortexResult;
use vortex_mask::Mask;
use vortex_scalar::Scalar;

use crate::{DictArray, DictEncoding};

impl ArrayComputeImpl for DictArray {
const FILTER: Option<KernelRef> = FilterKernelAdapter(DictEncoding).some();
}

impl ComputeVTable for DictEncoding {
fn binary_numeric_fn(&self) -> Option<&dyn BinaryNumericFn<&dyn Array>> {
Some(self)
Expand All @@ -33,10 +37,6 @@ impl ComputeVTable for DictEncoding {
Some(self)
}

fn filter_fn(&self) -> Option<&dyn FilterFn<&dyn Array>> {
Some(self)
}

fn like_fn(&self) -> Option<&dyn LikeFn<&dyn Array>> {
Some(self)
}
Expand Down Expand Up @@ -68,7 +68,7 @@ impl TakeFn<&DictArray> for DictEncoding {
}
}

impl FilterFn<&DictArray> for DictEncoding {
impl FilterKernel for DictEncoding {
fn filter(&self, array: &DictArray, mask: &Mask) -> VortexResult<ArrayRef> {
let codes = filter(array.codes(), mask)?;
DictArray::try_new(codes, array.values().clone()).map(|a| a.into_array())
Expand Down
4 changes: 2 additions & 2 deletions encodings/fastlanes/src/bitpacking/compute/filter.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use arrow_buffer::ArrowNativeType;
use fastlanes::BitPacking;
use vortex_array::arrays::PrimitiveArray;
use vortex_array::compute::{FilterFn, filter};
use vortex_array::compute::{FilterKernel, filter};
use vortex_array::variants::PrimitiveArrayTrait;
use vortex_array::{Array, ArrayRef, ToCanonical};
use vortex_buffer::{Buffer, BufferMut};
Expand All @@ -13,7 +13,7 @@ use super::chunked_indices;
use crate::bitpacking::compute::take::UNPACK_CHUNK_THRESHOLD;
use crate::{BitPackedArray, BitPackedEncoding};

impl FilterFn<&BitPackedArray> for BitPackedEncoding {
impl FilterKernel for BitPackedEncoding {
fn filter(&self, array: &BitPackedArray, mask: &Mask) -> VortexResult<ArrayRef> {
let primitive = match_each_unsigned_integer_ptype!(array.ptype().to_unsigned(), |$I| {
filter_primitive::<$I>(array, mask)
Expand Down
15 changes: 8 additions & 7 deletions encodings/fastlanes/src/bitpacking/compute/mod.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
use vortex_array::compute::{
BetweenFn, BetweenOptions, FilterFn, ScalarAtFn, SearchSortedFn, SliceFn, TakeFn, between,
BetweenFn, BetweenOptions, FilterKernelAdapter, KernelRef, ScalarAtFn, SearchSortedFn, SliceFn,
TakeFn, between,
};
use vortex_array::vtable::ComputeVTable;
use vortex_array::{Array, ArrayRef, IntoArray};
use vortex_array::{Array, ArrayComputeImpl, ArrayRef, IntoArray};
use vortex_error::VortexResult;

use crate::{BitPackedArray, BitPackedEncoding};
Expand All @@ -13,8 +14,12 @@ mod search_sorted;
mod slice;
mod take;

impl ArrayComputeImpl for BitPackedArray {
const FILTER: Option<KernelRef> = FilterKernelAdapter(BitPackedEncoding).some();
}

impl ComputeVTable for BitPackedEncoding {
fn filter_fn(&self) -> Option<&dyn FilterFn<&dyn Array>> {
fn between_fn(&self) -> Option<&dyn BetweenFn<&dyn Array>> {
Some(self)
}

Expand All @@ -33,10 +38,6 @@ impl ComputeVTable for BitPackedEncoding {
fn take_fn(&self) -> Option<&dyn TakeFn<&dyn Array>> {
Some(self)
}

fn between_fn(&self) -> Option<&dyn BetweenFn<&dyn Array>> {
Some(self)
}
}

fn chunked_indices<F: FnMut(usize, &[usize])>(
Expand Down
4 changes: 3 additions & 1 deletion encodings/fastlanes/src/delta/compute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@ use std::cmp::min;

use vortex_array::compute::{ScalarAtFn, SliceFn, scalar_at, slice};
use vortex_array::vtable::ComputeVTable;
use vortex_array::{Array, ArrayRef, ToCanonical};
use vortex_array::{Array, ArrayComputeImpl, ArrayRef, ToCanonical};
use vortex_error::VortexResult;
use vortex_scalar::Scalar;

use crate::{DeltaArray, DeltaEncoding};

impl ArrayComputeImpl for DeltaArray {}

impl ComputeVTable for DeltaEncoding {
fn scalar_at_fn(&self) -> Option<&dyn ScalarAtFn<&dyn Array>> {
Some(self)
Expand Down
17 changes: 9 additions & 8 deletions encodings/fastlanes/src/for/compute/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,29 @@ use std::ops::AddAssign;

use num_traits::{CheckedShl, CheckedShr, WrappingAdd, WrappingSub};
use vortex_array::compute::{
CompareFn, FilterFn, ScalarAtFn, SearchResult, SearchSortedFn, SearchSortedSide, SliceFn,
TakeFn, filter, scalar_at, search_sorted, slice, take,
CompareFn, FilterKernel, FilterKernelAdapter, KernelRef, ScalarAtFn, SearchResult,
SearchSortedFn, SearchSortedSide, SliceFn, TakeFn, filter, scalar_at, search_sorted, slice,
take,
};
use vortex_array::variants::PrimitiveArrayTrait;
use vortex_array::vtable::ComputeVTable;
use vortex_array::{Array, ArrayRef};
use vortex_array::{Array, ArrayComputeImpl, ArrayRef};
use vortex_dtype::{NativePType, match_each_integer_ptype};
use vortex_error::{VortexError, VortexExpect as _, VortexResult};
use vortex_mask::Mask;
use vortex_scalar::{PValue, Scalar};

use crate::{FoRArray, FoREncoding};

impl ArrayComputeImpl for FoRArray {
const FILTER: Option<KernelRef> = FilterKernelAdapter(FoREncoding).some();
}

impl ComputeVTable for FoREncoding {
fn compare_fn(&self) -> Option<&dyn CompareFn<&dyn Array>> {
Some(self)
}

fn filter_fn(&self) -> Option<&dyn FilterFn<&dyn Array>> {
Some(self)
}

fn scalar_at_fn(&self) -> Option<&dyn ScalarAtFn<&dyn Array>> {
Some(self)
}
Expand Down Expand Up @@ -53,7 +54,7 @@ impl TakeFn<&FoRArray> for FoREncoding {
}
}

impl FilterFn<&FoRArray> for FoREncoding {
impl FilterKernel for FoREncoding {
fn filter(&self, array: &FoRArray, mask: &Mask) -> VortexResult<ArrayRef> {
FoRArray::try_new(
filter(array.encoded(), mask)?,
Expand Down
14 changes: 7 additions & 7 deletions encodings/fsst/src/compute/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,26 @@ mod compare;
use vortex_array::arrays::varbin_scalar;
use vortex_array::builders::ArrayBuilder;
use vortex_array::compute::{
CompareFn, FilterFn, ScalarAtFn, SliceFn, TakeFn, filter, scalar_at, slice, take,
CompareFn, FilterKernel, FilterKernelAdapter, KernelRef, ScalarAtFn, SliceFn, TakeFn, filter,
scalar_at, slice, take,
};
use vortex_array::vtable::ComputeVTable;
use vortex_array::{Array, ArrayRef};
use vortex_array::{Array, ArrayComputeImpl, ArrayRef};
use vortex_buffer::ByteBuffer;
use vortex_error::{VortexResult, vortex_err};
use vortex_mask::Mask;
use vortex_scalar::Scalar;

use crate::{FSSTArray, FSSTEncoding};

impl ArrayComputeImpl for FSSTArray {
const FILTER: Option<KernelRef> = FilterKernelAdapter(FSSTEncoding).some();
}
impl ComputeVTable for FSSTEncoding {
fn compare_fn(&self) -> Option<&dyn CompareFn<&dyn Array>> {
Some(self)
}

fn filter_fn(&self) -> Option<&dyn FilterFn<&dyn Array>> {
Some(self)
}

fn scalar_at_fn(&self) -> Option<&dyn ScalarAtFn<&dyn Array>> {
Some(self)
}
Expand Down Expand Up @@ -89,7 +89,7 @@ impl ScalarAtFn<&FSSTArray> for FSSTEncoding {
}
}

impl FilterFn<&FSSTArray> for FSSTEncoding {
impl FilterKernel for FSSTEncoding {
// Filtering an FSSTArray filters the codes array, leaving the symbols array untouched
fn filter(&self, array: &FSSTArray, mask: &Mask) -> VortexResult<ArrayRef> {
Ok(FSSTArray::try_new(
Expand Down
4 changes: 2 additions & 2 deletions encodings/runend/src/compute/filter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use std::ops::AddAssign;
use arrow_buffer::BooleanBuffer;
use num_traits::AsPrimitive;
use vortex_array::arrays::PrimitiveArray;
use vortex_array::compute::{FilterFn, filter};
use vortex_array::compute::{FilterKernel, filter};
use vortex_array::validity::Validity;
use vortex_array::variants::PrimitiveArrayTrait;
use vortex_array::{Array, ArrayRef, Canonical, ToCanonical};
Expand All @@ -18,7 +18,7 @@ use crate::{RunEndArray, RunEndEncoding};

const FILTER_TAKE_THRESHOLD: f64 = 0.1;

impl FilterFn<&RunEndArray> for RunEndEncoding {
impl FilterKernel for RunEndEncoding {
fn filter(&self, array: &RunEndArray, mask: &Mask) -> VortexResult<ArrayRef> {
match mask {
Mask::AllTrue(_) => Ok(array.to_array()),
Expand Down
Loading
Loading