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,
)
| 791 | |
| 792 | |
| 793 | def _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 | |
| 810 | def _create_grid_torch( |
no test coverage detected
searching dependent graphs…