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

Add the shuffle option to the compression method #102

Merged
merged 2 commits into from
Feb 17, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
7 changes: 5 additions & 2 deletions netcdf/src/variable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,16 +170,19 @@ impl<'g> VariableMut<'g> {
/// compression (good for CPU bound tasks), and 9 providing the
/// highest compression level (good for memory bound tasks)
///
/// `shuffle` enables a filter to reorder bytes before compressing, which
/// can improve compression ratios
///
/// # Errors
///
/// Not a `netcdf-4` file or `deflate_level` not valid
pub fn compression(&mut self, deflate_level: nc_type) -> error::Result<()> {
pub fn compression(&mut self, deflate_level: nc_type, shuffle: bool) -> error::Result<()> {
unsafe {
error::checked(super::with_lock(|| {
nc_def_var_deflate(
self.ncid,
self.varid,
<_>::from(false),
shuffle.into(),
<_>::from(true),
deflate_level,
)
Expand Down
2 changes: 1 addition & 1 deletion netcdf/tests/group.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ fn find_variable() {

for mut var in group.variables_mut() {
if var.dimensions().len() > 0 {
var.compression(3).unwrap();
var.compression(3, false).unwrap();
}
if var.name() == "z" {
var.chunking(&[1]).unwrap();
Expand Down
7 changes: 4 additions & 3 deletions netcdf/tests/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -854,7 +854,7 @@ fn use_compression_chunking() {
file.add_dimension("x", 10).unwrap();

let var = &mut file.add_variable::<i32>("compressed", &["x"]).unwrap();
var.compression(5).unwrap();
var.compression(5, false).unwrap();
var.chunking(&[5]).unwrap();

let v = vec![0i32; 10];
Expand All @@ -863,7 +863,7 @@ fn use_compression_chunking() {
let var = &mut file
.add_variable::<i32>("compressed2", &["x", "x"])
.unwrap();
var.compression(9).unwrap();
var.compression(9, true).unwrap();
var.chunking(&[5, 5]).unwrap();
var.put_values(&[1i32, 2, 3, 4, 5, 6, 7, 8, 9, 10], (..10, ..1))
.unwrap();
Expand Down Expand Up @@ -903,7 +903,8 @@ fn set_compression_all_variables_in_a_group() {
.expect("Could not create variable");

for mut var in file.variables_mut() {
var.compression(9).expect("Could not set compression level");
var.compression(9, false)
.expect("Could not set compression level");
}
}

Expand Down