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
9 changes: 6 additions & 3 deletions encodings/alp/benches/alp_compress.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,16 +143,19 @@ fn compress_rd<T: ALPRDFloat + NativePType>(bencher: Bencher, args: (usize, f64)
let encoder = RDEncoder::new(primitive.as_slice::<T>());

bencher
.with_inputs(|| (&primitive, &encoder))
.bench_refs(|(primitive, encoder)| encoder.encode(primitive.as_view()))
.with_inputs(|| (&primitive, &encoder, LEGACY_SESSION.create_execution_ctx()))
.bench_refs(|(primitive, encoder, ctx)| encoder.encode(primitive.as_view(), ctx))
}

#[divan::bench(types = [f32, f64], args = RD_BENCH_ARGS)]
fn decompress_rd<T: ALPRDFloat + NativePType>(bencher: Bencher, args: (usize, f64)) {
let (n, fraction_patch) = args;
let primitive = make_rd_array::<T>(n, fraction_patch);
let encoder = RDEncoder::new(primitive.as_slice::<T>());
let encoded = encoder.encode(primitive.as_view());
let encoded = encoder.encode(
primitive.as_view(),
&mut LEGACY_SESSION.create_execution_ctx(),
);

bencher
.with_inputs(|| (&encoded, LEGACY_SESSION.create_execution_ctx()))
Expand Down
4 changes: 2 additions & 2 deletions encodings/alp/public-api.lock
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ impl vortex_alp::ALPRD

pub unsafe fn vortex_alp::ALPRD::new_unchecked(dtype: vortex_array::dtype::DType, left_parts: vortex_array::array::erased::ArrayRef, left_parts_dictionary: vortex_buffer::buffer::Buffer<u16>, right_parts: vortex_array::array::erased::ArrayRef, right_bit_width: u8, left_parts_patches: core::option::Option<vortex_array::patches::Patches>) -> vortex_alp::ALPRDArray

pub fn vortex_alp::ALPRD::try_new(dtype: vortex_array::dtype::DType, left_parts: vortex_array::array::erased::ArrayRef, left_parts_dictionary: vortex_buffer::buffer::Buffer<u16>, right_parts: vortex_array::array::erased::ArrayRef, right_bit_width: u8, left_parts_patches: core::option::Option<vortex_array::patches::Patches>) -> vortex_error::VortexResult<vortex_alp::ALPRDArray>
pub fn vortex_alp::ALPRD::try_new(dtype: vortex_array::dtype::DType, left_parts: vortex_array::array::erased::ArrayRef, left_parts_dictionary: vortex_buffer::buffer::Buffer<u16>, right_parts: vortex_array::array::erased::ArrayRef, right_bit_width: u8, left_parts_patches: core::option::Option<vortex_array::patches::Patches>, ctx: &mut vortex_array::executor::ExecutionCtx) -> vortex_error::VortexResult<vortex_alp::ALPRDArray>

impl core::clone::Clone for vortex_alp::ALPRD

Expand Down Expand Up @@ -380,7 +380,7 @@ pub struct vortex_alp::RDEncoder

impl vortex_alp::RDEncoder

pub fn vortex_alp::RDEncoder::encode(&self, array: vortex_array::array::view::ArrayView<'_, vortex_array::arrays::primitive::vtable::Primitive>) -> vortex_alp::ALPRDArray
pub fn vortex_alp::RDEncoder::encode(&self, array: vortex_array::array::view::ArrayView<'_, vortex_array::arrays::primitive::vtable::Primitive>, ctx: &mut vortex_array::executor::ExecutionCtx) -> vortex_alp::ALPRDArray

pub fn vortex_alp::RDEncoder::from_parts(right_bit_width: u8, codes: alloc::vec::Vec<u16>) -> Self

Expand Down
18 changes: 4 additions & 14 deletions encodings/alp/src/alp/array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -526,8 +526,6 @@ mod tests {
use vortex_array::Canonical;
use vortex_array::IntoArray;
use vortex_array::LEGACY_SESSION;
#[expect(deprecated)]
use vortex_array::ToCanonical;
use vortex_array::VortexSessionExecute;
use vortex_array::arrays::PrimitiveArray;
use vortex_array::assert_arrays_eq;
Expand Down Expand Up @@ -785,6 +783,7 @@ mod tests {
#[case(1000, 200)]
#[case(2048, 512)]
fn test_sliced_to_primitive(#[case] size: usize, #[case] slice_start: usize) {
let mut ctx = LEGACY_SESSION.create_execution_ctx();
let values: Vec<Option<f64>> = (0..size)
.map(|i| {
if i % 5 == 0 {
Expand All @@ -798,19 +797,13 @@ mod tests {
.collect();

let array = PrimitiveArray::from_option_iter(values.clone());
let encoded = alp_encode(
array.as_view(),
None,
&mut LEGACY_SESSION.create_execution_ctx(),
)
.unwrap();
let encoded = alp_encode(array.as_view(), None, &mut ctx).unwrap();

let slice_end = size - slice_start;
let slice_len = slice_end - slice_start;
let sliced_encoded = encoded.slice(slice_start..slice_end).unwrap();

#[expect(deprecated)]
let result_primitive = sliced_encoded.to_primitive();
let result_primitive = sliced_encoded.execute::<PrimitiveArray>(&mut ctx).unwrap();

for idx in 0..slice_len {
let expected_value = values[slice_start + idx];
Expand All @@ -819,10 +812,7 @@ mod tests {
.as_ref()
.validity()
.unwrap()
.to_mask(
result_primitive.as_ref().len(),
&mut LEGACY_SESSION.create_execution_ctx(),
)
.to_mask(result_primitive.as_ref().len(), &mut ctx)
.unwrap()
.value(idx);
assert_eq!(
Expand Down
162 changes: 88 additions & 74 deletions encodings/alp/src/alp/compress.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,6 @@ mod tests {
use f64::consts::E;
use f64::consts::PI;
use vortex_array::LEGACY_SESSION;
#[expect(deprecated)]
use vortex_array::ToCanonical;
use vortex_array::VortexSessionExecute;
use vortex_array::assert_arrays_eq;
use vortex_array::dtype::NativePType;
Expand Down Expand Up @@ -273,16 +271,14 @@ mod tests {

#[test]
fn roundtrips_all_null() {
let mut ctx = LEGACY_SESSION.create_execution_ctx();
let original =
PrimitiveArray::new(buffer![195.26274f64, PI, -48.815685], Validity::AllInvalid);
let alp_arr = alp_encode(
original.as_view(),
None,
&mut LEGACY_SESSION.create_execution_ctx(),
)
.unwrap();
#[expect(deprecated)]
let decompressed = alp_arr.into_array().to_primitive();
let alp_arr = alp_encode(original.as_view(), None, &mut ctx).unwrap();
let decompressed = alp_arr
.into_array()
.execute::<PrimitiveArray>(&mut ctx)
.unwrap();

assert_eq!(
// The second and third values become exceptions and are replaced
Expand All @@ -295,18 +291,17 @@ mod tests {

#[test]
fn non_finite_numbers() {
let mut ctx = LEGACY_SESSION.create_execution_ctx();
let original = PrimitiveArray::new(
buffer![0.0f32, -0.0, f32::NAN, f32::NEG_INFINITY, f32::INFINITY],
Validity::NonNullable,
);
let encoded = alp_encode(
original.as_view(),
None,
&mut LEGACY_SESSION.create_execution_ctx(),
)
.unwrap();
#[expect(deprecated)]
let decoded = encoded.as_array().to_primitive();
let encoded = alp_encode(original.as_view(), None, &mut ctx).unwrap();
let decoded = encoded
.as_array()
.clone()
.execute::<PrimitiveArray>(&mut ctx)
.unwrap();
for idx in 0..original.len() {
let decoded_val = decoded.as_slice::<f32>()[idx];
let original_val = original.as_slice::<f32>()[idx];
Expand All @@ -319,125 +314,149 @@ mod tests {

#[test]
fn test_chunk_offsets() {
let mut ctx = LEGACY_SESSION.create_execution_ctx();
let mut values = vec![1.0f64; 3072];

values[1023] = PI;
values[1024] = E;
values[1025] = PI;

let array = PrimitiveArray::new(Buffer::from(values), Validity::NonNullable);
let encoded = alp_encode(
array.as_view(),
None,
&mut LEGACY_SESSION.create_execution_ctx(),
)
.unwrap();
let encoded = alp_encode(array.as_view(), None, &mut ctx).unwrap();
let patches = encoded.patches().unwrap();

#[expect(deprecated)]
let chunk_offsets = patches.chunk_offsets().clone().unwrap().to_primitive();
let chunk_offsets = patches
.chunk_offsets()
.clone()
.unwrap()
.execute::<PrimitiveArray>(&mut ctx)
.unwrap();
let expected_offsets = PrimitiveArray::from_iter(vec![0u64, 1, 3]);
assert_arrays_eq!(chunk_offsets, expected_offsets);

#[expect(deprecated)]
let patch_indices = patches.indices().to_primitive();
let patch_indices = patches
.indices()
.clone()
.execute::<PrimitiveArray>(&mut ctx)
.unwrap();
let expected_indices = PrimitiveArray::from_iter(vec![1023u64, 1024, 1025]);
assert_arrays_eq!(patch_indices, expected_indices);

#[expect(deprecated)]
let patch_values = patches.values().to_primitive();
let patch_values = patches
.values()
.clone()
.execute::<PrimitiveArray>(&mut ctx)
.unwrap();
let expected_values = PrimitiveArray::from_iter(vec![PI, E, PI]);
assert_arrays_eq!(patch_values, expected_values);
}

#[test]
fn test_chunk_offsets_no_patches_in_middle() {
let mut ctx = LEGACY_SESSION.create_execution_ctx();
let mut values = vec![1.0f64; 3072];
values[0] = PI;
values[2048] = E;

let array = PrimitiveArray::new(Buffer::from(values), Validity::NonNullable);
let encoded = alp_encode(
array.as_view(),
None,
&mut LEGACY_SESSION.create_execution_ctx(),
)
.unwrap();
let encoded = alp_encode(array.as_view(), None, &mut ctx).unwrap();
let patches = encoded.patches().unwrap();

#[expect(deprecated)]
let chunk_offsets = patches.chunk_offsets().clone().unwrap().to_primitive();
let chunk_offsets = patches
.chunk_offsets()
.clone()
.unwrap()
.execute::<PrimitiveArray>(&mut ctx)
.unwrap();
let expected_offsets = PrimitiveArray::from_iter(vec![0u64, 1, 1]);
assert_arrays_eq!(chunk_offsets, expected_offsets);

#[expect(deprecated)]
let patch_indices = patches.indices().to_primitive();
let patch_indices = patches
.indices()
.clone()
.execute::<PrimitiveArray>(&mut ctx)
.unwrap();
let expected_indices = PrimitiveArray::from_iter(vec![0u64, 2048]);
assert_arrays_eq!(patch_indices, expected_indices);

#[expect(deprecated)]
let patch_values = patches.values().to_primitive();
let patch_values = patches
.values()
.clone()
.execute::<PrimitiveArray>(&mut ctx)
.unwrap();
let expected_values = PrimitiveArray::from_iter(vec![PI, E]);
assert_arrays_eq!(patch_values, expected_values);
}

#[test]
fn test_chunk_offsets_trailing_empty_chunks() {
let mut ctx = LEGACY_SESSION.create_execution_ctx();
let mut values = vec![1.0f64; 3072];
values[0] = PI;

let array = PrimitiveArray::new(Buffer::from(values), Validity::NonNullable);
let encoded = alp_encode(
array.as_view(),
None,
&mut LEGACY_SESSION.create_execution_ctx(),
)
.unwrap();
let encoded = alp_encode(array.as_view(), None, &mut ctx).unwrap();
let patches = encoded.patches().unwrap();

#[expect(deprecated)]
let chunk_offsets = patches.chunk_offsets().clone().unwrap().to_primitive();
let chunk_offsets = patches
.chunk_offsets()
.clone()
.unwrap()
.execute::<PrimitiveArray>(&mut ctx)
.unwrap();
let expected_offsets = PrimitiveArray::from_iter(vec![0u64, 1, 1]);
assert_arrays_eq!(chunk_offsets, expected_offsets);

#[expect(deprecated)]
let patch_indices = patches.indices().to_primitive();
let patch_indices = patches
.indices()
.clone()
.execute::<PrimitiveArray>(&mut ctx)
.unwrap();
let expected_indices = PrimitiveArray::from_iter(vec![0u64]);
assert_arrays_eq!(patch_indices, expected_indices);

#[expect(deprecated)]
let patch_values = patches.values().to_primitive();
let patch_values = patches
.values()
.clone()
.execute::<PrimitiveArray>(&mut ctx)
.unwrap();
let expected_values = PrimitiveArray::from_iter(vec![PI]);
assert_arrays_eq!(patch_values, expected_values);
}

#[test]
fn test_chunk_offsets_single_chunk() {
let mut ctx = LEGACY_SESSION.create_execution_ctx();
let mut values = vec![1.0f64; 512];
values[0] = PI;
values[100] = E;

let array = PrimitiveArray::new(Buffer::from(values), Validity::NonNullable);
let encoded = alp_encode(
array.as_view(),
None,
&mut LEGACY_SESSION.create_execution_ctx(),
)
.unwrap();
let encoded = alp_encode(array.as_view(), None, &mut ctx).unwrap();
let patches = encoded.patches().unwrap();

#[expect(deprecated)]
let chunk_offsets = patches.chunk_offsets().clone().unwrap().to_primitive();
let chunk_offsets = patches
.chunk_offsets()
.clone()
.unwrap()
.execute::<PrimitiveArray>(&mut ctx)
.unwrap();
let expected_offsets = PrimitiveArray::from_iter(vec![0u64]);
assert_arrays_eq!(chunk_offsets, expected_offsets);

#[expect(deprecated)]
let patch_indices = patches.indices().to_primitive();
let patch_indices = patches
.indices()
.clone()
.execute::<PrimitiveArray>(&mut ctx)
.unwrap();
let expected_indices = PrimitiveArray::from_iter(vec![0u64, 100]);
assert_arrays_eq!(patch_indices, expected_indices);

#[expect(deprecated)]
let patch_values = patches.values().to_primitive();
let patch_values = patches
.values()
.clone()
.execute::<PrimitiveArray>(&mut ctx)
.unwrap();
let expected_values = PrimitiveArray::from_iter(vec![PI, E]);
assert_arrays_eq!(patch_values, expected_values);
}
Expand Down Expand Up @@ -526,21 +545,16 @@ mod tests {

#[test]
fn test_slice_half_chunk_nullable_roundtrip() {
let mut ctx = LEGACY_SESSION.create_execution_ctx();
let values = (0..1024)
.map(|i| if i % 3 == 0 { None } else { Some(2.5f32) })
.collect::<Vec<_>>();

let original = PrimitiveArray::from_option_iter(values);
let encoded = alp_encode(
original.as_view(),
None,
&mut LEGACY_SESSION.create_execution_ctx(),
)
.unwrap();
let encoded = alp_encode(original.as_view(), None, &mut ctx).unwrap();

let sliced_alp = encoded.slice(512..1024).unwrap();
#[expect(deprecated)]
let decoded = sliced_alp.to_primitive();
let decoded = sliced_alp.execute::<PrimitiveArray>(&mut ctx).unwrap();

let expected_slice = original.slice(512..1024).unwrap();
assert_arrays_eq!(decoded, expected_slice);
Expand Down
Loading
Loading