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

Function _create_grid_torch

monai/transforms/utils.py:810–834  ·  view source on GitHub ↗

compute a `spatial_size` mesh with the torch API.

(
    spatial_size: Sequence[int],
    spacing: Sequence[float] | None = None,
    homogeneous: bool = True,
    dtype=torch.float32,
    device: torch.device | None = None,
)

Source from the content-addressed store, hash-verified

808
809
810def _create_grid_torch(
811 spatial_size: Sequence[int],
812 spacing: Sequence[float] | None = None,
813 homogeneous: bool = True,
814 dtype=torch.float32,
815 device: torch.device | None = None,
816):
817 """
818 compute a `spatial_size` mesh with the torch API.
819 """
820 spacing = spacing or tuple(1.0 for _ in spatial_size)
821 ranges = [
822 torch.linspace(
823 -(d - 1.0) / 2.0 * s,
824 (d - 1.0) / 2.0 * s,
825 int(d),
826 device=device,
827 dtype=get_equivalent_dtype(dtype, torch.Tensor),
828 )
829 for d, s in zip(spatial_size, spacing)
830 ]
831 coords = meshgrid_ij(*ranges)
832 if not homogeneous:
833 return torch.stack(coords)
834 return torch.stack([*coords, torch.ones_like(coords[0])])
835
836
837def create_control_grid(

Callers 1

create_gridFunction · 0.85

Calls 2

get_equivalent_dtypeFunction · 0.90
meshgrid_ijFunction · 0.90

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…