mirror of
https://github.com/gonum/gonum.git
synced 2025-10-05 15:16:59 +08:00
testlapack: add isIdentity helper
This commit is contained in:

committed by
Vladimír Chalupecký

parent
27d556d1f9
commit
87489715e5
@@ -5,7 +5,6 @@
|
||||
package testlapack
|
||||
|
||||
import (
|
||||
"math"
|
||||
"testing"
|
||||
|
||||
"golang.org/x/exp/rand"
|
||||
@@ -21,40 +20,19 @@ func TestDlagsy(t *testing.T) {
|
||||
if lda == 0 {
|
||||
lda = max(1, n)
|
||||
}
|
||||
// D is the identity matrix I.
|
||||
d := make([]float64, n)
|
||||
for i := range d {
|
||||
d[i] = 1
|
||||
}
|
||||
a := blas64.General{
|
||||
Rows: n,
|
||||
Cols: n,
|
||||
Stride: lda,
|
||||
Data: nanSlice(n * lda),
|
||||
}
|
||||
work := make([]float64, a.Rows+a.Cols)
|
||||
|
||||
Dlagsy(a.Rows, 0, d, a.Data, a.Stride, rnd, work)
|
||||
|
||||
isIdentity := true
|
||||
identityLoop:
|
||||
for i := 0; i < n; i++ {
|
||||
for j := 0; j < n; j++ {
|
||||
aij := a.Data[i*a.Stride+j]
|
||||
if math.IsNaN(aij) {
|
||||
isIdentity = false
|
||||
}
|
||||
if i == j && math.Abs(aij-1) > tol {
|
||||
isIdentity = false
|
||||
}
|
||||
if i != j && math.Abs(aij) > tol {
|
||||
isIdentity = false
|
||||
}
|
||||
if !isIdentity {
|
||||
break identityLoop
|
||||
}
|
||||
}
|
||||
}
|
||||
if !isIdentity {
|
||||
// Allocate an n×n symmetric matrix A and fill it with NaNs.
|
||||
a := nanSlice(n * lda)
|
||||
work := make([]float64, 2*n)
|
||||
// Compute A = U * D * U^T where U is a random orthogonal matrix.
|
||||
Dlagsy(n, 0, d, a, lda, rnd, work)
|
||||
// A should be the identity matrix because
|
||||
// A = U * D * U^T = U * I * U^T = U * U^T = I.
|
||||
if !isIdentity(n, a, lda, tol) {
|
||||
t.Errorf("Case n=%v,lda=%v: unexpected result", n, lda)
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user