From d093c738edfabf6d983c357ba65ec4d411e55c6b Mon Sep 17 00:00:00 2001 From: Vladimir Chalupecky Date: Fri, 12 Aug 2016 10:41:26 +0900 Subject: [PATCH] testlapack: add some helper functions --- testlapack/general.go | 45 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/testlapack/general.go b/testlapack/general.go index 14bdd9f6..26611a2e 100644 --- a/testlapack/general.go +++ b/testlapack/general.go @@ -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 +}