mirror of
https://github.com/gonum/gonum.git
synced 2025-10-26 00:30:27 +08:00
testlapack: add isIdentity helper
This commit is contained in:
committed by
Vladimír Chalupecký
parent
27d556d1f9
commit
87489715e5
@@ -1464,3 +1464,28 @@ func constructGSVPresults(n, p, m, k, l int, a, b blas64.General) (zeroA, zeroB
|
||||
|
||||
return zeroA, zeroB
|
||||
}
|
||||
|
||||
// isIdentity returns whether an n×n matrix A is approximately equal to the
|
||||
// identity matrix.
|
||||
func isIdentity(n int, a []float64, lda int, tol float64) bool {
|
||||
for i := 0; i < n; i++ {
|
||||
for j := 0; j < n; j++ {
|
||||
aij := a[i*lda+j]
|
||||
if math.IsNaN(aij) {
|
||||
return false
|
||||
}
|
||||
if i == j {
|
||||
if math.Abs(aij-1) > tol {
|
||||
fmt.Println(i, j, aij)
|
||||
return false
|
||||
}
|
||||
} else {
|
||||
if math.Abs(aij) > tol {
|
||||
fmt.Println(i, j, aij)
|
||||
return false
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user