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

Function create_scale

monai/transforms/utils.py:1015–1039  ·  view source on GitHub ↗

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,
)

Source from the content-addressed store, hash-verified

1013
1014
1015def 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
1042def _create_scale(spatial_dims: int, scaling_factor: Sequence[float] | float, array_func=np.diag) -> NdarrayOrTensor:

Callers 4

zoom_boxesFunction · 0.90
__call__Method · 0.90
compute_w_affineMethod · 0.90
scale_affineFunction · 0.85

Calls 3

look_up_optionFunction · 0.90
_create_scaleFunction · 0.85
as_tensorMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…