Skip to content

Commit

Permalink
extend test, fix estimate
Browse files Browse the repository at this point in the history
  • Loading branch information
PSeitz committed Sep 5, 2022
1 parent c64c383 commit 0e7e892
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 12 deletions.
2 changes: 1 addition & 1 deletion fastfield_codecs/src/blockwise_linear.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ impl FastFieldCodec for BlockwiseLinearCodec {
}
let estimated_bit_width = first_chunk
.iter()
.map(|el| (((el + 1) as f32 * 1.5) * 2.0) as u64)
.map(|el| ((el + 1) as f32 * 3.0) as u64)
.map(compute_num_bits)
.max()
.unwrap();
Expand Down
22 changes: 17 additions & 5 deletions fastfield_codecs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -284,26 +284,38 @@ mod tests {
let data: VecColumn = data.as_slice().into();

let linear_interpol_estimation = LinearCodec::estimate(&data).unwrap();
assert_le!(linear_interpol_estimation, 0.04);
assert_le!(linear_interpol_estimation, 0.01);

let multi_linear_interpol_estimation = BlockwiseLinearCodec::estimate(&data).unwrap();
assert_le!(multi_linear_interpol_estimation, 0.2);
assert_le!(linear_interpol_estimation, multi_linear_interpol_estimation);
assert_lt!(linear_interpol_estimation, multi_linear_interpol_estimation);

let bitpacked_estimation = BitpackedCodec::estimate(&data).unwrap();
assert_le!(linear_interpol_estimation, bitpacked_estimation);
assert_lt!(linear_interpol_estimation, bitpacked_estimation);
}
#[test]
fn estimation_test_bad_interpolation_case() {
let data: &[u64] = &[200, 10, 10, 10, 10, 1000, 20];

let data: VecColumn = data.into();
let linear_interpol_estimation = LinearCodec::estimate(&data).unwrap();
assert_le!(linear_interpol_estimation, 0.32);
assert_le!(linear_interpol_estimation, 0.34);

let bitpacked_estimation = BitpackedCodec::estimate(&data).unwrap();
assert_le!(bitpacked_estimation, linear_interpol_estimation);
assert_lt!(bitpacked_estimation, linear_interpol_estimation);
}

#[test]
fn estimation_prefer_bitpacked() {
let data: &[u64] = &[10, 10, 10, 10];

let data: VecColumn = data.into();
let linear_interpol_estimation = LinearCodec::estimate(&data).unwrap();

let bitpacked_estimation = BitpackedCodec::estimate(&data).unwrap();
assert_lt!(bitpacked_estimation, linear_interpol_estimation);
}

#[test]
fn estimation_test_bad_interpolation_case_monotonically_increasing() {
let mut data: Vec<u64> = (200..=20000_u64).collect();
Expand Down
4 changes: 2 additions & 2 deletions fastfield_codecs/src/line.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ impl Line {
Self::train_from(ys, sample_positions.iter().cloned())
}

// Same as train, but the intercept is only estimated from provided sample positions
// Intercept is only computed from provided positions
fn train_from(ys: &dyn Column, positions: impl Iterator<Item = u64>) -> Self {
let num_vals = if let Some(num_vals) = NonZeroU64::new(ys.num_vals() - 1) {
num_vals
Expand Down Expand Up @@ -164,7 +164,7 @@ mod tests {
/// This function operates translation over the data for better coverage.
#[track_caller]
fn test_line_interpol_with_translation(ys: &[u64], expected: Option<u64>) {
let mut translations = vec![0, 100, u64::MAX, u64::MAX - 1];
let mut translations = vec![0, 100, u64::MAX / 2, u64::MAX, u64::MAX - 1];
translations.extend_from_slice(ys);
for translation in translations {
let translated_ys: Vec<u64> = ys
Expand Down
6 changes: 3 additions & 3 deletions fastfield_codecs/src/linear.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ impl FastFieldCodec for LinearCodec {
.max()
.unwrap_or(0);

let num_bits = estimated_bit_width as u64 * fastfield_accessor.num_vals() as u64;
let num_bits = (estimated_bit_width as u64 * fastfield_accessor.num_vals() as u64) + 64;
let num_bits_uncompressed = 64 * fastfield_accessor.num_vals();
Some(num_bits as f32 / num_bits_uncompressed as f32)
}
Expand All @@ -182,8 +182,8 @@ mod tests {
let (estimate, actual_compression) =
create_and_validate(&data, "simple monotonically large").unwrap();

assert!(actual_compression < 0.03);
assert!(estimate < 0.04);
assert_le!(actual_compression, 0.001);
assert_le!(estimate, 0.02);
}

#[test]
Expand Down
2 changes: 1 addition & 1 deletion src/fastfield/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,7 @@ mod tests {
// assert_eq!(file.len(), 17710 as usize); //bitpacked size
// assert_eq!(file.len(), 10175_usize); // linear interpol size
// assert_eq!(file.len(), 75_usize); // linear interpol size after calc improvement
//assert_eq!(file.len(), 1325_usize); // linear interpol size after switching to int based
// assert_eq!(file.len(), 1325_usize); // linear interpol size after switching to int based
assert_eq!(file.len(), 62_usize); // linear interpol size after switching to int based, off
// by one fix

Expand Down

0 comments on commit 0e7e892

Please sign in to comment.