Skip to content

🐍 Geometric Computer Vision Library for Spatial AI

Merging comparisons with 'in' (#1229)

Edgar Riba6543ca92705d
diff --git a/kornia/augmentation/base.py b/kornia/augmentation/base.py
index c96c87129..75dc4aeea 100644
--- a/kornia/augmentation/base.py
+++ b/kornia/augmentation/base.py
@@ -272,11 +272,11 @@ class AugmentationBase2D(_AugmentationBase):
raise AssertionError('Input tensor is in batch mode ' 'but transformation matrix is not')
if mat.shape[0] != inp.shape[0]:
raise AssertionError(
- f'In batch dimension, input has {inp.shape[0]}' f'but transformation matrix has {mat.shape[0]}'
+ f"In batch dimension, input has {inp.shape[0]} but transformation matrix has {mat.shape[0]}"
)
- elif len(inp.shape) == 3 or len(inp.shape) == 2:
+ elif len(inp.shape) in (2, 3):
if len(mat.shape) != 2:
- raise AssertionError('Input tensor is in non-batch mode ' 'but transformation matrix is not')
+ raise AssertionError("Input tensor is in non-batch mode but transformation matrix is not")
else:
raise ValueError(f'Unrecognized output shape. Expected 2, 3, or 4, got {len(inp.shape)}')
@@ -425,11 +425,11 @@ class AugmentationBase3D(_AugmentationBase):
raise AssertionError('Input tensor is in batch mode ' 'but transformation matrix is not')
if mat.shape[0] != inp.shape[0]:
raise AssertionError(
- f'In batch dimension, input has {inp.shape[0]}' f'but transformation matrix has {mat.shape[0]}'
+ f"In batch dimension, input has {inp.shape[0]} but transformation matrix has {mat.shape[0]}"
)
- elif len(inp.shape) == 3 or len(inp.shape) == 4:
+ elif len(inp.shape) in (3, 4):
if len(mat.shape) != 2:
- raise AssertionError('Input tensor is in non-batch mode ' 'but transformation matrix is not')
+ raise AssertionError("Input tensor is in non-batch mode but transformation matrix is not")
else:
raise ValueError(f'Unrecognized output shape. Expected 3, 4 or 5, got {len(inp.shape)}')
@@ -469,11 +469,11 @@ class MixAugmentationBase(_BasicAugmentationBase):
raise AssertionError('Input tensor is in batch mode ' 'but transformation matrix is not')
if mat.shape[0] != inp.shape[0]:
raise AssertionError(
- f'In batch dimension, input has {inp.shape[0]}' f'but transformation matrix has {mat.shape[0]}'
+ f"In batch dimension, input has {inp.shape[0]} but transformation matrix has {mat.shape[0]}"
)
- elif len(inp.shape) == 3 or len(inp.shape) == 2:
+ elif len(inp.shape) in (2, 3):
if len(mat.shape) != 2:
- raise AssertionError('Input tensor is in non-batch mode ' 'but transformation matrix is not')
+ raise AssertionError("Input tensor is in non-batch mode but transformation matrix is not")
else:
raise ValueError(f'Unrecognized output shape. Expected 2, 3, or 4, got {len(inp.shape)}')
diff --git a/kornia/augmentation/random_generator/random_generator.py b/kornia/augmentation/random_generator/random_generator.py
index 098d1f837..28201bebf 100644
--- a/kornia/augmentation/random_generator/random_generator.py
+++ b/kornia/augmentation/random_generator/random_generator.py
@@ -226,7 +226,7 @@ def random_affine_generator(
# compute tensor ranges
if scale is not None:
scale = scale.to(device=device, dtype=dtype)
- if not (len(scale.shape) == 1 and (len(scale) == 2 or len(scale) == 4)):
+ if not (len(scale.shape) == 1 and len(scale) in (2, 4)):
raise AssertionError(f"`scale` shall have 2 or 4 elements. Got {scale}.")
_joint_range_check(cast(torch.Tensor, scale[:2]), "scale")
_scale = _adapted_uniform((batch_size,), scale[0], scale[1], same_on_batch).unsqueeze(1).repeat(1, 2)
diff --git a/test/geometry/test_pinhole.py b/test/geometry/test_pinhole.py
index 399b8d3a2..956e58c79 100644
--- a/test/geometry/test_pinhole.py
+++ b/test/geometry/test_pinhole.py
@@ -88,7 +88,7 @@ class TestCam2Pixel:
atol, rtol = 1e-5, 1e-3
# Different tolerances for the below case.
- if (device.type == "cuda") and ((dtype == "float64") or (dtype == torch.float64)):
+ if (device.type == "cuda") and (dtype == torch.float64):
atol, rtol = 1e-4, 1e-2
# If contiguous() is not called, gradcheck fails