Skip to content

Commit

Permalink
lapack/gonum: propagate NaN from Dgecon
Browse files Browse the repository at this point in the history
  • Loading branch information
vladimir-ch committed Jul 29, 2023
1 parent 194082c commit fbaba96
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions lapack/gonum/dgecon.go
Expand Up @@ -18,11 +18,11 @@ import (
//
// The slice a contains the result of the LU decomposition of A as computed by Dgetrf.
//
// anorm is the corresponding 1-norm or ∞-norm of the original matrix A.
// anorm is the corresponding 1-norm or ∞-norm of the original matrix A. anorm
// must be non-negative.
//
// work is a temporary data slice of length at least 4*n and Dgecon will panic otherwise.
//
// iwork is a temporary data slice of length at least n and Dgecon will panic otherwise.
// work must have length at least 4*n and iwork must have length at least n,
// otherwise Dgecon will panic.
func (impl Implementation) Dgecon(norm lapack.MatrixNorm, n int, a []float64, lda int, anorm float64, work []float64, iwork []int) float64 {
switch {
case norm != lapack.MaxColumnSum && norm != lapack.MaxRowSum:
Expand All @@ -31,6 +31,8 @@ func (impl Implementation) Dgecon(norm lapack.MatrixNorm, n int, a []float64, ld
panic(nLT0)
case lda < max(1, n):
panic(badLdA)
case anorm < 0:
panic(negANorm)
}

// Quick return if possible.
Expand All @@ -51,6 +53,12 @@ func (impl Implementation) Dgecon(norm lapack.MatrixNorm, n int, a []float64, ld
if anorm == 0 {
return 0
}
if math.IsNaN(anorm) {
// The reference implementation treats the NaN anorm as invalid and
// returns an error code. Our error handling is to panic which seems too
// harsh for a runtime condition, so we just propagate the NaN instead.
return anorm
}

bi := blas64.Implementation()
var rcond, ainvnm float64
Expand Down

0 comments on commit fbaba96

Please sign in to comment.