testlapack: add some helper functions

This commit is contained in:
Vladimir Chalupecky
2016-08-12 10:41:26 +09:00
parent 1ad3375777
commit d093c738ed

View File

@@ -7,6 +7,7 @@ package testlapack
import (
"fmt"
"math"
"math/cmplx"
"math/rand"
"testing"
@@ -950,3 +951,47 @@ func schurBlockSize(t blas64.General, i int) (size int, first bool) {
}
return size, first
}
// containsComplex returns whether z is approximately equal to one of the complex
// numbers in v.
func containsComplex(v []complex128, z complex128, tol float64) bool {
for i := range v {
if cmplx.Abs(v[i]-z) < tol {
return true
}
}
return false
}
func isAllNaN(x []float64) bool {
for _, v := range x {
if !math.IsNaN(v) {
return false
}
}
return true
}
func isAnyNaN(x []float64) bool {
for _, v := range x {
if math.IsNaN(v) {
return true
}
}
return false
}
func isHessenberg(h blas64.General) bool {
if h.Rows != h.Cols {
panic("matrix not square")
}
n := h.Rows
for i := 0; i < n; i++ {
for j := 0; j < n; j++ {
if i > j+1 && h.Data[i*h.Stride+j] != 0 {
return false
}
}
}
return true
}