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:
+13
-1
@@ -48,7 +48,19 @@ func Cholesky(a *core.Array) (*core.Array, error) {
|
||||
return nil, base.Errf("Cholesky: needs a square 2-D matrix, got shape %s", base.ShapeText(a.Shape()))
|
||||
}
|
||||
n := a.Shape()[0]
|
||||
lMat, err := denseCholFactor(denseFloats(a, n, n), n)
|
||||
aMat := denseFloats(a, n, n)
|
||||
// A non-finite entry is neither positive nor definite, but the pivot
|
||||
// test below cannot see it: NaN fails every comparison, so the sweep
|
||||
// would return an all-NaN factor with a nil error. The sparse twin
|
||||
// refuses the same input, and so does this one.
|
||||
for i := range n {
|
||||
for j := range n {
|
||||
if math.IsNaN(aMat[i*n+j]) || math.IsInf(aMat[i*n+j], 0) {
|
||||
return nil, base.Errf("Cholesky: entry [%d,%d] is not finite", i, j)
|
||||
}
|
||||
}
|
||||
}
|
||||
lMat, err := denseCholFactor(aMat, n)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user