Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions src/dataset/readers/binary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(())
}
Expand All @@ -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(())
}
Expand All @@ -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(())
}
12 changes: 8 additions & 4 deletions src/dataset/readers/h5.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,16 +102,20 @@ impl MmapMatrix {
fn row_f32(&self, idx: usize, name: &str) -> Result<Vec<f32>> {
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<Vec<i64>> {
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())
}
}
Expand Down
18 changes: 12 additions & 6 deletions src/dataset/readers/npy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
})
}
Expand Down
Loading