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,
)
| 808 | |
| 809 | |
| 810 | def _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 | |
| 837 | def create_control_grid( |
no test coverage detected
searching dependent graphs…