Skip to content

Commit

Permalink
CI: less expensive miri tests
Browse files Browse the repository at this point in the history
  • Loading branch information
robamler committed Nov 6, 2022
1 parent 24596d6 commit 772ebe8
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 21 deletions.
4 changes: 4 additions & 0 deletions src/stream/chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1255,6 +1255,10 @@ mod tests {
f64: AsPrimitive<Probability>,
i32: AsPrimitive<Probability>,
{
#[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,
);
Expand Down
26 changes: 17 additions & 9 deletions src/stream/queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1160,7 +1160,12 @@ mod tests {
f64: AsPrimitive<Probability>,
i32: AsPrimitive<Probability>,
{
#[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);
Expand Down Expand Up @@ -1242,21 +1247,24 @@ 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));

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::<Vec<_>>();
encoder.encode_iid_symbols(&chunk, &model).unwrap();
Expand All @@ -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::<Result<Vec<_>, _>>()
.unwrap();
assert_eq!(&decoded, chunk);
Expand All @@ -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::<Result<Vec<_>, _>>()
.unwrap();
assert_eq!(&decoded, &symbols[chunk_index])
Expand Down
32 changes: 20 additions & 12 deletions src/stream/stack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1303,7 +1303,12 @@ mod tests {
f64: AsPrimitive<Probability>,
i32: AsPrimitive<Probability>,
{
#[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);
Expand Down Expand Up @@ -1391,21 +1396,24 @@ 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));

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::<Vec<_>>();
encoder.encode_iid_symbols_reverse(&chunk, &model).unwrap();
Expand All @@ -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::<Result<Vec<_>, _>>()
.unwrap();
assert_eq!(&decoded, chunk)
Expand All @@ -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::<Result<Vec<_>, _>>()
.unwrap();
assert_eq!(&decoded, &symbols[chunk_index])
Expand All @@ -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::<Result<Vec<_>, _>>()
.unwrap();
assert_eq!(&decoded, chunk)
Expand All @@ -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::<Result<Vec<_>, _>>()
.unwrap();
assert_eq!(&decoded, &symbols[chunk_index])
Expand Down

0 comments on commit 772ebe8

Please sign in to comment.