create a scaling matrix Args: spatial_dims: spatial rank scaling_factor: scaling factors for every spatial dim, defaults to 1. device: device to compute and store the output (when the backend is "torch"). backend: APIs to use, ``numpy`` or ``torch``.
(
spatial_dims: int,
scaling_factor: Sequence[float] | float,
device: torch.device | str | None = None,
backend=TransformBackends.NUMPY,
)
| 1013 | |
| 1014 | |
| 1015 | def create_scale( |
| 1016 | spatial_dims: int, |
| 1017 | scaling_factor: Sequence[float] | float, |
| 1018 | device: torch.device | str | None = None, |
| 1019 | backend=TransformBackends.NUMPY, |
| 1020 | ) -> NdarrayOrTensor: |
| 1021 | """ |
| 1022 | create a scaling matrix |
| 1023 | |
| 1024 | Args: |
| 1025 | spatial_dims: spatial rank |
| 1026 | scaling_factor: scaling factors for every spatial dim, defaults to 1. |
| 1027 | device: device to compute and store the output (when the backend is "torch"). |
| 1028 | backend: APIs to use, ``numpy`` or ``torch``. |
| 1029 | """ |
| 1030 | _backend = look_up_option(backend, TransformBackends) |
| 1031 | if _backend == TransformBackends.NUMPY: |
| 1032 | return _create_scale(spatial_dims=spatial_dims, scaling_factor=scaling_factor, array_func=np.diag) |
| 1033 | if _backend == TransformBackends.TORCH: |
| 1034 | return _create_scale( |
| 1035 | spatial_dims=spatial_dims, |
| 1036 | scaling_factor=scaling_factor, |
| 1037 | array_func=lambda x: torch.diag(torch.as_tensor(x, device=device)), |
| 1038 | ) |
| 1039 | raise ValueError(f"backend {backend} is not supported") |
| 1040 | |
| 1041 | |
| 1042 | def _create_scale(spatial_dims: int, scaling_factor: Sequence[float] | float, array_func=np.diag) -> NdarrayOrTensor: |
no test coverage detected
searching dependent graphs…