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
4 changes: 3 additions & 1 deletion Cargo.lock

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

3 changes: 2 additions & 1 deletion encodings/elias-fano/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,11 @@ vortex-session = { workspace = true }

[dev-dependencies]
divan = { workspace = true }
hegeltest = { workspace = true }
mimalloc = { workspace = true }
rand = { workspace = true }
rstest = { workspace = true }
vortex-array = { workspace = true, features = ["_test-harness"] }
vortex-array = { workspace = true, features = ["_test-harness-hegel"] }

[[bench]]
name = "unary"
Expand Down
74 changes: 74 additions & 0 deletions encodings/elias-fano/src/elias_fano/tests.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// SPDX-License-Identifier: Apache-2.0
// SPDX-FileCopyrightText: Copyright the Vortex contributors

use hegel::TestCase;
use hegel::generators as gs;
use prost::Message;
use rstest::rstest;
use vortex_array::Array;
Expand All @@ -16,13 +18,16 @@ use vortex_array::arrays::PrimitiveArray;
use vortex_array::assert_arrays_eq;
use vortex_array::buffer::BufferHandle;
use vortex_array::compute::conformance::consistency::test_array_consistency;
use vortex_array::compute::conformance::hegel::EncodingCheckOptions;
use vortex_array::compute::conformance::hegel::check_encoding_roundtrip_and_ops;
use vortex_array::dtype::DType;
use vortex_array::dtype::Nullability::NonNullable;
use vortex_array::dtype::PType;
use vortex_array::test_harness::check_metadata;
use vortex_array::validity::Validity;
use vortex_array::vtable::VTable;
use vortex_buffer::buffer;
use vortex_error::VortexExpect;
use vortex_error::VortexResult;
use vortex_error::vortex_err;

Expand Down Expand Up @@ -296,3 +301,72 @@ fn test_elias_fano_metadata() {
.encode_to_vec(),
);
}

#[hegel::test(test_cases = 48, print_blob = true)]
Comment thread
devin-ai-integration[bot] marked this conversation as resolved.
Resolved
fn test_elias_fano_hegel_encoding_harness(tc: TestCase) {
const UNSIGNED_PTYPES: [PType; 4] = [PType::U8, PType::U16, PType::U32, PType::U64];

let mut ctx = SESSION.create_execution_ctx();
let ptype = tc.draw(gs::sampled_from(&UNSIGNED_PTYPES));
let max_val: u64 = match ptype {
PType::U8 => u64::from(u8::MAX),
PType::U16 => u64::from(u16::MAX),
PType::U32 => u64::from(u32::MAX),
PType::U64 => u64::MAX,
_ => unreachable!(),
};
let len = tc.draw(gs::integers::<usize>().max_value(96));
let mut values: Vec<u64> = match tc.draw(gs::integers::<u8>().max_value(3)) {
0 => vec![0; len],
1 => (0..len)
.map(|_| tc.draw(gs::integers::<u64>().max_value(max_val.min(64))))
.collect(),
2 => (0..len)
.map(|_| match tc.draw(gs::integers::<u8>().max_value(5)) {
0 => 0,
1 => max_val,
_ => tc.draw(gs::integers::<u64>().max_value(max_val)),
})
.collect(),
_ => (0..len)
.map(|_| tc.draw(gs::integers::<u64>().max_value(max_val.min(10_000))))
.collect(),
};
values.sort_unstable();

let canonical_prim = primitive(ptype, &values);
let ef = encode(&canonical_prim).vortex_expect("sorted unsigned encodes");

// Exercise both Primitive and Unary `upper` representations.
let encoded = if tc.draw(gs::booleans()) {
let counts = ef
.upper()
.clone()
.execute::<PrimitiveArray>(&mut ctx)
.vortex_expect("execute upper");
if let Some(unary_upper) = unary_encode(counts.as_ref().as_::<Primitive>(), &mut ctx)
.vortex_expect("unary_encode upper")
{
EliasFano::try_new(
unary_upper.into_array(),
ef.lower().clone(),
ef.lower_bits(),
)
.vortex_expect("ef with unary upper")
.into_array()
} else {
ef.into_array()
}
} else {
ef.into_array()
};

check_encoding_roundtrip_and_ops(
&tc,
&encoded,
&canonical_prim.into_array(),
&EncodingCheckOptions::default(),
&mut ctx,
)
.vortex_expect("EliasFano harness check");
}
50 changes: 50 additions & 0 deletions encodings/elias-fano/src/unary/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ use std::hash::Hasher;
use std::iter;
use std::slice;

use hegel::TestCase;
use hegel::generators as gs;
use prost::Message;
use rand::RngExt;
use rand::SeedableRng;
Expand All @@ -27,6 +29,8 @@ use vortex_array::arrays::PrimitiveArray;
use vortex_array::assert_arrays_eq;
use vortex_array::buffer::BufferHandle;
use vortex_array::compute::conformance::consistency::test_array_consistency;
use vortex_array::compute::conformance::hegel::EncodingCheckOptions;
use vortex_array::compute::conformance::hegel::check_encoding_roundtrip_and_ops;
use vortex_array::dtype::DType;
use vortex_array::dtype::Nullability::NonNullable;
use vortex_array::dtype::PType;
Expand All @@ -39,6 +43,7 @@ use vortex_array::vtable::VTable;
use vortex_buffer::BitBuffer;
use vortex_buffer::ByteBuffer;
use vortex_buffer::buffer;
use vortex_error::VortexExpect;
use vortex_error::VortexResult;
use vortex_error::vortex_err;

Expand Down Expand Up @@ -422,3 +427,48 @@ fn test_lazy_slice() -> VortexResult<()> {
assert_arrays_eq!(sliced, expected, &mut SESSION.create_execution_ctx());
check_access(&sliced, &expected, 0x51CE)
}

#[hegel::test(test_cases = 48, print_blob = true)]
fn test_unary_hegel_encoding_harness(tc: TestCase) {
const UNSIGNED_PTYPES: [PType; 4] = [PType::U8, PType::U16, PType::U32, PType::U64];

let mut ctx = SESSION.create_execution_ctx();
let ptype = tc.draw(gs::sampled_from(&UNSIGNED_PTYPES));
let len = tc.draw(gs::integers::<usize>().max_value(96));
let cap = u64::try_from((ptype.bit_width() - 1).min(24)).vortex_expect("fits u64");
let values: Vec<u64> = match tc.draw(gs::integers::<u8>().max_value(2)) {
0 => vec![0; len],
1 => (0..len)
.map(|_| tc.draw(gs::integers::<u64>().max_value(cap.min(3))))
.collect(),
_ => (0..len)
.map(|_| tc.draw(gs::integers::<u64>().max_value(cap)))
.collect(),
};
let canonical_prim = primitive(ptype, &values);
let unary = unary_encode(canonical_prim.as_ref().as_::<Primitive>(), &mut ctx)
.vortex_expect("unary_encode")
.vortex_expect("bounded values must unary-encode");

// Half the time shift the bit buffer by a non-zero bit offset so sliced-bit paths run too.
let encoded = if tc.draw(gs::booleans()) {
let bit_offset = tc.draw(gs::integers::<usize>().min_value(1).max_value(15));
let shifted: BitBuffer = iter::repeat_n(false, bit_offset)
.chain(unary.to_bit_buffer().iter())
.collect();
Unary::try_new(shifted.slice(bit_offset..), ptype, len)
.vortex_expect("shifted unary")
.into_array()
} else {
unary.into_array()
};

check_encoding_roundtrip_and_ops(
&tc,
&encoded,
&canonical_prim.into_array(),
&EncodingCheckOptions::default(),
&mut ctx,
)
.vortex_expect("Unary harness check");
}
3 changes: 2 additions & 1 deletion encodings/onpair/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,10 @@ _test-harness = ["vortex-array/_test-harness"]

[dev-dependencies]
divan = { workspace = true }
hegeltest = { workspace = true }
mimalloc = { workspace = true }
rstest = { workspace = true }
vortex-array = { workspace = true, features = ["_test-harness"] }
vortex-array = { workspace = true, features = ["_test-harness-hegel"] }

[[bench]]
name = "decode"
Expand Down
Loading
Loading