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
+12
View File
@@ -55,6 +55,18 @@ func EigenComplex(a *core.Array) (values, vectors *core.Array, err error) {
if !hermitianOK(h, n) {
return nil, nil, base.Errf("EigenComplex: matrix is not Hermitian within 1e-12 tolerance")
}
// A non-finite entry slips through the Hermitian test above: the
// difference of a NaN and its conjugate never exceeds the tolerance.
// The sparse twin refuses it in its own guard, and so does this one,
// before the Jacobi sweep burns its passes on a poisoned matrix.
for i := range n {
for j := range n {
z := h[i*n+j]
if math.IsNaN(real(z)) || math.IsNaN(imag(z)) || math.IsInf(real(z), 0) || math.IsInf(imag(z), 0) {
return nil, nil, base.Errf("EigenComplex: entry [%d,%d] is not finite", i, j)
}
}
}
// The Jacobi sweep's convergence test is a sum of squared
// magnitudes: outside the safe window it overflows to +Inf, which
// makes every sweep look already converged, or underflows to 0,