diff --git a/src/dataset/readers/binary.rs b/src/dataset/readers/binary.rs index 6b791ff..8174bf9 100644 --- a/src/dataset/readers/binary.rs +++ b/src/dataset/readers/binary.rs @@ -7,8 +7,8 @@ pub(super) fn read_i64_array(file: &mut File, out: &mut [i64]) -> Result<()> { let mut buf = vec![0u8; out.len() * 8]; file.read_exact(&mut buf) .context("failed to read i64 array")?; - for (slot, chunk) in out.iter_mut().zip(buf.chunks_exact(8)) { - *slot = i64::from_le_bytes(chunk.try_into().unwrap()); + for (slot, chunk) in out.iter_mut().zip(buf.as_chunks::<8>().0) { + *slot = i64::from_le_bytes(*chunk); } Ok(()) } @@ -17,8 +17,8 @@ pub(super) fn read_i32_array(file: &mut File, out: &mut [i32]) -> Result<()> { let mut buf = vec![0u8; out.len() * 4]; file.read_exact(&mut buf) .context("failed to read i32 array")?; - for (slot, chunk) in out.iter_mut().zip(buf.chunks_exact(4)) { - *slot = i32::from_le_bytes(chunk.try_into().unwrap()); + for (slot, chunk) in out.iter_mut().zip(buf.as_chunks::<4>().0) { + *slot = i32::from_le_bytes(*chunk); } Ok(()) } @@ -27,8 +27,8 @@ pub(super) fn read_f32_array(file: &mut File, out: &mut [f32]) -> Result<()> { let mut buf = vec![0u8; out.len() * 4]; file.read_exact(&mut buf) .context("failed to read f32 array")?; - for (slot, chunk) in out.iter_mut().zip(buf.chunks_exact(4)) { - *slot = f32::from_le_bytes(chunk.try_into().unwrap()); + for (slot, chunk) in out.iter_mut().zip(buf.as_chunks::<4>().0) { + *slot = f32::from_le_bytes(*chunk); } Ok(()) } diff --git a/src/dataset/readers/h5.rs b/src/dataset/readers/h5.rs index 9d55c61..6276899 100644 --- a/src/dataset/readers/h5.rs +++ b/src/dataset/readers/h5.rs @@ -102,16 +102,20 @@ impl MmapMatrix { fn row_f32(&self, idx: usize, name: &str) -> Result> { Ok(self .row_bytes(idx, name)? - .chunks_exact(4) - .map(|b| f32::from_le_bytes(b.try_into().unwrap())) + .as_chunks::<4>() + .0 + .iter() + .map(|b| f32::from_le_bytes(*b)) .collect()) } fn row_i64(&self, idx: usize, name: &str) -> Result> { Ok(self .row_bytes(idx, name)? - .chunks_exact(8) - .map(|b| i64::from_le_bytes(b.try_into().unwrap())) + .as_chunks::<8>() + .0 + .iter() + .map(|b| i64::from_le_bytes(*b)) .collect()) } } diff --git a/src/dataset/readers/npy.rs b/src/dataset/readers/npy.rs index d614fcc..741d6ca 100644 --- a/src/dataset/readers/npy.rs +++ b/src/dataset/readers/npy.rs @@ -85,16 +85,22 @@ impl NpyMatrix { let bytes = &self.mmap[start..start + row_bytes]; Ok(match self.layout.dtype { Dtype::F16 => bytes - .chunks_exact(2) - .map(|b| f16::from_le_bytes([b[0], b[1]]).to_f32()) + .as_chunks::<2>() + .0 + .iter() + .map(|b| f16::from_le_bytes(*b).to_f32()) .collect(), Dtype::F32 => bytes - .chunks_exact(4) - .map(|b| f32::from_le_bytes(b.try_into().unwrap())) + .as_chunks::<4>() + .0 + .iter() + .map(|b| f32::from_le_bytes(*b)) .collect(), Dtype::F64 => bytes - .chunks_exact(8) - .map(|b| f64::from_le_bytes(b.try_into().unwrap()) as f32) + .as_chunks::<8>() + .0 + .iter() + .map(|b| f64::from_le_bytes(*b) as f32) .collect(), }) }