From 772ebe8ee4fba62fef0ffe066dbac3d8996d7497 Mon Sep 17 00:00:00 2001 From: Robert Bamler Date: Sun, 6 Nov 2022 23:45:40 +0100 Subject: [PATCH] CI: less expensive miri tests --- src/stream/chain.rs | 4 ++++ src/stream/queue.rs | 26 +++++++++++++++++--------- src/stream/stack.rs | 32 ++++++++++++++++++++------------ 3 files changed, 41 insertions(+), 21 deletions(-) diff --git a/src/stream/chain.rs b/src/stream/chain.rs index 985bae0..86edaed 100644 --- a/src/stream/chain.rs +++ b/src/stream/chain.rs @@ -1255,6 +1255,10 @@ mod tests { f64: AsPrimitive, i32: AsPrimitive, { + #[cfg(miri)] + let (amt_compressed_words, amt_symbols) = + (amt_compressed_words.min(128), amt_symbols.min(100)); + let mut rng = Xoshiro256StarStar::seed_from_u64( (amt_compressed_words as u64).rotate_left(32) ^ amt_symbols as u64, ); diff --git a/src/stream/queue.rs b/src/stream/queue.rs index bb3c020..8a7b859 100644 --- a/src/stream/queue.rs +++ b/src/stream/queue.rs @@ -1160,7 +1160,12 @@ mod tests { f64: AsPrimitive, i32: AsPrimitive, { + #[cfg(not(miri))] const AMT: usize = 1000; + + #[cfg(miri)] + const AMT: usize = 100; + let mut symbols_gaussian = Vec::with_capacity(AMT); let mut means = Vec::with_capacity(AMT); let mut stds = Vec::with_capacity(AMT); @@ -1242,8 +1247,11 @@ mod tests { #[test] fn seek() { - const NUM_CHUNKS: usize = 100; - const SYMBOLS_PER_CHUNK: usize = 100; + #[cfg(not(miri))] + let (num_chunks, symbols_per_chunk) = (100, 100); + + #[cfg(miri)] + let (num_chunks, symbols_per_chunk) = (10, 10); let quantizer = LeakyQuantizer::<_, _, u32, 24>::new(-100..=100); let model = quantizer.quantize(Gaussian::new(0.0, 10.0)); @@ -1251,12 +1259,12 @@ mod tests { let mut encoder = DefaultRangeEncoder::new(); let mut rng = Xoshiro256StarStar::seed_from_u64(123); - let mut symbols = Vec::with_capacity(NUM_CHUNKS); - let mut jump_table = Vec::with_capacity(NUM_CHUNKS); + let mut symbols = Vec::with_capacity(num_chunks); + let mut jump_table = Vec::with_capacity(num_chunks); - for _ in 0..NUM_CHUNKS { + for _ in 0..num_chunks { jump_table.push(encoder.pos()); - let chunk = (0..SYMBOLS_PER_CHUNK) + let chunk = (0..symbols_per_chunk) .map(|_| model.quantile_function(rng.next_u32() % (1 << 24)).0) .collect::>(); encoder.encode_iid_symbols(&chunk, &model).unwrap(); @@ -1271,7 +1279,7 @@ mod tests { // implement `Pos` due to complications at the stream end.) for (chunk, _) in symbols.iter().zip(&jump_table) { let decoded = decoder - .decode_iid_symbols(SYMBOLS_PER_CHUNK, &model) + .decode_iid_symbols(symbols_per_chunk, &model) .collect::, _>>() .unwrap(); assert_eq!(&decoded, chunk); @@ -1284,13 +1292,13 @@ mod tests { // Make sure we test jumping to beginning at least once. 0 } else { - rng.next_u32() as usize % NUM_CHUNKS + rng.next_u32() as usize % num_chunks }; let pos_and_state = jump_table[chunk_index]; decoder.seek(pos_and_state).unwrap(); let decoded = decoder - .decode_iid_symbols(SYMBOLS_PER_CHUNK, &model) + .decode_iid_symbols(symbols_per_chunk, &model) .collect::, _>>() .unwrap(); assert_eq!(&decoded, &symbols[chunk_index]) diff --git a/src/stream/stack.rs b/src/stream/stack.rs index e550e3a..0b22ba7 100644 --- a/src/stream/stack.rs +++ b/src/stream/stack.rs @@ -1303,7 +1303,12 @@ mod tests { f64: AsPrimitive, i32: AsPrimitive, { + #[cfg(not(miri))] const AMT: usize = 1000; + + #[cfg(miri)] + const AMT: usize = 100; + let mut symbols_gaussian = Vec::with_capacity(AMT); let mut means = Vec::with_capacity(AMT); let mut stds = Vec::with_capacity(AMT); @@ -1391,8 +1396,11 @@ mod tests { #[test] fn seek() { - const NUM_CHUNKS: usize = 100; - const SYMBOLS_PER_CHUNK: usize = 100; + #[cfg(not(miri))] + let (num_chunks, symbols_per_chunk) = (100, 100); + + #[cfg(miri)] + let (num_chunks, symbols_per_chunk) = (10, 10); let quantizer = DefaultLeakyQuantizer::new(-100..=100); let model = quantizer.quantize(Gaussian::new(0.0, 10.0)); @@ -1400,12 +1408,12 @@ mod tests { let mut encoder = DefaultAnsCoder::new(); let mut rng = Xoshiro256StarStar::seed_from_u64(123); - let mut symbols = Vec::with_capacity(NUM_CHUNKS); - let mut jump_table = Vec::with_capacity(NUM_CHUNKS); + let mut symbols = Vec::with_capacity(num_chunks); + let mut jump_table = Vec::with_capacity(num_chunks); let (initial_pos, initial_state) = encoder.pos(); - for _ in 0..NUM_CHUNKS { - let chunk = (0..SYMBOLS_PER_CHUNK) + for _ in 0..num_chunks { + let chunk = (0..symbols_per_chunk) .map(|_| model.quantile_function(rng.next_u32() % (1 << 24)).0) .collect::>(); encoder.encode_iid_symbols_reverse(&chunk, &model).unwrap(); @@ -1421,7 +1429,7 @@ mod tests { for (chunk, &(pos, state)) in symbols.iter().zip(&jump_table).rev() { assert_eq!(seekable_decoder.pos(), (pos, state)); let decoded = seekable_decoder - .decode_iid_symbols(SYMBOLS_PER_CHUNK, &model) + .decode_iid_symbols(symbols_per_chunk, &model) .collect::, _>>() .unwrap(); assert_eq!(&decoded, chunk) @@ -1431,11 +1439,11 @@ mod tests { // Seek to some random offsets in the jump table and decode one chunk for _ in 0..100 { - let chunk_index = rng.next_u32() as usize % NUM_CHUNKS; + let chunk_index = rng.next_u32() as usize % num_chunks; let (pos, state) = jump_table[chunk_index]; seekable_decoder.seek((pos, state)).unwrap(); let decoded = seekable_decoder - .decode_iid_symbols(SYMBOLS_PER_CHUNK, &model) + .decode_iid_symbols(symbols_per_chunk, &model) .collect::, _>>() .unwrap(); assert_eq!(&decoded, &symbols[chunk_index]) @@ -1458,7 +1466,7 @@ mod tests { for (chunk, &(pos, state)) in symbols.iter().zip(&jump_table).rev() { assert_eq!(seekable_decoder.pos(), (pos, state)); let decoded = seekable_decoder - .decode_iid_symbols(SYMBOLS_PER_CHUNK, &model) + .decode_iid_symbols(symbols_per_chunk, &model) .collect::, _>>() .unwrap(); assert_eq!(&decoded, chunk) @@ -1468,11 +1476,11 @@ mod tests { // Seek to some random offsets in the jump table and decode one chunk each time. for _ in 0..100 { - let chunk_index = rng.next_u32() as usize % NUM_CHUNKS; + let chunk_index = rng.next_u32() as usize % num_chunks; let (pos, state) = jump_table[chunk_index]; seekable_decoder.seek((pos, state)).unwrap(); let decoded = seekable_decoder - .decode_iid_symbols(SYMBOLS_PER_CHUNK, &model) + .decode_iid_symbols(symbols_per_chunk, &model) .collect::, _>>() .unwrap(); assert_eq!(&decoded, &symbols[chunk_index])