Skip to content

Commit fee6f33

Browse files
committed
Add Dataset::num_chunks()
1 parent 97b986d commit fee6f33

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

src/hl/dataset.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use hdf5_sys::{
88
h5::HADDR_UNDEF,
99
h5d::{
1010
H5D_fill_value_t, H5D_layout_t, H5Dcreate2, H5Dcreate_anon, H5Dget_create_plist,
11-
H5Dget_offset, H5Dset_extent, H5D_FILL_TIME_ALLOC,
11+
H5Dget_num_chunks, H5Dget_offset, H5Dset_extent, H5D_FILL_TIME_ALLOC,
1212
},
1313
h5p::{
1414
H5Pcreate, H5Pfill_value_defined, H5Pget_chunk, H5Pget_fill_value, H5Pget_layout,
@@ -77,6 +77,17 @@ impl Dataset {
7777
})
7878
}
7979

80+
/// Returns number of chunks if the dataset is chunked.
81+
pub fn num_chunks(&self) -> Option<usize> {
82+
if !self.is_chunked() {
83+
return None;
84+
}
85+
h5lock!(self.space().map_or(None, |s| {
86+
let mut n: hsize_t = 0;
87+
h5check(H5Dget_num_chunks(self.id(), s.id(), &mut n)).map(|_| n as _).ok()
88+
}))
89+
}
90+
8091
/// Returns the chunk shape if the dataset is chunked.
8192
pub fn chunks(&self) -> Option<Vec<Ix>> {
8293
h5lock!({

0 commit comments

Comments
 (0)