Skip to content

Commit a6bc4cd

Browse files
Implement math.prod() improvements from CodeRabbit review
- Use math.prod() for cleaner normalization calculations - Replace manual multiplication loops with built-in function - Maintains all functionality while improving code readability - Formatting fixes from pre-commit hooks
1 parent c8eae2b commit a6bc4cd

File tree

1 file changed

+4
-9
lines changed

1 file changed

+4
-9
lines changed

monai/transforms/signal/radial_fourier.py

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
from __future__ import annotations
1616

17+
import math
1718
from collections.abc import Sequence
1819
from typing import Optional, Union
1920

@@ -182,9 +183,7 @@ def __call__(self, img: NdarrayOrTensor) -> NdarrayOrTensor:
182183

183184
# Normalize if requested
184185
if self.normalize:
185-
norm_factor = 1
186-
for dim in spatial_shape:
187-
norm_factor *= dim
186+
norm_factor = math.prod(spatial_shape)
188187
spectrum = spectrum / norm_factor
189188

190189
# Compute radial coordinates
@@ -208,9 +207,7 @@ def __call__(self, img: NdarrayOrTensor) -> NdarrayOrTensor:
208207
spatial_size = spectrum_flat.shape[-1]
209208

210209
# Reshape to 2D: (non_spatial_product, spatial_size)
211-
non_spatial_product = 1
212-
for dim in non_spatial_dims:
213-
non_spatial_product *= dim
210+
non_spatial_product = math.prod(non_spatial_dims)
214211

215212
spectrum_2d = spectrum_flat.reshape(non_spatial_product, spatial_size)
216213

@@ -289,9 +286,7 @@ def inverse(self, radial_data: NdarrayOrTensor, original_shape: tuple[int, ...])
289286
result = fftshift(result, dim=self.spatial_dims)
290287

291288
if self.normalize:
292-
shape_product = 1
293-
for dim in original_shape:
294-
shape_product *= dim
289+
shape_product = math.prod(original_shape)
295290
result = result * shape_product
296291

297292
result, *_ = convert_data_type(result.real, type(radial_data))

0 commit comments

Comments
 (0)