create a translation matrix Args: spatial_dims: spatial rank shift: translate pixel/voxel for every spatial dim, defaults to 0. device: device to compute and store the output (when the backend is "torch"). backend: APIs to use, ``numpy`` or ``torch``.
(
spatial_dims: int,
shift: Sequence[float] | float,
device: torch.device | None = None,
backend=TransformBackends.NUMPY,
)
| 1045 | |
| 1046 | |
| 1047 | def create_translate( |
| 1048 | spatial_dims: int, |
| 1049 | shift: Sequence[float] | float, |
| 1050 | device: torch.device | None = None, |
| 1051 | backend=TransformBackends.NUMPY, |
| 1052 | ) -> NdarrayOrTensor: |
| 1053 | """ |
| 1054 | create a translation matrix |
| 1055 | |
| 1056 | Args: |
| 1057 | spatial_dims: spatial rank |
| 1058 | shift: translate pixel/voxel for every spatial dim, defaults to 0. |
| 1059 | device: device to compute and store the output (when the backend is "torch"). |
| 1060 | backend: APIs to use, ``numpy`` or ``torch``. |
| 1061 | """ |
| 1062 | _backend = look_up_option(backend, TransformBackends) |
| 1063 | spatial_dims = int(spatial_dims) |
| 1064 | if _backend == TransformBackends.NUMPY: |
| 1065 | return _create_translate(spatial_dims=spatial_dims, shift=shift, eye_func=np.eye, array_func=np.asarray) |
| 1066 | if _backend == TransformBackends.TORCH: |
| 1067 | return _create_translate( |
| 1068 | spatial_dims=spatial_dims, |
| 1069 | shift=shift, |
| 1070 | eye_func=lambda x: torch.eye(torch.as_tensor(x), device=device), # type: ignore |
| 1071 | array_func=lambda x: torch.as_tensor(x, device=device), |
| 1072 | ) |
| 1073 | raise ValueError(f"backend {backend} is not supported") |
| 1074 | |
| 1075 | |
| 1076 | def _create_translate( |
no test coverage detected
searching dependent graphs…