#4633·kornia

AugmentationSequential.identity_matrix is unreachable: 0 calls across 1197 tests

Author: ducha-aikiCreated Sep 17, 2026Updated Sep 17, 2026

AugmentationSequential.identity_matrix (kornia/augmentation/container/augment.py:395) overrides the base implementation to return a 4x4 identity when the container holds 3D augmentations:

python
def identity_matrix(self, input: torch.Tensor) -> torch.Tensor:
    """Return identity matrix."""
    if self.contains_3d_augmentation:
        return eye_like(4, input)
    return eye_like(3, input)

No call site reaches it. Every identity_matrix call in the package is made on a child module, not on the container. The container-level one is kornia/augmentation/container/image.py:362:

python
mat = module.identity_matrix(input) if _mat is None else _mat

module, i.e. the child augmentation, whose own identity_matrix comes from RigidAffineAugmentationBase2D/3D. The remaining call sites (_2d/base.py:257, :339, _2d/intensity/base.py:131, _2d/geometric/pad.py:91, _3d/base.py:101, _3d/intensity/equalize.py:77, auto/operations/policy.py:96) are all self.identity_matrix inside a leaf augmentation.

Measured

Patched the override to count invocations and ran the suite:

tests/augmentation/container + tests/augmentation/test_augmentation.py
  --device=cpu --dtype=float32
  1197 passed, 293 skipped, 18 xfailed, 5 xpassed

>>> AugmentationSequential.identity_matrix called 0 times; callers=set()

Zero calls. That is why a mutation of its predicate (if self.contains_3d_augmentation -> if not self.contains_3d_augmentation) survives the whole augmentation suite — I hit this while mutation-testing #4618, where it was the one mutant of thirteen that lived.

Why it matters

It is dead code that silently absorbs mutation-testing budget and gives a false impression of coverage for the 3D container path. Either something should be calling it — in which case the 3D container is returning a 3x3 identity where a 4x4 is intended, and that is a real defect — or it should be deleted.

Worth deciding which, rather than leaving it. Pre-existing; it is not introduced by any recent PR.

Environment: torch 2.14.0, CPU, macOS arm64, main at 3f748920e.

Posted on behalf of @ducha-aiki by Claude (Opus 5).