Skip to content

Commit

Permalink
test chunk contains
Browse files Browse the repository at this point in the history
  • Loading branch information
gauteh committed Jun 4, 2023
1 parent ce62726 commit 40fbbdc
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
7 changes: 3 additions & 4 deletions src/idx/dataset/dataset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -310,10 +310,9 @@ impl<const D: usize> Dataset<'_, D> {
let end: u64 = self.shape.iter().product();
let chunk_sh: u64 = self.chunk_shape.iter().product();

ensure!(end % chunk_sh == 0, "chunks not modulo of dataset shape: {0:?} vs {1:?}", self.shape, self.chunk_shape);
let chunks = end / chunk_sh;
ensure!(chunks == self.chunks.len() as u64, "number of chunks does not match dataset shape: {chunks} != {}", self.chunks.len());

// ensure!(end % chunk_sh == 0, "chunks not modulo of dataset shape: {0:?} vs {1:?}", self.shape, self.chunk_shape);
// let chunks = end / chunk_sh;
// ensure!(chunks == self.chunks.len() as u64, "number of chunks does not match dataset shape: {chunks} != {}", self.chunks.len());



Expand Down
12 changes: 12 additions & 0 deletions src/idx/dataset/slicer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,8 @@ impl<'a, const D: usize> Iterator for ChunkSlice<'a, D> {

let chunk = self.dataset.chunk_at_coord(&I0);

dbg!(self.dataset.shape);

// Iterate through dimensions, starting at the last (smallest) one.
for di in (0..D).rev() {
dbg!(di);
Expand Down Expand Up @@ -394,6 +396,16 @@ mod tests {

ds.valid().unwrap();

let end: u64 = ds.shape.iter().product();
for i in 0..end {
let I = offset_to_coords(i, ds.dim_sz);
let ii = coords_to_offset(I, ds.dim_sz);
assert_eq!(ii, i);

let chunk = ds.chunk_at_coord(&I);
assert!(chunk.contains(&I, &ds.chunk_shape) == std::cmp::Ordering::Equal);
}

ChunkSlice::new(&ds, [0, 0, 0], [2, 32, 580]).for_each(drop);

// Should be all chunks.
Expand Down

0 comments on commit 40fbbdc

Please sign in to comment.