fix(linalg): refuse non-finite input in dense Cholesky, Eigen and rank-one updates

Assisted-by: GLM 5.3 Flash
This commit is contained in:
2026-09-27 11:12:43 +02:00
parent af4ee19703
commit 7bc030c78b
10 changed files with 144 additions and 11 deletions
+15
View File
@@ -691,3 +691,18 @@ func TestCholeskyBlockedReconstruction(t *testing.T) {
}
}
}
// TestCholeskyRefusesNonFinite pins the refusal of a poisoned matrix:
// the pivot test cannot see a NaN (it fails every comparison), so
// without the gate the sweep would answer an all-NaN factor with a nil
// error, where the sparse sibling refuses the same input.
func TestCholeskyRefusesNonFinite(t *testing.T) {
nan := mustFromFloats(t, []float64{math.NaN(), 0, 0, 1}, 2, 2)
if _, err := Cholesky(nan); err == nil || !strings.Contains(err.Error(), "not finite") {
t.Fatalf("Cholesky(NaN): %v", err)
}
inf := mustFromFloats(t, []float64{0, 0, 0, math.Inf(1)}, 2, 2)
if _, err := Cholesky(inf); err == nil || !strings.Contains(err.Error(), "not finite") {
t.Fatalf("Cholesky(Inf): %v", err)
}
}