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

Function _create_grid_numpy

monai/transforms/utils.py:793–807  ·  view source on GitHub ↗

compute a `spatial_size` mesh with the numpy API.

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

Source from the content-addressed store, hash-verified

791
792
793def _create_grid_numpy(
794 spatial_size: Sequence[int],
795 spacing: Sequence[float] | None = None,
796 homogeneous: bool = True,
797 dtype: DtypeLike | torch.dtype = float,
798):
799 """
800 compute a `spatial_size` mesh with the numpy API.
801 """
802 spacing = spacing or tuple(1.0 for _ in spatial_size)
803 ranges = [np.linspace(-(d - 1.0) / 2.0 * s, (d - 1.0) / 2.0 * s, int(d)) for d, s in zip(spatial_size, spacing)]
804 coords = np.asarray(np.meshgrid(*ranges, indexing="ij"), dtype=get_equivalent_dtype(dtype, np.ndarray))
805 if not homogeneous:
806 return coords
807 return np.concatenate([coords, np.ones_like(coords[:1])])
808
809
810def _create_grid_torch(

Callers 1

create_gridFunction · 0.85

Calls 1

get_equivalent_dtypeFunction · 0.90

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…