Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue-118, Auto compressor selection fix #119

Merged
merged 5 commits into from
Sep 18, 2024
Merged
Changes from 4 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
31 changes: 15 additions & 16 deletions brro-compressor/src/frame/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,7 @@ impl CompressorFrame {
// We need enough samples to do decent compression, minimum is 128 (2^7)
let data_sample = COMPRESSION_SPEED[compression_speed] as usize;
// Eligible compressors for use
let compressor_list = [
Compressor::Constant,
Compressor::FFT,
Compressor::Polynomial,
];
let compressor_list = [Compressor::FFT, Compressor::Polynomial];
cjrolo marked this conversation as resolved.
Show resolved Hide resolved
// Do a statistical analysis of the data, let's see if we can pick a compressor out of this.
let stats = DataStats::new(data);
// Checking the statistical analysis and chose, if possible, a compressor
Expand All @@ -90,6 +86,7 @@ impl CompressorFrame {
compressor,
)
})
.filter(|(result, _)| result.error <= max_error as f64)
.min_by_key(|x| x.0.compressed_data.len())
.unwrap();
self.compressor = *chosen_compressor;
Expand All @@ -100,19 +97,21 @@ impl CompressorFrame {
.compressed_data;
} else {
// Run all the eligible compressors and choose smallest
let (smallest_result, chosen_compressor) = compressor_list
.iter()
.map(|compressor| {
(
compressor.get_compress_bounded_results(data, max_error as f64),
compressor,
)
})
let compressor_results = compressor_list.iter().map(|compressor| {
(
compressor.get_compress_bounded_results(data, max_error as f64),
compressor,
)
});
let best_compressor = compressor_results
.clone()
.filter(|(result, _)| result.error <= max_error as f64)
.min_by_key(|x| x.0.compressed_data.len())
.unwrap();
.or_else(|| compressor_results.min_by_key(|x| x.0.compressed_data.len()));

self.data = smallest_result.compressed_data;
self.compressor = *chosen_compressor;
let selection = best_compressor.unwrap();
self.data = selection.0.compressed_data;
self.compressor = *selection.1;
}
debug!("Auto Compressor Selection: {:?}", self.compressor);
}
Expand Down
Loading