Skip to content

Commit

Permalink
fixes assertion conditions
Browse files Browse the repository at this point in the history
Signed-off-by: Wenqi Li <wenqil@nvidia.com>
  • Loading branch information
wyli committed Jan 15, 2021
1 parent 5684eb4 commit 691d512
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 12 deletions.
2 changes: 1 addition & 1 deletion monai/inferers/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def sliding_window_inference(
"""
num_spatial_dims = len(inputs.shape) - 2
if 0 > overlap:
if overlap < 0 or overlap >= 1:
raise AssertionError("overlap must be >= 0 and < 1.")

# determine image spatial size and batch size
Expand Down
6 changes: 2 additions & 4 deletions monai/networks/blocks/dynunet_block.py
Original file line number Diff line number Diff line change
Expand Up @@ -277,9 +277,8 @@ def get_padding(
kernel_size_np = np.atleast_1d(kernel_size)
stride_np = np.atleast_1d(stride)
padding_np = (kernel_size_np - stride_np + 1) / 2
error_msg = "padding value should not be negative, please change the kernel size and/or stride."
if np.min(padding_np) < 0:
raise AssertionError(error_msg)
raise AssertionError("padding value should not be negative, please change the kernel size and/or stride.")
padding = tuple(int(p) for p in padding_np)

return padding if len(padding) > 1 else padding[0]
Expand All @@ -295,9 +294,8 @@ def get_output_padding(
padding_np = np.atleast_1d(padding)

out_padding_np = 2 * padding_np + stride_np - kernel_size_np
error_msg = "out_padding value should not be negative, please change the kernel size and/or stride."
if np.min(out_padding_np) < 0:
raise AssertionError(error_msg)
raise AssertionError("out_padding value should not be negative, please change the kernel size and/or stride.")
out_padding = tuple(int(p) for p in out_padding_np)

return out_padding if len(out_padding) > 1 else out_padding[0]
5 changes: 2 additions & 3 deletions monai/networks/nets/dynunet.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,9 +176,8 @@ def check_kernel_stride(self):
def check_deep_supr_num(self):
deep_supr_num, strides = self.deep_supr_num, self.strides
num_up_layers = len(strides) - 1
error_msg = "deep_supr_num should be less than the number of up sample layers."
if 1 > deep_supr_num:
raise AssertionError(error_msg)
if deep_supr_num < 1 or deep_supr_num >= num_up_layers:
raise AssertionError("deep_supr_num should be less than the number of up sample layers.")

def forward(self, x):
out = self.skip_layers(x)
Expand Down
4 changes: 2 additions & 2 deletions monai/transforms/intensity/array.py
Original file line number Diff line number Diff line change
Expand Up @@ -471,9 +471,9 @@ class ScaleIntensityRangePercentiles(Transform):
def __init__(
self, lower: float, upper: float, b_min: float, b_max: float, clip: bool = False, relative: bool = False
) -> None:
if 0.0 > lower:
if lower < 0.0 or lower > 100.0:
raise AssertionError("Percentiles must be in the range [0, 100]")
if 0.0 > upper:
if upper < 0.0 or upper > 100.0:
raise AssertionError("Percentiles must be in the range [0, 100]")
self.lower = lower
self.upper = upper
Expand Down
2 changes: 1 addition & 1 deletion monai/utils/aliases.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def resolve_name(name):
with alias_lock:
obj = GlobalAliases.get(name, None)

if not (name not in GlobalAliases or obj is not None):
if name in GlobalAliases and obj is None:
raise AssertionError

# attempt to resolve a qualified name
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
BUILD_CUDA = (torch.cuda.is_available() and (CUDA_HOME is not None)) or FORCE_CUDA

_pt_version = pkg_resources.parse_version(torch.__version__).release # type: ignore[attr-defined]
if not (_pt_version is not None and len(_pt_version) >= 3):
if _pt_version is None or len(_pt_version) < 3:
raise AssertionError("unknown torch version")
TORCH_VERSION = int(_pt_version[0]) * 10000 + int(_pt_version[1]) * 100 + int(_pt_version[2])
except (ImportError, TypeError, AssertionError, AttributeError) as e:
Expand Down

0 comments on commit 691d512

Please sign in to comment.