MCPcopy Create free account
hub / github.com/Project-MONAI/MONAI / _init_identity_cache

Method _init_identity_cache

monai/transforms/spatial/array.py:2497–2519  ·  view source on GitHub ↗

Create cache of the identity grid if cache_grid=True and spatial_size is known.

(self, lazy: bool)

Source from the content-addressed store, hash-verified

2495 self.rand_affine_grid.lazy = val
2496
2497 def _init_identity_cache(self, lazy: bool):
2498 """
2499 Create cache of the identity grid if cache_grid=True and spatial_size is known.
2500 """
2501 if lazy:
2502 return None
2503 if self.spatial_size is None:
2504 if self.cache_grid:
2505 warnings.warn(
2506 "cache_grid=True is not compatible with the dynamic spatial_size, please specify 'spatial_size'."
2507 )
2508 return None
2509 _sp_size = ensure_tuple(self.spatial_size)
2510 _ndim = len(_sp_size)
2511 if _sp_size != fall_back_tuple(_sp_size, [1] * _ndim) or _sp_size != fall_back_tuple(_sp_size, [2] * _ndim):
2512 # dynamic shape because it falls back to different outcomes
2513 if self.cache_grid:
2514 warnings.warn(
2515 "cache_grid=True is not compatible with the dynamic spatial_size "
2516 f"'spatial_size={self.spatial_size}', please specify 'spatial_size'."
2517 )
2518 return None
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 """

Callers 1

__init__Method · 0.95

Calls 3

ensure_tupleFunction · 0.90
fall_back_tupleFunction · 0.90
create_gridFunction · 0.90

Tested by

no test coverage detected