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
10 changes: 6 additions & 4 deletions encodings/alp/public-api.lock
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@ impl vortex_array::arrays::filter::kernel::FilterKernel for vortex_alp::ALPRDVTa
pub fn vortex_alp::ALPRDVTable::filter(array: &vortex_alp::ALPRDArray, mask: &vortex_mask::Mask, _ctx: &mut vortex_array::executor::ExecutionCtx) -> vortex_error::VortexResult<core::option::Option<vortex_array::array::ArrayRef>>
impl vortex_array::arrays::slice::SliceKernel for vortex_alp::ALPRDVTable
pub fn vortex_alp::ALPRDVTable::slice(array: &Self::Array, range: core::ops::range::Range<usize>, _ctx: &mut vortex_array::executor::ExecutionCtx) -> vortex_error::VortexResult<core::option::Option<vortex_array::array::ArrayRef>>
impl vortex_array::compute::cast::CastKernel for vortex_alp::ALPRDVTable
pub fn vortex_alp::ALPRDVTable::cast(&self, array: &vortex_alp::ALPRDArray, dtype: &vortex_dtype::dtype::DType) -> vortex_error::VortexResult<core::option::Option<vortex_array::array::ArrayRef>>
impl vortex_array::compute::cast::CastReduce for vortex_alp::ALPRDVTable
pub fn vortex_alp::ALPRDVTable::cast(array: &vortex_alp::ALPRDArray, dtype: &vortex_dtype::dtype::DType) -> vortex_error::VortexResult<core::option::Option<vortex_array::array::ArrayRef>>
impl vortex_array::compute::mask::MaskKernel for vortex_alp::ALPRDVTable
pub fn vortex_alp::ALPRDVTable::mask(&self, array: &vortex_alp::ALPRDArray, filter_mask: &vortex_mask::Mask) -> vortex_error::VortexResult<vortex_array::array::ArrayRef>
impl vortex_array::vtable::VTable for vortex_alp::ALPRDVTable
Expand All @@ -96,6 +96,7 @@ pub fn vortex_alp::ALPRDVTable::execute(array: &Self::Array, ctx: &mut vortex_ar
pub fn vortex_alp::ALPRDVTable::execute_parent(array: &Self::Array, parent: &vortex_array::array::ArrayRef, child_idx: usize, ctx: &mut vortex_array::executor::ExecutionCtx) -> vortex_error::VortexResult<core::option::Option<vortex_array::array::ArrayRef>>
pub fn vortex_alp::ALPRDVTable::id(_array: &Self::Array) -> vortex_array::vtable::dyn_::ArrayId
pub fn vortex_alp::ALPRDVTable::metadata(array: &vortex_alp::ALPRDArray) -> vortex_error::VortexResult<Self::Metadata>
pub fn vortex_alp::ALPRDVTable::reduce_parent(array: &Self::Array, parent: &vortex_array::array::ArrayRef, child_idx: usize) -> vortex_error::VortexResult<core::option::Option<vortex_array::array::ArrayRef>>
pub fn vortex_alp::ALPRDVTable::serialize(metadata: Self::Metadata) -> vortex_error::VortexResult<core::option::Option<alloc::vec::Vec<u8>>>
pub fn vortex_alp::ALPRDVTable::with_children(array: &mut Self::Array, children: alloc::vec::Vec<vortex_array::array::ArrayRef>) -> vortex_error::VortexResult<()>
impl vortex_array::vtable::array::BaseArrayVTable<vortex_alp::ALPRDVTable> for vortex_alp::ALPRDVTable
Expand Down Expand Up @@ -126,8 +127,8 @@ impl vortex_array::arrays::slice::SliceKernel for vortex_alp::ALPVTable
pub fn vortex_alp::ALPVTable::slice(array: &Self::Array, range: core::ops::range::Range<usize>, _ctx: &mut vortex_array::executor::ExecutionCtx) -> vortex_error::VortexResult<core::option::Option<vortex_array::array::ArrayRef>>
impl vortex_array::compute::between::BetweenKernel for vortex_alp::ALPVTable
pub fn vortex_alp::ALPVTable::between(&self, array: &vortex_alp::ALPArray, lower: &dyn vortex_array::array::Array, upper: &dyn vortex_array::array::Array, options: &vortex_array::compute::between::BetweenOptions) -> vortex_error::VortexResult<core::option::Option<vortex_array::array::ArrayRef>>
impl vortex_array::compute::cast::CastKernel for vortex_alp::ALPVTable
pub fn vortex_alp::ALPVTable::cast(&self, array: &vortex_alp::ALPArray, dtype: &vortex_dtype::dtype::DType) -> vortex_error::VortexResult<core::option::Option<vortex_array::array::ArrayRef>>
impl vortex_array::compute::cast::CastReduce for vortex_alp::ALPVTable
pub fn vortex_alp::ALPVTable::cast(array: &vortex_alp::ALPArray, dtype: &vortex_dtype::dtype::DType) -> vortex_error::VortexResult<core::option::Option<vortex_array::array::ArrayRef>>
impl vortex_array::compute::compare::CompareKernel for vortex_alp::ALPVTable
pub fn vortex_alp::ALPVTable::compare(&self, lhs: &vortex_alp::ALPArray, rhs: &dyn vortex_array::array::Array, operator: vortex_array::compute::compare::Operator) -> vortex_error::VortexResult<core::option::Option<vortex_array::array::ArrayRef>>
impl vortex_array::compute::mask::MaskKernel for vortex_alp::ALPVTable
Expand All @@ -147,6 +148,7 @@ pub fn vortex_alp::ALPVTable::execute(array: &Self::Array, ctx: &mut vortex_arra
pub fn vortex_alp::ALPVTable::execute_parent(array: &Self::Array, parent: &vortex_array::array::ArrayRef, child_idx: usize, ctx: &mut vortex_array::executor::ExecutionCtx) -> vortex_error::VortexResult<core::option::Option<vortex_array::array::ArrayRef>>
pub fn vortex_alp::ALPVTable::id(_array: &Self::Array) -> vortex_array::vtable::dyn_::ArrayId
pub fn vortex_alp::ALPVTable::metadata(array: &vortex_alp::ALPArray) -> vortex_error::VortexResult<Self::Metadata>
pub fn vortex_alp::ALPVTable::reduce_parent(array: &Self::Array, parent: &vortex_array::array::ArrayRef, child_idx: usize) -> vortex_error::VortexResult<core::option::Option<vortex_array::array::ArrayRef>>
pub fn vortex_alp::ALPVTable::serialize(metadata: Self::Metadata) -> vortex_error::VortexResult<core::option::Option<alloc::vec::Vec<u8>>>
pub fn vortex_alp::ALPVTable::with_children(array: &mut Self::Array, children: alloc::vec::Vec<vortex_array::array::ArrayRef>) -> vortex_error::VortexResult<()>
impl vortex_array::vtable::array::BaseArrayVTable<vortex_alp::ALPVTable> for vortex_alp::ALPVTable
Expand Down
9 changes: 9 additions & 0 deletions encodings/alp/src/alp/array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ use crate::ALPFloat;
use crate::alp::Exponents;
use crate::alp::decompress::execute_decompress;
use crate::alp::rules::PARENT_KERNELS;
use crate::alp::rules::RULES;

vtable!(ALP);

Expand Down Expand Up @@ -174,6 +175,14 @@ impl VTable for ALPVTable {
Ok(execute_decompress(array.clone(), ctx)?.into_array())
}

fn reduce_parent(
array: &Self::Array,
parent: &ArrayRef,
child_idx: usize,
) -> VortexResult<Option<ArrayRef>> {
RULES.evaluate(array, parent, child_idx)
}

fn execute_parent(
array: &Self::Array,
parent: &ArrayRef,
Expand Down
39 changes: 16 additions & 23 deletions encodings/alp/src/alp/compute/cast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,23 @@

use vortex_array::ArrayRef;
use vortex_array::IntoArray;
use vortex_array::compute::CastKernel;
use vortex_array::compute::CastKernelAdapter;
use vortex_array::compute::cast;
use vortex_array::builtins::ArrayBuiltins;
use vortex_array::compute::CastReduce;
use vortex_array::patches::Patches;
use vortex_array::register_kernel;
use vortex_dtype::DType;
use vortex_error::VortexResult;

use crate::alp::ALPArray;
use crate::alp::ALPVTable;

impl CastKernel for ALPVTable {
fn cast(&self, array: &ALPArray, dtype: &DType) -> VortexResult<Option<ArrayRef>> {
impl CastReduce for ALPVTable {
fn cast(array: &ALPArray, dtype: &DType) -> VortexResult<Option<ArrayRef>> {
// Check if this is just a nullability change
if array.dtype().eq_ignore_nullability(dtype) {
// For nullability-only changes, we can avoid decoding
// Cast the encoded array (integers) to handle nullability
let new_encoded = cast(
array.encoded(),
&array
let new_encoded = array.encoded().cast(
array
.encoded()
.dtype()
.with_nullability(dtype.nullability()),
Expand All @@ -38,7 +35,7 @@ impl CastKernel for ALPVTable {
p.array_len(),
p.offset(),
p.indices().clone(),
cast(p.values(), dtype)?,
p.values().cast(dtype.clone())?,
p.chunk_offsets().clone(),
)
}
Expand All @@ -63,16 +60,14 @@ impl CastKernel for ALPVTable {
}
}

register_kernel!(CastKernelAdapter(ALPVTable).lift());

#[cfg(test)]
mod tests {
use rstest::rstest;
use vortex_array::IntoArray;
use vortex_array::ToCanonical;
use vortex_array::arrays::PrimitiveArray;
use vortex_array::assert_arrays_eq;
use vortex_array::compute::cast;
use vortex_array::builtins::ArrayBuiltins;
use vortex_array::compute::conformance::cast::test_cast_conformance;
use vortex_buffer::buffer;
use vortex_dtype::DType;
Expand All @@ -94,9 +89,9 @@ mod tests {
);

let nullable_dtype = DType::Primitive(PType::F32, Nullability::Nullable);
let casted = cast(alp.as_ref(), &nullable_dtype)?;
let casted = alp.to_array().cast(nullable_dtype.clone())?;

let expected = cast(&values, &nullable_dtype)?;
let expected = values.cast(nullable_dtype)?;

assert_arrays_eq!(casted.to_canonical()?.into_primitive(), expected);

Expand All @@ -108,10 +103,9 @@ mod tests {
let values = buffer![1.5f32, 2.5, 3.5, 4.5].into_array();
let alp = alp_encode(&values.to_primitive(), None)?;

let casted = cast(
alp.as_ref(),
&DType::Primitive(PType::F64, Nullability::NonNullable),
)?;
let casted = alp
.to_array()
.cast(DType::Primitive(PType::F64, Nullability::NonNullable))?;
assert_eq!(
casted.dtype(),
&DType::Primitive(PType::F64, Nullability::NonNullable)
Expand All @@ -131,10 +125,9 @@ mod tests {
let values = buffer![1.0f32, 2.0, 3.0, 4.0].into_array();
let alp = alp_encode(&values.to_primitive(), None)?;

let casted = cast(
alp.as_ref(),
&DType::Primitive(PType::I32, Nullability::NonNullable),
)?;
let casted = alp
.to_array()
.cast(DType::Primitive(PType::I32, Nullability::NonNullable))?;
assert_eq!(
casted.dtype(),
&DType::Primitive(PType::I32, Nullability::NonNullable)
Expand Down
5 changes: 5 additions & 0 deletions encodings/alp/src/alp/rules.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
use vortex_array::arrays::FilterExecuteAdaptor;
use vortex_array::arrays::SliceExecuteAdaptor;
use vortex_array::arrays::TakeExecuteAdaptor;
use vortex_array::compute::CastReduceAdaptor;
use vortex_array::kernel::ParentKernelSet;
use vortex_array::optimizer::rules::ParentRuleSet;

use crate::ALPVTable;

Expand All @@ -13,3 +15,6 @@ pub(super) const PARENT_KERNELS: ParentKernelSet<ALPVTable> = ParentKernelSet::n
ParentKernelSet::lift(&SliceExecuteAdaptor(ALPVTable)),
ParentKernelSet::lift(&TakeExecuteAdaptor(ALPVTable)),
]);

pub(super) const RULES: ParentRuleSet<ALPVTable> =
ParentRuleSet::new(&[ParentRuleSet::lift(&CastReduceAdaptor(ALPVTable))]);
16 changes: 15 additions & 1 deletion encodings/alp/src/alp_rd/array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ use vortex_mask::Mask;
use vortex_session::VortexSession;

use crate::alp_rd::kernel::PARENT_KERNELS;
use crate::alp_rd::rules::RULES;
use crate::alp_rd_decode;

vtable!(ALPRD);
Expand Down Expand Up @@ -264,6 +265,14 @@ impl VTable for ALPRDVTable {
Ok(decoded_array.into_array())
}

fn reduce_parent(
array: &Self::Array,
parent: &ArrayRef,
child_idx: usize,
) -> VortexResult<Option<ArrayRef>> {
RULES.evaluate(array, parent, child_idx)
}

fn execute_parent(
array: &Self::Array,
parent: &ArrayRef,
Expand Down Expand Up @@ -338,7 +347,12 @@ impl ALPRDArray {
vortex_bail!("patches must be all valid: {}", patches.values());
}
// TODO(ngates): assert the DType, don't cast it.
patches.cast_values(left_parts.dtype())
// TODO(joe): assert the DType, don't cast it in the next PR.
let mut patches = patches.cast_values(left_parts.dtype())?;
// Force execution of the lazy cast so patch values are materialized
// before serialization.
*patches.values_mut() = patches.values().to_canonical()?.into_array();
Ok(patches)
})
.transpose()?;

Expand Down
44 changes: 18 additions & 26 deletions encodings/alp/src/alp_rd/compute/cast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,25 @@

use vortex_array::ArrayRef;
use vortex_array::IntoArray;
use vortex_array::compute::CastKernel;
use vortex_array::compute::CastKernelAdapter;
use vortex_array::compute::cast;
use vortex_array::register_kernel;
use vortex_array::builtins::ArrayBuiltins;
use vortex_array::compute::CastReduce;
use vortex_dtype::DType;
use vortex_error::VortexResult;

use crate::alp_rd::ALPRDArray;
use crate::alp_rd::ALPRDVTable;

impl CastKernel for ALPRDVTable {
fn cast(&self, array: &ALPRDArray, dtype: &DType) -> VortexResult<Option<ArrayRef>> {
impl CastReduce for ALPRDVTable {
fn cast(array: &ALPRDArray, dtype: &DType) -> VortexResult<Option<ArrayRef>> {
// ALPRDArray stores floating-point values, so only cast between float types
// or if just changing nullability

// Check if this is just a nullability change
if array.dtype().eq_ignore_nullability(dtype) {
// For nullability-only changes, we need to cast the left_parts array
// since it carries the validity information
let new_left_parts = cast(
array.left_parts(),
&array
let new_left_parts = array.left_parts().cast(
array
.left_parts()
.dtype()
.with_nullability(dtype.nullability()),
Expand All @@ -48,14 +45,12 @@ impl CastKernel for ALPRDVTable {
}
}

register_kernel!(CastKernelAdapter(ALPRDVTable).lift());

#[cfg(test)]
mod tests {
use rstest::rstest;
use vortex_array::ToCanonical;
use vortex_array::arrays::PrimitiveArray;
use vortex_array::compute::cast;
use vortex_array::builtins::ArrayBuiltins;
use vortex_array::compute::conformance::cast::test_cast_conformance;
use vortex_dtype::DType;
use vortex_dtype::Nullability;
Expand All @@ -70,11 +65,10 @@ mod tests {
let encoder = RDEncoder::new(&values);
let alprd = encoder.encode(&arr);

let casted = cast(
alprd.as_ref(),
&DType::Primitive(PType::F64, Nullability::NonNullable),
)
.unwrap();
let casted = alprd
.to_array()
.cast(DType::Primitive(PType::F64, Nullability::NonNullable))
.unwrap();
assert_eq!(
casted.dtype(),
&DType::Primitive(PType::F64, Nullability::NonNullable)
Expand All @@ -96,18 +90,16 @@ mod tests {
let alprd = encoder.encode(&arr);

// Cast to NonNullable should fail since we have nulls
let result = cast(
alprd.as_ref(),
&DType::Primitive(PType::F64, Nullability::NonNullable),
);
let result = alprd
.to_array()
.cast(DType::Primitive(PType::F64, Nullability::NonNullable));
assert!(result.is_err());

// Cast to same type with Nullable should succeed
let casted = cast(
alprd.as_ref(),
&DType::Primitive(PType::F64, Nullability::Nullable),
)
.unwrap();
let casted = alprd
.to_array()
.cast(DType::Primitive(PType::F64, Nullability::Nullable))
.unwrap();
assert_eq!(
casted.dtype(),
&DType::Primitive(PType::F64, Nullability::Nullable)
Expand Down
1 change: 1 addition & 0 deletions encodings/alp/src/alp_rd/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ mod array;
mod compute;
mod kernel;
mod ops;
mod rules;
mod slice;

use std::ops::Shl;
Expand Down
10 changes: 10 additions & 0 deletions encodings/alp/src/alp_rd/rules.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// SPDX-License-Identifier: Apache-2.0
// SPDX-FileCopyrightText: Copyright the Vortex contributors

use vortex_array::compute::CastReduceAdaptor;
use vortex_array::optimizer::rules::ParentRuleSet;

use crate::alp_rd::ALPRDVTable;

pub(crate) static RULES: ParentRuleSet<ALPRDVTable> =
ParentRuleSet::new(&[ParentRuleSet::lift(&CastReduceAdaptor(ALPRDVTable))]);
4 changes: 2 additions & 2 deletions encodings/bytebool/public-api.lock
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ impl vortex_array::arrays::dict::take::TakeExecute for vortex_bytebool::ByteBool
pub fn vortex_bytebool::ByteBoolVTable::take(array: &vortex_bytebool::ByteBoolArray, indices: &dyn vortex_array::array::Array, _ctx: &mut vortex_array::executor::ExecutionCtx) -> vortex_error::VortexResult<core::option::Option<vortex_array::array::ArrayRef>>
impl vortex_array::arrays::slice::SliceReduce for vortex_bytebool::ByteBoolVTable
pub fn vortex_bytebool::ByteBoolVTable::slice(array: &vortex_bytebool::ByteBoolArray, range: core::ops::range::Range<usize>) -> vortex_error::VortexResult<core::option::Option<vortex_array::array::ArrayRef>>
impl vortex_array::compute::cast::CastKernel for vortex_bytebool::ByteBoolVTable
pub fn vortex_bytebool::ByteBoolVTable::cast(&self, array: &vortex_bytebool::ByteBoolArray, dtype: &vortex_dtype::dtype::DType) -> vortex_error::VortexResult<core::option::Option<vortex_array::array::ArrayRef>>
impl vortex_array::compute::cast::CastReduce for vortex_bytebool::ByteBoolVTable
pub fn vortex_bytebool::ByteBoolVTable::cast(array: &vortex_bytebool::ByteBoolArray, dtype: &vortex_dtype::dtype::DType) -> vortex_error::VortexResult<core::option::Option<vortex_array::array::ArrayRef>>
impl vortex_array::compute::mask::MaskKernel for vortex_bytebool::ByteBoolVTable
pub fn vortex_bytebool::ByteBoolVTable::mask(&self, array: &vortex_bytebool::ByteBoolArray, mask: &vortex_mask::Mask) -> vortex_error::VortexResult<vortex_array::array::ArrayRef>
impl vortex_array::vtable::VTable for vortex_bytebool::ByteBoolVTable
Expand Down
Loading
Loading