Skip to content

Commit a232b6a

Browse files
committed
Apply suggestions from code review
1 parent 05b968b commit a232b6a

File tree

3 files changed

+22
-20
lines changed

3 files changed

+22
-20
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
## Unreleased
44

55
### Added
6+
67
- Conversion from `Infallible` to `Error` to allow infallible conversion to
78
extents.
89

examples/chunking.rs

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,37 @@
11
//! Create, write, and read a chunked dataset
2-
fn main() -> hdf5::Result<()> {
3-
let file = hdf5::File::create("chunking.h5")?;
42
5-
let ny = 100;
6-
let nx = 100;
7-
let arr = ndarray::Array2::from_shape_fn((ny, nx), |(j, i)| (1000 * j + i) as f32);
3+
use hdf5::{File, Result};
4+
use ndarray::Array2;
85

9-
{
10-
let ds = file
6+
fn main() -> Result<()> {
7+
let file = File::create("chunking.h5")?;
8+
9+
let (ny, nx) = (100, 100);
10+
let arr = Array2::from_shape_fn((ny, nx), |(j, i)| (1000 * j + i) as f32);
11+
12+
let ds = file
1113
.new_dataset::<f32>()
12-
.chunk((1, ny, nx)) // nx*ny elements will be compressed as a single chunk
13-
.shape((1.., ny, nx)) // Initial size of 1 on the unlimited dimension
14+
.chunk((1, ny, nx)) // each chunk contains ny * nx elements
15+
.shape((1.., ny, nx)) // first axis is unlimited with initial size of 1
1416
.deflate(3)
1517
.create("variable")?;
1618

17-
// Writing a chunk at a time will be most efficient
18-
ds.write_slice(&arr, (0, .., ..))?;
19+
// writing one chunk at a time is the most efficient
20+
ds.write_slice(&arr, (0, .., ..))?;
1921

20-
// Dataset can be resized along an unlimited dimension
21-
ds.resize((10, ny, nx))?;
22-
ds.write_slice(&arr, (1, .., ..))?;
23-
}
22+
// dataset can be resized along an unlimited dimension
23+
ds.resize((10, ny, nx))?;
24+
ds.write_slice(&arr, (1, .., ..))?;
2425

25-
let ds = file.dataset("variable")?;
2626
let chunksize = ds.chunk().unwrap();
2727
assert_eq!(chunksize, &[1, ny, nx]);
2828

2929
let shape = ds.shape();
3030
assert_eq!(shape, &[10, ny, nx]);
3131

32-
// Reading from a chunked dataset should be done in a chunk-wise order
32+
// it's best to read from a chunked dataset in a chunk-wise fashion
3333
for k in 0..shape[0] {
34-
let _arr: ndarray::Array2<f32> = ds.read_slice((k, .., ..))?;
34+
let _arr: Array2<f32> = ds.read_slice((k, .., ..))?;
3535
}
3636

3737
Ok(())

src/error.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use std::convert::Infallible;
12
use std::error::Error as StdError;
23
use std::fmt;
34
use std::ops::Deref;
@@ -229,8 +230,8 @@ impl From<String> for Error {
229230
}
230231
}
231232

232-
impl From<core::convert::Infallible> for Error {
233-
fn from(_v: core::convert::Infallible) -> Self {
233+
impl From<Infallible> for Error {
234+
fn from(_: Infallible) -> Self {
234235
unreachable!("Infallible error can never be constructed")
235236
}
236237
}

0 commit comments

Comments
 (0)