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

Function create_rotate

monai/transforms/utils.py:862–897  ·  view source on GitHub ↗

create a 2D or 3D rotation matrix Args: spatial_dims: {``2``, ``3``} spatial rank radians: rotation radians when spatial_dims == 3, the `radians` sequence corresponds to rotation in the 1st, 2nd, and 3rd dim respectively. device: device to co

(
    spatial_dims: int,
    radians: Sequence[float] | float,
    device: torch.device | None = None,
    backend: str = TransformBackends.NUMPY,
)

Source from the content-addressed store, hash-verified

860
861
862def create_rotate(
863 spatial_dims: int,
864 radians: Sequence[float] | float,
865 device: torch.device | None = None,
866 backend: str = TransformBackends.NUMPY,
867) -> NdarrayOrTensor:
868 """
869 create a 2D or 3D rotation matrix
870
871 Args:
872 spatial_dims: {``2``, ``3``} spatial rank
873 radians: rotation radians
874 when spatial_dims == 3, the `radians` sequence corresponds to
875 rotation in the 1st, 2nd, and 3rd dim respectively.
876 device: device to compute and store the output (when the backend is "torch").
877 backend: APIs to use, ``numpy`` or ``torch``.
878
879 Raises:
880 ValueError: When ``radians`` is empty.
881 ValueError: When ``spatial_dims`` is not one of [2, 3].
882
883 """
884 _backend = look_up_option(backend, TransformBackends)
885 if _backend == TransformBackends.NUMPY:
886 return _create_rotate(
887 spatial_dims=spatial_dims, radians=radians, sin_func=np.sin, cos_func=np.cos, eye_func=np.eye
888 )
889 if _backend == TransformBackends.TORCH:
890 return _create_rotate(
891 spatial_dims=spatial_dims,
892 radians=radians,
893 sin_func=lambda th: torch.sin(torch.as_tensor(th, dtype=torch.float32, device=device)),
894 cos_func=lambda th: torch.cos(torch.as_tensor(th, dtype=torch.float32, device=device)),
895 eye_func=lambda rank: torch.eye(rank, device=device),
896 )
897 raise ValueError(f"backend {backend} is not supported")
898
899
900def _create_rotate(

Callers 6

rotateFunction · 0.90
rotate90Function · 0.90
__call__Method · 0.90
test_create_rotateMethod · 0.90

Calls 3

look_up_optionFunction · 0.90
_create_rotateFunction · 0.85
as_tensorMethod · 0.80

Tested by 2

test_create_rotateMethod · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…