Return a cached or new identity grid depends on the availability. Args: spatial_size: non-dynamic spatial size
(self, spatial_size: Sequence[int], lazy: bool)
| 2519 | return create_grid(spatial_size=_sp_size, device=self.rand_affine_grid.device, backend="torch") |
| 2520 | |
| 2521 | def get_identity_grid(self, spatial_size: Sequence[int], lazy: bool): |
| 2522 | """ |
| 2523 | Return a cached or new identity grid depends on the availability. |
| 2524 | |
| 2525 | Args: |
| 2526 | spatial_size: non-dynamic spatial size |
| 2527 | """ |
| 2528 | if lazy: |
| 2529 | return None |
| 2530 | ndim = len(spatial_size) |
| 2531 | if spatial_size != fall_back_tuple(spatial_size, [1] * ndim) or spatial_size != fall_back_tuple( |
| 2532 | spatial_size, [2] * ndim |
| 2533 | ): |
| 2534 | raise RuntimeError(f"spatial_size should not be dynamic, got {spatial_size}.") |
| 2535 | return ( |
| 2536 | create_grid(spatial_size=spatial_size, device=self.rand_affine_grid.device, backend="torch") |
| 2537 | if self._cached_grid is None |
| 2538 | else self._cached_grid |
| 2539 | ) |
| 2540 | |
| 2541 | def set_random_state(self, seed: int | None = None, state: np.random.RandomState | None = None) -> RandAffine: |
| 2542 | self.rand_affine_grid.set_random_state(seed, state) |
no test coverage detected