Skip to content

Commit

Permalink
Add support for the NoPrediction and Lossless compressors
Browse files Browse the repository at this point in the history
  • Loading branch information
juntyr authored and rroohhh committed Dec 9, 2024
1 parent 71faf50 commit 1e81def
Showing 1 changed file with 23 additions and 7 deletions.
30 changes: 23 additions & 7 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ pub enum CompressionAlgorithm {
regression_second_order: bool,
prediction_dimension: Option<u32>,
},
NoPrediction,
Lossless,
}

impl CompressionAlgorithm {
Expand All @@ -23,7 +25,9 @@ impl CompressionAlgorithm {
regression_second_order: config.regression2,
prediction_dimension: Some(config.pred_dim as _),
},
_ => unreachable!(),
sz3_sys::SZ3_ALGO_ALGO_NOPRED => Self::NoPrediction,
sz3_sys::SZ3_ALGO_ALGO_LOSSLESS => Self::Lossless,
algo => panic!("unsupported compression algorithm {}", algo),
}
}

Expand All @@ -32,6 +36,8 @@ impl CompressionAlgorithm {
Self::Interpolation { .. } => sz3_sys::SZ3_ALGO_ALGO_INTERP,
Self::InterpolationLorenzo { .. } => sz3_sys::SZ3_ALGO_ALGO_INTERP_LORENZO,
Self::LorenzoRegression { .. } => sz3_sys::SZ3_ALGO_ALGO_LORENZO_REG,
Self::NoPrediction => sz3_sys::SZ3_ALGO_ALGO_NOPRED,
Self::Lossless => sz3_sys::SZ3_ALGO_ALGO_LOSSLESS,
}) as _
}

Expand Down Expand Up @@ -155,7 +161,7 @@ impl ErrorBound {
absolute_bound: config.absErrorBound,
relative_bound: config.relErrorBound,
},
_ => unreachable!(),
mode => panic!("unsupported error bound {}", mode),
}
}

Expand Down Expand Up @@ -215,7 +221,7 @@ impl InterpolationAlgorithm {
match config.interpAlgo as _ {
sz3_sys::SZ3_INTERP_ALGO_INTERP_ALGO_LINEAR => Self::Linear,
sz3_sys::SZ3_INTERP_ALGO_INTERP_ALGO_CUBIC => Self::Cubic,
_ => unreachable!(),
algo => panic!("unsupported interpolation algorithm {}", algo),
}
}

Expand All @@ -239,7 +245,7 @@ impl LossLess {
match config.lossless {
0 => LossLess::LossLessBypass,
1 => LossLess::ZSTD,
_ => unreachable!(),
mode => panic!("unsupported lossless mode {}", mode),
}
}

Expand All @@ -265,7 +271,7 @@ impl Encoder {
0 => Self::SkipEncoder,
1 => Self::HuffmanEncoder,
2 => Self::ArithmeticEncoder,
_ => unreachable!(),
encoder => panic!("unsupported encoder {}", encoder),
}
}

Expand Down Expand Up @@ -837,7 +843,8 @@ mod tests {
})
.sum();
let psnr = 20. * (max - min).log10() - 10. * mse.log10();
assert!(psnr < psnr_bound);
// PSNR for zero error is infinity but meets the bound
assert!(mse == 0.0 || psnr < psnr_bound);
}
ErrorBound::L2Norm(l2norm_bound) => {
let mse: f64 = data
Expand Down Expand Up @@ -879,6 +886,12 @@ mod tests {
}
}

if matches!(config.compression_algorithm, CompressionAlgorithm::Lossless) {
for (orig, compressed) in data.data().iter().zip(decompressed_data.data()) {
assert_eq!(f64::from(*orig).to_bits(), f64::from(*compressed).to_bits());
}
}

Ok(())
}

Expand Down Expand Up @@ -937,6 +950,7 @@ mod tests {
([(lossless_bypass, LossLess::LossLessBypass), (zstd, LossLess::ZSTD)],
([(true, cfg(feature = "openmp")), (false, cfg(all()))],
([
(absolute_0, ErrorBound::Absolute(0.)),
(absolute_1_0, ErrorBound::Absolute(1.)),
(absolute_0_1, ErrorBound::Absolute(0.1)),
(absolute_0_01, ErrorBound::Absolute(0.01)),
Expand Down Expand Up @@ -968,7 +982,9 @@ mod tests {
Some(true),
Some(true),
None
))
)),
(no_prediction, CompressionAlgorithm::NoPrediction),
(lossless, CompressionAlgorithm::Lossless)
],
([(linear, InterpolationAlgorithm::Linear), (cubic, InterpolationAlgorithm::Cubic)],
([65536, 256, 2097152],
Expand Down

0 comments on commit 1e81def

Please sign in to comment.