Skip to content

Commit 1dd05be

Browse files
committed
fix: correct hdf5 array checkpoint conversions
1 parent e621ad0 commit 1dd05be

1 file changed

Lines changed: 7 additions & 11 deletions

File tree

src/io/checkpoint.rs

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use std::path::Path;
22
use std::time::{SystemTime, UNIX_EPOCH};
33

44
use hdf5::types::VarLenUnicode;
5-
use hdf5::File;
5+
use hdf5::{File, H5Type};
66
use ndarray::ArrayView3;
77
use num_complex::Complex64;
88

@@ -19,16 +19,12 @@ const PSI_DATASET: &str = "psi";
1919

2020
type ComplexRepr = [f64; 2];
2121

22-
impl From<Complex64> for [f64; 2] {
23-
fn from(value: Complex64) -> Self {
24-
[value.re, value.im]
25-
}
22+
fn to_repr(value: Complex64) -> ComplexRepr {
23+
[value.re, value.im]
2624
}
2725

28-
impl From<[f64; 2]> for Complex64 {
29-
fn from(value: ComplexRepr) -> Self {
30-
Self::new(value[0], value[1])
31-
}
26+
fn from_repr(value: ComplexRepr) -> Complex64 {
27+
Complex64::new(value[0], value[1])
3228
}
3329

3430
fn io_error(err: impl std::fmt::Display) -> Error {
@@ -128,7 +124,7 @@ pub fn save_checkpoint(path: &Path, grid: &Grid3, state: &State3) -> Result<(),
128124
create_attr(&grid_group, "lz", &lengths[2])?;
129125

130126
let state_group = root.create_group(STATE_GROUP).map_err(io_error)?;
131-
let psi_repr: Vec<ComplexRepr> = state.psi.iter().copied().map(ComplexRepr::from).collect();
127+
let psi_repr: Vec<ComplexRepr> = state.psi.iter().copied().map(to_repr).collect();
132128
let psi_view = ArrayView3::from_shape((shape[0], shape[1], shape[2]), &psi_repr)
133129
.map_err(|_| Error::InvalidFftInputLength)?;
134130

@@ -200,7 +196,7 @@ pub fn load_checkpoint(path: &Path) -> Result<(Grid3, State3), Error> {
200196
Ok((
201197
grid,
202198
State3 {
203-
psi: psi_raw.into_iter().map(Complex64::from).collect(),
199+
psi: psi_raw.into_iter().map(from_repr).collect(),
204200
},
205201
))
206202
}

0 commit comments

Comments
 (0)