(
sample_in,
sample_out,
anchor,
abs_slice_shape,
abs_start,
abs_end,
out_of_bounds_policy,
fill_values,
naxes=2,
mean=None,
std=None,
flip=None,
permute=None,
)
| 564 | |
| 565 | |
| 566 | def check_slice_output( |
| 567 | sample_in, |
| 568 | sample_out, |
| 569 | anchor, |
| 570 | abs_slice_shape, |
| 571 | abs_start, |
| 572 | abs_end, |
| 573 | out_of_bounds_policy, |
| 574 | fill_values, |
| 575 | naxes=2, |
| 576 | mean=None, |
| 577 | std=None, |
| 578 | flip=None, |
| 579 | permute=None, |
| 580 | ): |
| 581 | in_shape = sample_in.shape |
| 582 | out_shape = sample_out.shape |
| 583 | ndim = len(out_shape) |
| 584 | orig_nchannels = in_shape[2] |
| 585 | out_ch_dim = permute.index(2) if permute is not None else 2 |
| 586 | out_nchannels = out_shape[out_ch_dim] |
| 587 | |
| 588 | if out_of_bounds_policy == "pad": |
| 589 | if permute is not None: |
| 590 | assert all( |
| 591 | [ |
| 592 | abs_slice_shape[permute[i]] == out_shape[i] |
| 593 | for i in range(ndim) |
| 594 | if permute[i] < naxes |
| 595 | ] |
| 596 | ) |
| 597 | else: |
| 598 | assert all([abs_slice_shape[i] == out_shape[i] for i in range(naxes)]) |
| 599 | elif out_of_bounds_policy == "trim_to_shape": |
| 600 | assert all([out_shape[i] <= in_shape[i] for i in range(naxes)]) |
| 601 | for i in range(naxes): |
| 602 | if abs_start[i] < 0: |
| 603 | abs_start[i] = 0 |
| 604 | if abs_end[i] > in_shape[i]: |
| 605 | abs_end[i] = in_shape[i] |
| 606 | abs_slice_shape[i] = abs_end[i] - abs_start[i] |
| 607 | if permute is not None: |
| 608 | assert all( |
| 609 | [ |
| 610 | abs_slice_shape[permute[i]] == out_shape[i] |
| 611 | for i in range(ndim) |
| 612 | if permute[i] < naxes |
| 613 | ] |
| 614 | ) |
| 615 | else: |
| 616 | assert all([abs_slice_shape[i] == out_shape[i] for i in range(naxes)]) |
| 617 | else: |
| 618 | raise ValueError(f"Wrong out_of_bounds_policy: {out_of_bounds_policy}") |
| 619 | |
| 620 | pad_before = [-abs_start[i] if abs_start[i] < 0 else 0 for i in range(naxes)] |
| 621 | pad_after = [abs_end[i] - in_shape[i] if in_shape[i] < abs_end[i] else 0 for i in range(naxes)] |
| 622 | sliced = [abs_slice_shape[i] - pad_before[i] - pad_after[i] for i in range(naxes)] |
| 623 |
no test coverage detected