Skip to content
Merged
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
26 changes: 9 additions & 17 deletions httomo/runner/block_split.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import math
from typing import Iterator
from httomo.runner.dataset import DataSetBlock
from httomo.runner.dataset_store_interfaces import DataSetSource

Expand All @@ -22,6 +21,7 @@ def __init__(self, source: DataSetSource, max_slices: int):
self._chunk_size = source.chunk_shape[source.slicing_dim]
self._max_slices = int(min(max_slices, self._chunk_size))
self._num_blocks = math.ceil(self._chunk_size / self._max_slices)
self._current = 0
assert self._source.slicing_dim in [
0,
1,
Expand All @@ -41,20 +41,12 @@ def __getitem__(self, idx: int) -> DataSetBlock:
len = min(self.slices_per_block, self._chunk_size - start)
return self._source.read_block(start, len)

def __iter__(self) -> Iterator[DataSetBlock]:
class BlockIterator:
def __init__(self, splitter):
self.splitter = splitter
self._current = 0
def __iter__(self):
return self

def __iter__(self) -> "BlockIterator":
return self # pragma: no cover

def __next__(self) -> DataSetBlock:
if self._current >= len(self.splitter):
raise StopIteration
v = self.splitter[self._current]
self._current += 1
return v

return BlockIterator(self)
def __next__(self) -> DataSetBlock:
if self._current >= len(self):
raise StopIteration
v = self[self._current]
self._current += 1
return v
Loading