Skip to content

Commit

Permalink
fix in_trim_slice size for non overlapping blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
scottstanie committed Oct 18, 2024
1 parent 70b0a95 commit 1d76300
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
11 changes: 5 additions & 6 deletions src/dolphin/io/_blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,12 +146,11 @@ def get_full_res_trim(
) -> BlockIndices:
in_no_pad_rows, in_no_pad_cols = in_no_pad_block
in_rows, in_cols = in_block
trim_full_col = slice(
in_no_pad_cols.start - in_cols.start, in_no_pad_cols.stop - in_cols.stop
)
trim_full_row = slice(
in_no_pad_rows.start - in_rows.start, in_no_pad_rows.stop - in_rows.stop
)
# If the stops are the same, return None instead of slice(0, 0)
col_stop = (in_no_pad_cols.stop - in_cols.stop) or None
row_stop = (in_no_pad_rows.stop - in_rows.stop) or None
trim_full_col = slice(in_no_pad_cols.start - in_cols.start, col_stop)
trim_full_row = slice(in_no_pad_rows.start - in_rows.start, row_stop)
return BlockIndices.from_slices(trim_full_row, trim_full_col)


Expand Down
8 changes: 8 additions & 0 deletions tests/test_io_blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,14 @@ def test_iter_outputs(self):
assert row_slice.stop < nrows - out_row_margin
assert col_slice.stop < ncols - out_col_margin

def test_zero_trim_size(self):
bm = StridedBlockManager(
(7, 7), (100, 100), Strides(3, 3), half_window=HalfWindow(1, 1)
)
in_row_trim, in_col_trim = next(iter(bm.iter_blocks()))[-1]
assert get_slice_length(in_row_trim, data_size=7) == 7
assert get_slice_length(in_col_trim, data_size=7) == 7


# @pytest.mark.skip(reason="Uses old logic ")
class TestFakeProcess:
Expand Down

0 comments on commit 1d76300

Please sign in to comment.