Skip to content

Commit aea3856

Browse files
Remove unnecessary PyTorch fallbacks per CodeRabbit review
- MONAI requires PyTorch ≥ 2.4.1, so fallbacks for older versions are unnecessary - Simplify _compute_radial_coordinates method - Clarify inverse() docstring about supported cases - Formatting fixes from pre-commit hooks
1 parent a6bc4cd commit aea3856

File tree

1 file changed

+3
-18
lines changed

1 file changed

+3
-18
lines changed

monai/transforms/signal/radial_fourier.py

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -99,26 +99,11 @@ def _compute_radial_coordinates(self, shape: tuple[int, ...], device: torch.devi
9999
coords = []
100100
for dim_size in shape:
101101
# Create frequency range from -0.5 to 0.5
102-
# Compatible with older PyTorch versions
103-
if hasattr(torch.fft, 'fftfreq'):
104-
freq = torch.fft.fftfreq(dim_size, device=device)
105-
else:
106-
# Fallback for older PyTorch versions (pre-1.8)
107-
n = dim_size
108-
val = 1.0 / n
109-
freq = torch.arange(-(n//2), (n+1)//2, device=device) * val
110-
freq = torch.roll(freq, n//2)
102+
freq = torch.fft.fftfreq(dim_size, device=device)
111103
coords.append(freq)
112104

113105
# Create meshgrid and compute radial distance
114-
# Compatible with older PyTorch versions (pre-1.10)
115-
try:
116-
mesh = torch.meshgrid(coords, indexing="ij")
117-
except TypeError:
118-
# Older PyTorch doesn't support indexing parameter
119-
mesh = torch.meshgrid(coords)
120-
# Note: older meshgrid uses ij indexing by default in PyTorch
121-
106+
mesh = torch.meshgrid(coords, indexing="ij")
122107
radial = torch.sqrt(torch.stack([c**2 for c in mesh]).sum(dim=0))
123108

124109
return radial
@@ -258,7 +243,7 @@ def inverse(self, radial_data: NdarrayOrTensor, original_shape: tuple[int, ...])
258243
Reconstructed spatial data.
259244
260245
Note:
261-
This is an approximate inverse when radial_bins is used.
246+
Only exact inverse is supported (radial_bins=None). Raises NotImplementedError otherwise.
262247
"""
263248
if self.radial_bins is None:
264249
# Direct inverse FFT

0 commit comments

Comments
 (0)