Skip to content

Commit

Permalink
Merge pull request #77 from instaclustr/improving_optimize
Browse files Browse the repository at this point in the history
Optimizing Data Conversion
  • Loading branch information
joshuabvarghese authored Nov 16, 2023
2 parents e5aa857 + 1073801 commit a369ff5
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions brro-compressor/src/compressor/constant.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,9 @@ impl Constant {
self.residuals.len();
}

/// Currently the data is provided in f64, this compressor needs i64. So the optimizer needs
/// to get this out for the compressor
/// TODO: Make this work decently, right now is only doing a cast (And maybe that is it?)
/// This method optimizes the data conversion from f64 to i64.
pub fn optimize(data: &[f64]) -> Vec<i64> {
let mut out_vec = Vec::with_capacity(data.len());
for element in data {
out_vec.push(*element as i64);
}
out_vec
data.iter().map(|&x| x.round() as i64).collect()
}

/// Compresses the data. Walks the data array and sets one value as the constant.
Expand Down Expand Up @@ -175,4 +169,11 @@ mod tests {
let out = constant_to_data(frame_size, &compressed_data);
assert_eq!(vector1, out);
}

#[test]
fn test_optimize() {
let vector1 = vec![1.1, 2.5, 3.8, 4.2, 5.7];
let optimized_data = Constant::optimize(&vector1);
assert_eq!(optimized_data, vec![1, 3, 4, 4, 6]);
}
}

0 comments on commit a369ff5

Please sign in to comment.