Skip to content

🐍 Geometric Computer Vision Library for Spatial AI

test(feature): resolve Ruff PT018 compound assertions (#5527)

Daniele Lorued9d86ea50fd
diff --git a/tests/feature/test_integrated.py b/tests/feature/test_integrated.py
index 1411a6395..16075a595 100644
--- a/tests/feature/test_integrated.py
+++ b/tests/feature/test_integrated.py
@@ -309,7 +309,8 @@ class TestSIFTFeatureHalfPrecision(BaseTester):
img = torch.rand(1, 1, 64, 64, device=device, dtype=torch.float16)
with torch.no_grad():
lafs, _, descs = SIFTFeature(50).to(device, torch.float16)(img)
- assert lafs.dtype == torch.float16 and descs.dtype == torch.float16
+ assert lafs.dtype == torch.float16
+ assert descs.dtype == torch.float16
assert int(lafs[0].ne(0).any(dim=-1).any(dim=-1).sum()) > 0
assert torch.isfinite(lafs).all()
assert torch.isfinite(descs).all()
@@ -601,7 +602,8 @@ class TestSIFTDescriptorLayoutArgument(BaseTester):
image = torch.rand(1, 1, 64, 64, device=device, dtype=dtype)
default = preset(num_features=8, descriptor_backend=backend).to(device, dtype).eval()
opencv = preset(num_features=8, descriptor_backend=backend, descriptor_layout="opencv").to(device, dtype).eval()
- assert default.descriptor_layout == "kornia" and opencv.descriptor_layout == "opencv"
+ assert default.descriptor_layout == "kornia"
+ assert opencv.descriptor_layout == "opencv"
lafs, responses, descriptors = default(image)
opencv_lafs, opencv_responses, opencv_descriptors = opencv(image)
self.assert_close(opencv_lafs, lafs)
diff --git a/tests/feature/test_laf.py b/tests/feature/test_laf.py
index 8c358672a..2c660eeff 100644
--- a/tests/feature/test_laf.py
+++ b/tests/feature/test_laf.py
@@ -868,8 +868,10 @@ class TestExtractPatchesSimple(BaseTester):
self.assert_close(patches[:, :1], expected_finite)
assert patches[:, 1:].abs().sum().item() == 0
patches.sum().backward()
- assert grad_img.grad is not None and bool(grad_img.grad.isfinite().all())
- assert grad_laf.grad is not None and bool(grad_laf.grad.isfinite().all())
+ assert grad_img.grad is not None
+ assert bool(grad_img.grad.isfinite().all())
+ assert grad_laf.grad is not None
+ assert bool(grad_laf.grad.isfinite().all())
assert grad_laf.grad[:, 1:].abs().sum().item() == 0
def test_same_odd(self, device, dtype):
@@ -1157,8 +1159,10 @@ class TestExtractPatchesPyr(BaseTester):
self.assert_close(patches[:, :1], expected_finite)
assert patches[:, 1:].abs().sum().item() == 0
patches.sum().backward()
- assert grad_img.grad is not None and bool(grad_img.grad.isfinite().all())
- assert grad_laf.grad is not None and bool(grad_laf.grad.isfinite().all())
+ assert grad_img.grad is not None
+ assert bool(grad_img.grad.isfinite().all())
+ assert grad_laf.grad is not None
+ assert bool(grad_laf.grad.isfinite().all())
assert grad_laf.grad[:, 1:].abs().sum().item() == 0
def test_giant_laf_uses_actual_coarsest_level(self, device, dtype):
@@ -1384,7 +1388,8 @@ class TestExtractPatchesPyr(BaseTester):
pyramid = kornia.feature.extract_patches_from_pyramid(img, laf, 16)
reference = kornia.feature.extract_patches_simple(img.float(), laf.float(), 16).to(dtype)
assert simple.dtype == pyramid.dtype == dtype
- assert bool(simple.isfinite().all()) and bool(pyramid.isfinite().all())
+ assert bool(simple.isfinite().all())
+ assert bool(pyramid.isfinite().all())
self.assert_close(simple, reference)
self.assert_close(pyramid, reference)
diff --git a/tests/feature/test_lightglue.py b/tests/feature/test_lightglue.py
index b29d765c0..b66abde22 100644
--- a/tests/feature/test_lightglue.py
+++ b/tests/feature/test_lightglue.py
@@ -263,8 +263,10 @@ class TestTokenConfidence(BaseTester):
d0 = torch.rand(1, 20, 32, device=device, dtype=dtype)
d1 = torch.rand(1, 20, 32, device=device, dtype=dtype)
s0, s1 = tc(d0, d1)
- assert (s0 >= 0).all() and (s0 <= 1).all()
- assert (s1 >= 0).all() and (s1 <= 1).all()
+ assert (s0 >= 0).all()
+ assert (s0 <= 1).all()
+ assert (s1 >= 0).all()
+ assert (s1 <= 1).all()
def test_gradcheck(self, device):
pass # TokenConfidence uses detach() on inputs; not differentiable w.r.t. inputs
diff --git a/tests/feature/test_local_features_orientation.py b/tests/feature/test_local_features_orientation.py
index b9bc0ff1c..78dc28c1e 100644
--- a/tests/feature/test_local_features_orientation.py
+++ b/tests/feature/test_local_features_orientation.py
@@ -178,7 +178,8 @@ class TestOrientationHalfPrecisionIsFinite(BaseTester):
patches = torch.zeros(2, 1, 32, 32, device=device, dtype=ori_dtype, requires_grad=True)
out = PatchDominantGradientOrientation(32).to(device, ori_dtype)(patches)
out.sum().backward()
- assert patches.grad is not None and torch.isfinite(patches.grad).all()
+ assert patches.grad is not None
+ assert torch.isfinite(patches.grad).all()
assert bool((patches.grad == 0).all()), patches.grad.abs().max().item()
@pytest.mark.parametrize("half_dtype", [torch.float16, torch.bfloat16])
diff --git a/tests/feature/test_loftr.py b/tests/feature/test_loftr.py
index 1fb6508dc..87fc1972b 100644
--- a/tests/feature/test_loftr.py
+++ b/tests/feature/test_loftr.py
@@ -171,7 +171,8 @@ class TestCoarseMatching(BaseTester):
n_pad = max(n_train - self.N_PRED, self.CFG["train_pad_num_gt_min"]) # 3
assert out["b_ids"].shape[0] == self.N_PRED + n_pad
assert (out["b_ids"] == 0).all()
- assert (out["i_ids"] < L).all() and (out["j_ids"] < S).all()
+ assert (out["i_ids"] < L).all()
+ assert (out["j_ids"] < S).all()
assert out["i_ids"][: self.N_PRED].tolist() == list(range(self.N_PRED))
assert out["j_ids"][: self.N_PRED].tolist() == list(range(self.N_PRED))
assert (out["i_ids"][self.N_PRED :] == L - 1).all()
diff --git a/tests/feature/test_matching.py b/tests/feature/test_matching.py
index dbdbb5836..d420adb32 100644
--- a/tests/feature/test_matching.py
+++ b/tests/feature/test_matching.py
@@ -753,5 +753,7 @@ class TestCDist(BaseTester):
assert dists[1, 2] == 0.0
loss = dists.sum()
loss.backward()
- assert d1.grad is not None and torch.isfinite(d1.grad).all()
- assert d2.grad is not None and torch.isfinite(d2.grad).all()
+ assert d1.grad is not None
+ assert torch.isfinite(d1.grad).all()
+ assert d2.grad is not None
+ assert torch.isfinite(d2.grad).all()
diff --git a/tests/feature/test_scale_space_detector.py b/tests/feature/test_scale_space_detector.py
index ef6c05819..83d8a4f39 100644
--- a/tests/feature/test_scale_space_detector.py
+++ b/tests/feature/test_scale_space_detector.py
@@ -180,7 +180,8 @@ class TestScaleSpaceDetector(BaseTester):
self.assert_close(a, e)
# The subclass refines each sign of every octave in its own call. The built-in refiner
# stacks both signs into one call, unless a candidate cap keeps it on the separate path.
- assert len(separate_calls) > 0 and len(separate_calls) % 2 == 0
+ assert len(separate_calls) > 0
+ assert len(separate_calls) % 2 == 0
assert len(joint_calls) == (len(separate_calls) if max_candidates is not None else len(separate_calls) // 2)
actual_grad = torch.autograd.grad(sum(x.sum() for x in actual), img, retain_graph=True)[0]
expected_grad = torch.autograd.grad(sum(x.sum() for x in expected), img)[0]
@@ -288,7 +289,8 @@ class TestScaleSpaceDetector(BaseTester):
n_real = int((~zero_laf).sum())
assert bool((~zero_laf[:n_real]).all()), "real detections must come first"
lafs_fwd, resps_fwd = det(inp)
- assert torch.equal(resps_fwd, resps) and torch.equal(lafs_fwd, lafs)
+ assert torch.equal(resps_fwd, resps)
+ assert torch.equal(lafs_fwd, lafs)
def test_negative_detections_sort_before_the_padding(self, device, dtype):
# A signed response function can have every maximum below zero. The padding must still
@@ -319,7 +321,8 @@ class TestScaleSpaceDetector(BaseTester):
filled = lafs[0].ne(0).any(dim=-1).any(dim=-1)
n_real = int(filled.sum())
assert 0 < n_real < 50, f"expected a partially filled result, got {n_real}"
- assert bool(filled[:n_real].all()) and not bool(filled[n_real:].any())
+ assert bool(filled[:n_real].all())
+ assert not bool(filled[n_real:].any())
assert (resps[0, :n_real] < 0).all()
assert (resps[0, n_real:] == 0).all()
@@ -357,7 +360,8 @@ class TestScaleSpaceDetector(BaseTester):
self.assert_close(resps[0][~right], torch.tensor([-0.20, -0.40], device=device, dtype=dtype))
self.assert_close(resps[0][right], torch.tensor([-0.50, -0.60], device=device, dtype=dtype))
assert resps[0].tolist() == sorted(resps[0].tolist(), reverse=True)
- assert xs[0] < 48 and xs[1] < 48, f"a down-weighted candidate outranked a full-weight one: {xs.tolist()}"
+ assert xs[0] < 48, f"a down-weighted candidate outranked a full-weight one: {xs.tolist()}"
+ assert xs[1] < 48, f"a down-weighted candidate outranked a full-weight one: {xs.tolist()}"
def test_a_weighted_negative_response_never_sorts_below_the_padding(self, device, dtype):
# A weight *divides* a negative score, and a small weight can push the quotient past the
@@ -409,7 +413,8 @@ class TestScaleSpaceDetector(BaseTester):
filled1 = lafs1.ne(0).any(dim=-1).any(dim=-1)
filled2 = lafs2.ne(0).any(dim=-1).any(dim=-1)
assert int(filled1.sum()) == 4, f"single-image path lost a detection: {resps1.tolist()}"
- assert int(filled2[0].sum()) == 4 and int(filled2[1].sum()) == 4, f"batched path lost one: {resps2.tolist()}"
+ assert int(filled2[0].sum()) == 4, f"batched path lost one: {resps2.tolist()}"
+ assert int(filled2[1].sum()) == 4, f"batched path lost one: {resps2.tolist()}"
assert torch.isfinite(resps2).all()
self.assert_close(resps2[0], resps1[0])
@@ -431,7 +436,8 @@ class TestScaleSpaceDetector(BaseTester):
mask = torch.zeros(1, 1, 96, 96, device=device, dtype=torch.bool)
mask[..., 32:] = True
lafs, resps = det(img, mask)
- assert bool((lafs == 0).all()) and bool((resps == 0).all()), (
+ assert bool((lafs == 0).all()), f"a refined centre at {lafs[0, 0, :, 2].tolist()} lies in the masked-out region"
+ assert bool((resps == 0).all()), (
f"a refined centre at {lafs[0, 0, :, 2].tolist()} lies in the masked-out region"
)
# Control: the same peak is returned, refined, when the mask allows the pixels it touches.
@@ -477,7 +483,8 @@ class TestScaleSpaceDetector(BaseTester):
det = ScaleSpaceDetector(50).to(device, dtype)
lafs_b, resps_b = det(inp, torch.ones(1, 1, 64, 64, device=device, dtype=torch.bool))
lafs_f, resps_f = det(inp, torch.full((1, 1, 64, 64), 255.0, device=device, dtype=dtype))
- assert torch.equal(resps_f, resps_b) and torch.equal(lafs_f, lafs_b)
+ assert torch.equal(resps_f, resps_b)
+ assert torch.equal(lafs_f, lafs_b)
def test_a_zero_response_maximum_keeps_its_laf(self, device, dtype):
# The response function is pluggable and may be signed, so an exact zero can be a genuine
@@ -567,8 +574,10 @@ class TestScaleSpaceDetector(BaseTester):
valid = lafs.ne(0).any(dim=-1).any(dim=-1)
centers = lafs[..., 2][valid]
assert bool(valid.any())
- assert (centers[:, 0] >= 0).all() and (centers[:, 0] <= 95).all()
- assert (centers[:, 1] >= 0).all() and (centers[:, 1] <= 95).all()
+ assert (centers[:, 0] >= 0).all()
+ assert (centers[:, 0] <= 95).all()
+ assert (centers[:, 1] >= 0).all()
+ assert (centers[:, 1] <= 95).all()
def test_multichannel_response_is_rejected(self, device, dtype):
inp = torch.rand(1, 3, 64, 64, device=device, dtype=dtype)
@@ -732,8 +741,10 @@ class TestMultiResolutionDetector(BaseTester):
lafs, _ = det(inp)
cx = lafs[0, :, 0, 2]
cy = lafs[0, :, 1, 2]
- assert (cx >= 0).all() and (cx <= 64).all()
- assert (cy >= 0).all() and (cy <= 64).all()
+ assert (cx >= 0).all()
+ assert (cx <= 64).all()
+ assert (cy >= 0).all()
+ assert (cy <= 64).all()
def test_no_upscale_levels(self, device, dtype):
# up_levels=0 disables the upsampling branch; should still produce valid output.
@@ -859,7 +870,8 @@ class TestMultiResolutionDetector(BaseTester):
det = self._make_detector().to(device, dtype)
lafs_b, resps_b = det(inp, torch.ones(1, 1, 64, 64, device=device, dtype=torch.bool))
lafs_f, resps_f = det(inp, torch.full((1, 1, 64, 64), 255.0, device=device, dtype=dtype))
- assert torch.equal(resps_f, resps_b) and torch.equal(lafs_f, lafs_b)
+ assert torch.equal(resps_f, resps_b)
+ assert torch.equal(lafs_f, lafs_b)
def test_float_mask_weights_the_score_and_keeps_the_candidates(self, device, dtype):
# A graded mask used to be multiplied into the response before the NMS and the sub-pixel
@@ -881,7 +893,8 @@ class TestMultiResolutionDetector(BaseTester):
self.assert_close(order(lafs[0][keep]), order(lafs_plain[0][keep_plain]))
ratio = resps[0][keep] / resps_plain[0][keep]
- assert float(ratio.min()) >= 0.2 - 1e-2 and float(ratio.max()) <= 1.0 + 1e-2
+ assert float(ratio.min()) >= 0.2 - 1e-2
+ assert float(ratio.max()) <= 1.0 + 1e-2
assert not torch.allclose(resps[0][keep], resps_plain[0][keep_plain])
def test_response_map_must_match_the_level_size(self, device, dtype):
@@ -1011,8 +1024,10 @@ class TestMultiResolutionDetector(BaseTester):
assert bool(found.any())
cx = lafs[0, :, 0, 2]
cy = lafs[0, :, 1, 2]
- assert (cx >= 0).all() and (cx <= 63).all()
- assert (cy >= 0).all() and (cy <= 63).all()
+ assert (cx >= 0).all()
+ assert (cx <= 63).all()
+ assert (cy >= 0).all()
+ assert (cy <= 63).all()
def test_multichannel_response_is_rejected(self, device, dtype):
inp = torch.rand(1, 3, 64, 64, device=device, dtype=dtype)
@@ -1181,7 +1196,8 @@ class TestMultiResolutionDetector(BaseTester):
ref = self._make_detector(num_features=10).to(device, dtype)
lafs, resps = det(inp)
lafs_ref, resps_ref = ref(inp)
- assert torch.equal(lafs, lafs_ref) and torch.equal(resps, resps_ref)
+ assert torch.equal(lafs, lafs_ref)
+ assert torch.equal(resps, resps_ref)
with pytest.raises(TypeError):
det(inp, torch.ones(1, 1, 64, 64, device=device, dtype=dtype))
diff --git a/tests/feature/test_sift_scale_pyramid_optimized.py b/tests/feature/test_sift_scale_pyramid_optimized.py
index d27b8039d..a518ceebe 100644
--- a/tests/feature/test_sift_scale_pyramid_optimized.py
+++ b/tests/feature/test_sift_scale_pyramid_optimized.py
@@ -120,7 +120,8 @@ class TestSIFTScalePyramidCPUOptimized(BaseTester):
actual.square().mean().backward()
expected.square().mean().backward()
- assert actual_input.grad is not None and torch.isfinite(actual_input.grad).all()
+ assert actual_input.grad is not None
+ assert torch.isfinite(actual_input.grad).all()
self.assert_close(actual_input.grad, expected_input.grad)
def test_dynamo(self, device, dtype, torch_optimizer):
diff --git a/tests/feature/test_sift_scale_space.py b/tests/feature/test_sift_scale_space.py
index 3f6e0dcca..0ee732d19 100644
--- a/tests/feature/test_sift_scale_space.py
+++ b/tests/feature/test_sift_scale_space.py
@@ -330,11 +330,16 @@ class TestSharedSIFTScaleSpace(BaseTester):
lafs, responses, descriptors = feature(image, mask)
- assert not lafs.any() and not responses.any() and not descriptors.any()
- assert lafs.requires_grad and responses.requires_grad and descriptors.requires_grad
+ assert not lafs.any()
+ assert not responses.any()
+ assert not descriptors.any()
+ assert lafs.requires_grad
+ assert responses.requires_grad
+ assert descriptors.requires_grad
(lafs.sum() + responses.sum() + descriptors.sum()).backward()
assert image.grad is not None
- assert torch.isfinite(image.grad).all() and not image.grad.any()
+ assert torch.isfinite(image.grad).all()
+ assert not image.grad.any()
def test_float16_tiny_float32_mask_is_suppressed(self, device, dtype):
if dtype != torch.float16:
@@ -344,7 +349,8 @@ class TestSharedSIFTScaleSpace(BaseTester):
detector = _SIFTScaleSpaceDetector(1, _FixedPyramid(dog)).to(device, dtype)
mask = torch.full((1, 1, 32, 32), 1e-10, device=device, dtype=torch.float32)
lafs, responses = detector(image, mask)
- assert not lafs.any() and not responses.any()
+ assert not lafs.any()
+ assert not responses.any()
def test_flat_gradient_backward(self, device, dtype):
image = torch.zeros(1, 1, 1, 32, 32, device=device, dtype=dtype, requires_grad=True)
@@ -405,7 +411,8 @@ class TestSharedSIFTScaleSpace(BaseTester):
weights = torch.linspace(0.1, 1.0, actual.numel(), device=device, dtype=work_dtype).reshape_as(actual)
(actual * weights).sum().backward()
(expected * weights).sum().backward()
- assert actual_images.grad is not None and expected_images.grad is not None
+ assert actual_images.grad is not None
+ assert expected_images.grad is not None
self.assert_close(actual_images.grad, expected_images.grad)
def test_grid_inference_matches_autograd_path(self, device, dtype):
@@ -551,12 +558,14 @@ class TestSIFTScalePyramid(BaseTester):
assert not pyramid.state_dict()
for index, expected in enumerate(reference):
kernel = getattr(pyramid, f"kernel_{index}")
- assert kernel.device.type == device.type and kernel.dtype == kernel_dtype
+ assert kernel.device.type == device.type
+ assert kernel.dtype == kernel_dtype
assert torch.equal(kernel.cpu(), expected.to(kernel_dtype))
pyramid.cpu()
for index, expected in enumerate(reference):
kernel = getattr(pyramid, f"kernel_{index}")
- assert kernel.dtype == torch.float64 and torch.equal(kernel, expected)
+ assert kernel.dtype == torch.float64
+ assert torch.equal(kernel, expected)
def test_whole_module_pickle_rebuilds_kernels_where_they_land(self, device):
from kornia.feature.sift.scale_space import _SIFTScalePyramid
@@ -572,7 +581,8 @@ class TestSIFTScalePyramid(BaseTester):
expected = _SIFTScalePyramid().to(target)
for index in range(6):
kernel, reference = getattr(restored, f"kernel_{index}"), getattr(expected, f"kernel_{index}")
- assert kernel.device.type == target.type and kernel.dtype == reference.dtype
+ assert kernel.device.type == target.type
+ assert kernel.dtype == reference.dtype
assert torch.equal(kernel, reference)
def test_pyramid_backend_rejects_unknown_compile_component(self):
@@ -656,7 +666,8 @@ class TestSIFTScaleSpaceDetector(BaseTester):
loss = sum((value * weights.to(device)).sum() for value in actual[4:7]) + image[..., :0].sum()
reference_loss.backward()
loss.backward()
- assert image.grad is not None and reference_image.grad is not None
+ assert image.grad is not None
+ assert reference_image.grad is not None
assert torch.isfinite(image.grad).all()
self.assert_close(image.grad, reference_image.grad.to(device))
@@ -679,7 +690,8 @@ class TestSIFTScaleSpaceDetector(BaseTester):
dog[0, 2 + ds, 16 + dy, 16 + dx] = sign
detector = _SIFTScaleSpaceDetector(2, _FixedPyramid(dog))
lafs, responses = detector(torch.zeros(1, 1, 32, 32, device=device, dtype=dtype))
- assert not lafs.any() and not responses.any()
+ assert not lafs.any()
+ assert not responses.any()
def test_checkerboard_equal_diagonals_reject_before_neighbourhood_gather(self, device, dtype, monkeypatch):
y = torch.arange(32, device=device).view(1, 1, 32, 1)
@@ -718,7 +730,9 @@ class TestSIFTScaleSpaceDetector(BaseTester):
with torch.inference_mode():
result = detector._octave(gaussian, 0, None)
limit = 16384 if device.type == "cpu" else 65536
- assert len(calls) > 1 and sum(calls) > limit and max(calls) <= limit
+ assert len(calls) > 1
+ assert sum(calls) > limit
+ assert max(calls) <= limit
assert all(value.numel() == 0 for value in result)
def test_many_middle_scale_extrema_refine_in_chunks(self, device, dtype, monkeypatch):
@@ -741,7 +755,9 @@ class TestSIFTScaleSpaceDetector(BaseTester):
with torch.inference_mode():
*_, responses, _, _, _ = detector._octave(gaussian, 0, None)
expected_count = coordinates.numel() ** 2
- assert len(calls) > 1 and sum(calls) == expected_count and max(calls) <= 16384
+ assert len(calls) > 1
+ assert sum(calls) == expected_count
+ assert max(calls) <= 16384
assert responses.numel() == expected_count
self.assert_close(responses, torch.ones_like(responses))
@@ -802,13 +818,15 @@ class TestSIFTScaleSpaceDetector(BaseTester):
assert laf_is_filled(lafs)[:, 0].all()
self.assert_close(weighted[:, 0], unmasked[:, 0] * 0.25, rtol=2e-3, atol=2e-3)
zero_lafs, zero_responses = detector(image, torch.zeros_like(mask))
- assert not zero_lafs.any() and not zero_responses.any()
+ assert not zero_lafs.any()
+ assert not zero_responses.any()
def test_flat_and_singular_refinement_reject_without_oob_access(self, device, dtype):
image = torch.zeros(1, 1, 32, 32, device=device, dtype=dtype)
flat = torch.zeros(1, 5, 32, 32, device=device, dtype=dtype)
lafs, responses = _SIFTScaleSpaceDetector(2, _FixedPyramid(flat)).to(device, dtype)(image)
- assert not lafs.any() and not responses.any()
+ assert not lafs.any()
+ assert not responses.any()
detector = _SIFTScaleSpaceDetector(1, _FixedPyramid(flat)).to(device, dtype)
b = torch.zeros(1, device=device, dtype=torch.long)
s = torch.full_like(b, 2)
diff --git a/tests/feature/test_siftdesc.py b/tests/feature/test_siftdesc.py
index f5968729a..e735c81f0 100644
--- a/tests/feature/test_siftdesc.py
+++ b/tests/feature/test_siftdesc.py
@@ -88,7 +88,8 @@ class TestSIFTDescriptor(BaseTester):
expected[0, 0], expected[1, 4] = descriptors[0, 0], descriptors[1, 4]
# The float32 pi in the bin scale leaked every vote into the bin below (4.3e-8 after normalisation).
self.assert_close(descriptors, expected, rtol=0.0, atol=1e-12)
- assert (descriptors[0, 0] > 0.1).all() and (descriptors[1, 4] > 0.1).all()
+ assert (descriptors[0, 0] > 0.1).all()
+ assert (descriptors[1, 4] > 0.1).all()
@pytest.mark.skip("Compiled functions can't take variable number")
def test_jit(self, device, dtype):
@@ -205,7 +206,8 @@ class TestSIFTConstantPatchIsFinite(BaseTester):
out = SIFTDescriptor(32, rootsift=rootsift).to(device, desc_dtype)(patches)
out.sum().backward()
assert torch.isfinite(out).all()
- assert patches.grad is not None and torch.isfinite(patches.grad).all()
+ assert patches.grad is not None
+ assert torch.isfinite(patches.grad).all()
@pytest.mark.parametrize("desc_dtype", [torch.float16, torch.bfloat16, torch.float32])
@pytest.mark.parametrize("rootsift", [False, True])
@@ -222,7 +224,8 @@ class TestSIFTConstantPatchIsFinite(BaseTester):
out = SIFTDescriptor(16, rootsift=rootsift).to(device, desc_dtype)(patches)
out.sum().backward()
assert torch.isfinite(out).all()
- assert patches.grad is not None and torch.isfinite(patches.grad).all(), patches.grad.abs().max()
+ assert patches.grad is not None, patches.grad.abs().max()
+ assert torch.isfinite(patches.grad).all(), patches.grad.abs().max()
assert bool((patches.grad == 0).all()), f"flat patch has a gradient of {patches.grad.abs().max().item()}"
@pytest.mark.parametrize("desc_dtype", [torch.float16, torch.bfloat16, torch.float32, torch.float64])
@@ -233,7 +236,8 @@ class TestSIFTConstantPatchIsFinite(BaseTester):
pytest.skip("MPS does not support float64")
x = torch.zeros(3, 8, device=device, dtype=desc_dtype, requires_grad=True)
_l2_normalize(x, dim=1).sum().backward()
- assert x.grad is not None and bool((x.grad == 0).all()), x.grad
+ assert x.grad is not None, x.grad
+ assert bool((x.grad == 0).all()), x.grad
# and a non-zero vector keeps `F.normalize`'s value and gradient
torch.manual_seed(0)
y = torch.rand(3, 8, device=device, dtype=desc_dtype, requires_grad=True)
@@ -433,7 +437,8 @@ class TestConvertSIFTDescriptorLayout(BaseTester):
descriptors = torch.rand(2, 5, 128, device=device, dtype=dtype)
converted = convert_sift_descriptor_layout(descriptors, "kornia", "opencv")
assert converted.shape == descriptors.shape
- assert converted.dtype == dtype and converted.device == descriptors.device
+ assert converted.dtype == dtype
+ assert converted.device == descriptors.device
def test_index_mapping(self, device, dtype):
# kornia stores (angle, row, column) and OpenCV (row, column, angle), with the angle bins counted the other
diff --git a/tests/feature/test_xfeat.py b/tests/feature/test_xfeat.py
index b9cc132f2..d102ea7dc 100644
--- a/tests/feature/test_xfeat.py
+++ b/tests/feature/test_xfeat.py
@@ -196,8 +196,10 @@ class TestXFeat(BaseTester):
if out[0]["keypoints"].numel() == 0:
pytest.skip("No keypoints detected on random input")
kpts = out[0]["keypoints"].float()
- assert (kpts[:, 0] >= 0).all() and (kpts[:, 0] < W).all()
- assert (kpts[:, 1] >= 0).all() and (kpts[:, 1] < H).all()
+ assert (kpts[:, 0] >= 0).all()
+ assert (kpts[:, 0] < W).all()
+ assert (kpts[:, 1] >= 0).all()
+ assert (kpts[:, 1] < H).all()
def test_dense_output_shapes(self, device, dtype):
top_k = 32