Skip to content

Commit f3e00e3

Browse files
committed
allow a zero-sized chunked dataset, if it is resizable
1 parent 76b239a commit f3e00e3

File tree

1 file changed

+21
-5
lines changed

1 file changed

+21
-5
lines changed

src/hl/dataset.rs

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -326,11 +326,14 @@ impl<T: H5Type> DatasetBuilder<T> {
326326
"Invalid chunk: {:?} (all dimensions must be positive)",
327327
dims
328328
);
329-
ensure!(
330-
dims.iter().zip(shape.dims().iter()).all(|(&c, &s)| c <= s),
331-
"Invalid chunk: {:?} (must not exceed data shape in any dimension)",
332-
dims
333-
);
329+
330+
if !self.resizable {
331+
ensure!(
332+
dims.iter().zip(shape.dims().iter()).all(|(&c, &s)| c <= s),
333+
"Invalid chunk: {:?} (must not exceed data shape in any dimension)",
334+
dims
335+
);
336+
}
334337

335338
let c_dims: Vec<hsize_t> = dims.iter().map(|&x| x as _).collect();
336339
h5try!(H5Pset_chunk(id, dims.ndim() as _, c_dims.as_ptr()));
@@ -516,6 +519,19 @@ pub mod tests {
516519
})
517520
}
518521

522+
#[test]
523+
pub fn test_chunks_resizable_zero_size() {
524+
with_tmp_file(|file| {
525+
let ds = file.new_dataset::<u32>().chunk((128,)).resizable(true).create("chunked_empty", (0,)).unwrap();
526+
assert_eq!(ds.shape(), vec![0]);
527+
528+
ds.resize((10,)).unwrap();
529+
assert_eq!(ds.shape(), vec![10]);
530+
531+
ds.as_writer().write(&vec![3; 10]).unwrap();
532+
})
533+
}
534+
519535
#[test]
520536
pub fn test_invalid_chunk() {
521537
with_tmp_file(|file| {

0 commit comments

Comments
 (0)