vortex_array/test_harness/
mod.rs1use std::io::Write;
9
10use goldenfile::Mint;
11use goldenfile::differs::binary_diff;
12use itertools::Itertools;
13use vortex_error::VortexResult;
14use vortex_session::VortexSession;
15
16use crate::ArrayRef;
17use crate::ExecutionCtx;
18use crate::arrays::BoolArray;
19use crate::arrays::bool::BoolArrayExt;
20use crate::optimizer::ArrayOptimizer;
21use crate::optimizer::mark_decoded_optimized;
22
23mod execution_paths;
24pub use execution_paths::ExpectedOutcome;
25pub use execution_paths::assert_execution_paths;
26
27#[cfg(not(codspeed))]
28pub mod trace;
29
30#[expect(clippy::unwrap_used)]
34pub fn check_metadata(name: &str, metadata: &[u8]) {
35 let mut mint = Mint::new("goldenfiles/");
36 let mut f = mint
37 .new_goldenfile_with_differ(name, Box::new(binary_diff))
38 .unwrap();
39 f.write_all(metadata).unwrap();
40}
41
42pub fn to_int_indices(indices_bits: BoolArray, ctx: &mut ExecutionCtx) -> VortexResult<Vec<u64>> {
44 let buffer = indices_bits.to_bit_buffer();
45 let mask = indices_bits
46 .as_ref()
47 .validity()?
48 .execute_mask(indices_bits.as_ref().len(), ctx)?;
49 Ok(buffer
50 .iter()
51 .enumerate()
52 .filter_map(|(idx, v)| (v && mask.value(idx)).then_some(idx as u64))
53 .collect_vec())
54}
55
56pub fn mark_optimized(array: &ArrayRef, session: &VortexSession) -> VortexResult<()> {
67 let optimized = array.optimize_ctx(session)?;
68 assert!(
69 ArrayRef::ptr_eq(&optimized, array),
70 "the optimizer rewrote the benchmark input:\n{}\ninto:\n{}",
71 array.display_tree(),
72 optimized.display_tree(),
73 );
74
75 Ok(())
76}
77
78pub fn mark_decoded(array: &ArrayRef) {
84 for node in array.depth_first_traversal() {
85 mark_decoded_optimized(&node);
86 }
87}