Skip to content
12 changes: 9 additions & 3 deletions encodings/alp/benches/alp_compress.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,14 @@ fn compress_alp<T: ALPFloat + NativePType>(bencher: Bencher, args: (usize, f64,
let values = values.freeze();
let array = PrimitiveArray::new(values, validity);

bencher
.with_inputs(|| &array)
.bench_values(|array| alp_encode(array.as_view(), None).unwrap())
bencher.with_inputs(|| &array).bench_values(|array| {
alp_encode(
array.as_view(),
None,
&mut LEGACY_SESSION.create_execution_ctx(),
)
.unwrap()
})
}

#[divan::bench(types = [f32, f64], args = BENCH_ARGS)]
Expand All @@ -95,6 +100,7 @@ fn decompress_alp<T: ALPFloat + NativePType>(bencher: Bencher, args: (usize, f64
alp_encode(
PrimitiveArray::new(Buffer::copy_from(&values), validity.clone()).as_view(),
None,
&mut LEGACY_SESSION.create_execution_ctx(),
)
.unwrap(),
LEGACY_SESSION.create_execution_ctx(),
Expand Down
2 changes: 1 addition & 1 deletion encodings/alp/public-api.lock
Original file line number Diff line number Diff line change
Expand Up @@ -636,7 +636,7 @@ pub fn f64::to_bits(value: Self) -> Self::UINT

pub fn f64::to_u16(bits: Self::UINT) -> u16

pub fn vortex_alp::alp_encode(parray: vortex_array::array::view::ArrayView<'_, vortex_array::arrays::primitive::vtable::Primitive>, exponents: core::option::Option<vortex_alp::Exponents>) -> vortex_error::VortexResult<vortex_alp::ALPArray>
pub fn vortex_alp::alp_encode(parray: vortex_array::array::view::ArrayView<'_, vortex_array::arrays::primitive::vtable::Primitive>, exponents: core::option::Option<vortex_alp::Exponents>, ctx: &mut vortex_array::executor::ExecutionCtx) -> vortex_error::VortexResult<vortex_alp::ALPArray>

pub fn vortex_alp::alp_rd_decode<T: vortex_alp::ALPRDFloat>(left_parts: vortex_buffer::buffer_mut::BufferMut<u16>, left_parts_dict: &[u16], right_bit_width: u8, right_parts: vortex_buffer::buffer_mut::BufferMut<<T as vortex_alp::ALPRDFloat>::UINT>, left_parts_patches: core::option::Option<vortex_array::patches::Patches>, ctx: &mut vortex_array::executor::ExecutionCtx) -> vortex_error::VortexResult<vortex_buffer::buffer::Buffer<T>>

Expand Down
64 changes: 54 additions & 10 deletions encodings/alp/src/alp/array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -552,11 +552,11 @@ mod tests {
#[case(2048)]
#[case(2049)]
fn test_execute_f32(#[case] size: usize) {
let mut ctx = SESSION.create_execution_ctx();
let values = PrimitiveArray::from_iter((0..size).map(|i| i as f32));
let encoded = alp_encode(values.as_view(), None).unwrap();
let encoded = alp_encode(values.as_view(), None, &mut ctx).unwrap();

let result_canonical = {
let mut ctx = SESSION.create_execution_ctx();
encoded
.clone()
.into_array()
Expand All @@ -582,7 +582,12 @@ mod tests {
#[case(2049)]
fn test_execute_f64(#[case] size: usize) {
let values = PrimitiveArray::from_iter((0..size).map(|i| i as f64));
let encoded = alp_encode(values.as_view(), None).unwrap();
let encoded = alp_encode(
values.as_view(),
None,
&mut LEGACY_SESSION.create_execution_ctx(),
)
.unwrap();

let result_canonical = {
let mut ctx = SESSION.create_execution_ctx();
Expand Down Expand Up @@ -616,7 +621,12 @@ mod tests {
.collect();

let array = PrimitiveArray::from_iter(values);
let encoded = alp_encode(array.as_view(), None).unwrap();
let encoded = alp_encode(
array.as_view(),
None,
&mut LEGACY_SESSION.create_execution_ctx(),
)
.unwrap();
assert!(encoded.patches().unwrap().array_len() > 0);

let result_canonical = {
Expand Down Expand Up @@ -650,7 +660,12 @@ mod tests {
.collect();

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

let result_canonical = {
let mut ctx = SESSION.create_execution_ctx();
Expand Down Expand Up @@ -685,7 +700,12 @@ mod tests {
.collect();

let array = PrimitiveArray::from_option_iter(values);
let encoded = alp_encode(array.as_view(), None).unwrap();
let encoded = alp_encode(
array.as_view(),
None,
&mut LEGACY_SESSION.create_execution_ctx(),
)
.unwrap();
assert!(encoded.patches().unwrap().array_len() > 0);

let result_canonical = {
Expand Down Expand Up @@ -721,7 +741,12 @@ mod tests {
.collect();

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

let slice_end = size - slice_start;
let slice_len = slice_end - slice_start;
Expand Down Expand Up @@ -772,7 +797,12 @@ mod tests {
.collect();

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

let slice_end = size - slice_start;
let slice_len = slice_end - slice_start;
Expand All @@ -783,7 +813,16 @@ mod tests {
for idx in 0..slice_len {
let expected_value = values[slice_start + idx];

let result_valid = result_primitive.validity_mask().unwrap().value(idx);
let result_valid = result_primitive
.as_ref()
.validity()
.unwrap()
.to_mask(
result_primitive.as_ref().len(),
&mut LEGACY_SESSION.create_execution_ctx(),
)
.unwrap()
.value(idx);
assert_eq!(
result_valid,
expected_value.is_some(),
Expand Down Expand Up @@ -813,7 +852,12 @@ mod tests {
let original = PrimitiveArray::from_iter(values);

// First encode normally to get a properly formed ALPArray with patches.
let normally_encoded = alp_encode(original.as_view(), None).unwrap();
let normally_encoded = alp_encode(
original.as_view(),
None,
&mut LEGACY_SESSION.create_execution_ctx(),
)
.unwrap();
assert!(
normally_encoded.patches().is_some(),
"Test requires patches to be present"
Expand Down
Loading
Loading