Skip to content

Commit 20db2c0

Browse files
committed
Test additional properties of H.
1 parent ba9bf21 commit 20db2c0

1 file changed

Lines changed: 11 additions & 0 deletions

File tree

tests/unit/sparse/test_linalg.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,18 @@ def test_hnf_decomposition(shape: tuple[int, int], max_rank: int):
2525

2626
rank = H.shape[1]
2727

28+
# Note that with these assert, the rank is typically correct as it is at most max_rank, which it
29+
# is with high probability, and we can reconstruct A=H @ V, so the rank of H is at least that of
30+
# A, similarly, the rank of H is at most that of A.
2831
assert rank <= max_rank
2932
assert torch.equal(V @ U, torch.eye(rank, dtype=torch.int64))
3033
assert torch.equal(H @ V, A)
3134
assert torch.equal(A @ U, H)
35+
36+
# Check H is upper triangular
37+
mask = torch.triu(torch.ones(shape[0], rank, dtype=torch.bool), diagonal=1)
38+
assert torch.all(H[mask] == 0).item()
39+
40+
# Check pivots are positive
41+
pivots = H.diag()[:rank]
42+
return torch.all(pivots > 0).item()

0 commit comments

Comments
 (0)