blas/testblas: add znan variable and use it in tests
MODIFY
blas/testblas/common.go
blas/testblas/common.go
@@ -15,6 +15,8 @@ import (
// throwPanic will throw unexpected panics if true, or will just report them as errors if false
const throwPanic = true
+var znan = cmplx.NaN()
+
func dTolEqual(a, b float64) bool {
if math.IsNaN(a) && math.IsNaN(b) {
return true
@@ -325,7 +327,7 @@ func makeZVector(data []complex128, inc int) []complex128 {
inc = abs(inc)
x := make([]complex128, (len(data)-1)*inc+1)
for i := range x {
- x[i] = cmplx.NaN()
+ x[i] = znan
}
for i, v := range data {
x[i*inc] = v
@@ -348,7 +350,7 @@ func makeZGeneral(data []complex128, m, n int, ld int) []complex128 {
}
a := make([]complex128, (m-1)*ld+n)
for i := range a {
- a[i] = cmplx.NaN()
+ a[i] = znan
}
if data != nil {
for i := 0; i < m; i++ {

MODIFY
blas/testblas/dzasum.go
blas/testblas/dzasum.go
package testblas
import (
- "math/cmplx"
"testing"
"golang.org/x/exp/rand"
@@ -28,7 +27,7 @@ func DzasumTest(t *testing.T, impl Dzasumer) {
x = make([]complex128, (n-1)*aincX+1)
}
for i := range x {
- x[i] = cmplx.NaN()
+ x[i] = znan
}
for i := 0; i < n; i++ {
re := float64(2*i + 1)

MODIFY
blas/testblas/dznrm2.go
blas/testblas/dznrm2.go
@@ -7,7 +7,6 @@ package testblas
import (
"fmt"
"math"
- "math/cmplx"
"testing"
"golang.org/x/exp/rand"
@@ -122,7 +121,7 @@ func Dznrm2Test(t *testing.T, impl Dznrm2er) {
x := make([]complex128, (n-1)*incX+1)
for i := range x {
- x[i] = cmplx.NaN()
+ x[i] = znan
}
for i := range re {
x[i*incX] = complex(re[i], im[i])

MODIFY
blas/testblas/izamax.go
blas/testblas/izamax.go
package testblas
import (
- "math/cmplx"
"testing"
"golang.org/x/exp/rand"
@@ -25,7 +24,7 @@ func IzamaxTest(t *testing.T, impl Izamaxer) {
x = make([]complex128, (n-1)*aincX+1)
}
for i := range x {
- x[i] = cmplx.NaN()
+ x[i] = znan
}
for i := 0; i < n; i++ {
re := 2*rnd.Float64() - 1

MODIFY
blas/testblas/zcopy.go
blas/testblas/zcopy.go
@@ -6,8 +6,6 @@ package testblas
import (
"fmt"
- "math"
- "math/cmplx"
"testing"
"golang.org/x/exp/rand"
@@ -31,7 +29,7 @@ func ZcopyTest(t *testing.T, impl Zcopyer) {
x = make([]complex128, (n-1)*aincX+1)
}
for i := range x {
- x[i] = complex(math.NaN(), math.NaN())
+ x[i] = znan
}
for i := 0; i < n; i++ {
x[i*aincX] = complex(rnd.NormFloat64(), rnd.NormFloat64())
@@ -44,12 +42,12 @@ func ZcopyTest(t *testing.T, impl Zcopyer) {
y = make([]complex128, (n-1)*aincY+1)
}
for i := range y {
- y[i] = complex(math.NaN(), math.NaN())
+ y[i] = znan
}
want := make([]complex128, len(y))
for i := range want {
- want[i] = cmplx.NaN()
+ want[i] = znan
}
if incX*incY > 0 {
for i := 0; i < n; i++ {

MODIFY
blas/testblas/zhemv.go
blas/testblas/zhemv.go
package testblas
import (
- "math/cmplx"
"testing"
"gonum.org/v1/gonum/blas"
@@ -39,9 +38,9 @@ var zhemvTestCases = []struct {
alpha: 6 + 2i,
a: []complex128{
7, 8 + 4i, -9 - 6i, -9 + 3i,
- 0, -3, -10 - 6i, 0 + 3i,
- 0, 0, 6, 2 + 8i,
- 0, 0, 0, -4,
+ znan, -3, -10 - 6i, 0 + 3i,
+ znan, znan, 6, 2 + 8i,
+ znan, znan, znan, -4,
},
x: []complex128{
-4 + 0i,
@@ -85,9 +84,9 @@ var zhemvTestCases = []struct {
uplo: blas.Lower,
alpha: 6 + 2i,
a: []complex128{
- 7, 0, 0, 0,
- 8 - 4i, -3, 0, 0,
- -9 + 6i, -10 + 6i, 6, 0,
+ 7, znan, znan, znan,
+ 8 - 4i, -3, znan, znan,
+ -9 + 6i, -10 + 6i, 6, znan,
-9 - 3i, 0 - 3i, 2 - 8i, -4,
},
x: []complex128{
@@ -133,9 +132,9 @@ var zhemvTestCases = []struct {
alpha: 0,
a: []complex128{
7, 8 + 4i, -9 - 6i, -9 + 3i,
- 0, -3, -10 - 6i, 0 + 3i,
- 0, 0, 6, 2 + 8i,
- 0, 0, 0, -4,
+ znan, -3, -10 - 6i, 0 + 3i,
+ znan, znan, 6, 2 + 8i,
+ znan, znan, znan, -4,
},
x: []complex128{
-4 + 0i,
@@ -180,9 +179,9 @@ var zhemvTestCases = []struct {
alpha: 6 + 2i,
a: []complex128{
7, 8 + 4i, -9 - 6i, -9 + 3i,
- 0, -3, -10 - 6i, 0 + 3i,
- 0, 0, 6, 2 + 8i,
- 0, 0, 0, -4,
+ znan, -3, -10 - 6i, 0 + 3i,
+ znan, znan, 6, 2 + 8i,
+ znan, znan, znan, -4,
},
x: []complex128{
-4 + 0i,
@@ -229,30 +228,15 @@ type Zhemver interface {
}
func ZhemvTest(t *testing.T, impl Zhemver) {
- nan := cmplx.NaN()
for tc, test := range zhemvTestCases {
n := len(test.x)
for _, incX := range []int{-11, -2, -1, 1, 2, 7} {
for _, incY := range []int{-11, -2, -1, 1, 2, 7} {
for _, lda := range []int{max(1, n), n + 11} {
-
alpha := test.alpha
beta := test.beta
a := makeZGeneral(test.a, n, n, lda)
- if test.uplo == blas.Upper {
- for i := 0; i < n; i++ {
- for j := 0; j < i; j++ {
- a[i*lda+j] = nan
- }
- }
- } else {
- for i := 0; i < n; i++ {
- for j := i + 1; j < n; j++ {
- a[i*lda+j] = nan
- }
- }
- }
aCopy := make([]complex128, len(a))
copy(aCopy, a)

MODIFY
blas/testblas/zher.go
blas/testblas/zher.go
package testblas
import (
- "math/cmplx"
"testing"
"gonum.org/v1/gonum/blas"
@@ -126,15 +125,15 @@ func ZherTest(t *testing.T, impl Zherer) {
if uplo == blas.Upper {
for i := 0; i < n; i++ {
for j := 0; j < i; j++ {
- a[i*lda+j] = cmplx.NaN()
- want[i*lda+j] = cmplx.NaN()
+ a[i*lda+j] = znan
+ want[i*lda+j] = znan
}
}
} else {
for i := 0; i < n; i++ {
for j := i + 1; j < n; j++ {
- a[i*lda+j] = cmplx.NaN()
- want[i*lda+j] = cmplx.NaN()
+ a[i*lda+j] = znan
+ want[i*lda+j] = znan
}
}
}

MODIFY
blas/testblas/zher2.go
blas/testblas/zher2.go
package testblas
import (
- "math/cmplx"
"testing"
"gonum.org/v1/gonum/blas"
@@ -284,15 +283,15 @@ func Zher2Test(t *testing.T, impl Zher2er) {
if uplo == blas.Upper {
for i := 0; i < n; i++ {
for j := 0; j < i; j++ {
- a[i*lda+j] = cmplx.NaN()
- want[i*lda+j] = cmplx.NaN()
+ a[i*lda+j] = znan
+ want[i*lda+j] = znan
}
}
} else {
for i := 0; i < n; i++ {
for j := i + 1; j < n; j++ {
- a[i*lda+j] = cmplx.NaN()
- want[i*lda+j] = cmplx.NaN()
+ a[i*lda+j] = znan
+ want[i*lda+j] = znan
}
}
}

MODIFY
blas/testblas/zswap.go
blas/testblas/zswap.go
@@ -6,7 +6,6 @@ package testblas
import (
"fmt"
- "math/cmplx"
"testing"
"golang.org/x/exp/rand"
@@ -31,10 +30,10 @@ func ZswapTest(t *testing.T, impl Zswaper) {
y = make([]complex128, (n-1)*aincY+1)
}
for i := range x {
- x[i] = cmplx.NaN()
+ x[i] = znan
}
for i := range y {
- y[i] = cmplx.NaN()
+ y[i] = znan
}
for i := 0; i < n; i++ {
x[i*aincX] = complex(rnd.NormFloat64(), rnd.NormFloat64())
@@ -43,11 +42,11 @@ func ZswapTest(t *testing.T, impl Zswaper) {
xWant := make([]complex128, len(x))
for i := range xWant {
- xWant[i] = cmplx.NaN()
+ xWant[i] = znan
}
yWant := make([]complex128, len(y))
for i := range yWant {
- yWant[i] = cmplx.NaN()
+ yWant[i] = znan
}
if incX*incY > 0 {
for i := 0; i < n; i++ {

MODIFY
blas/testblas/ztrmv.go
blas/testblas/ztrmv.go
package testblas
import (
- "math/cmplx"
"testing"
"gonum.org/v1/gonum/blas"
@@ -38,9 +37,9 @@ var ztrmvTestCases = []struct {
uplo: blas.Upper,
a: []complex128{
6 - 8i, -10 + 10i, -6 - 3i, -1 - 8i,
- 0, 7 + 8i, -7 + 9i, 3 + 6i,
- 0, 0, 6 - 4i, -2 - 5i,
- 0, 0, 0, 4 - 8i,
+ znan, 7 + 8i, -7 + 9i, 3 + 6i,
+ znan, znan, 6 - 4i, -2 - 5i,
+ znan, znan, znan, 4 - 8i,
},
x: []complex128{
10 - 5i,
@@ -126,9 +125,9 @@ var ztrmvTestCases = []struct {
{
uplo: blas.Lower,
a: []complex128{
- 10 - 8i, 0, 0, 0,
- 1 - 6i, -4 + 8i, 0, 0,
- 2 - 6i, 4 - 8i, 5 + 3i, 0,
+ 10 - 8i, znan, znan, znan,
+ 1 - 6i, -4 + 8i, znan, znan,
+ 2 - 6i, 4 - 8i, 5 + 3i, znan,
-7 - 4i, 1 + 3i, -2 - 4i, 9 + 8i,
},
x: []complex128{
@@ -219,7 +218,6 @@ type Ztrmver interface {
}
func ZtrmvTest(t *testing.T, impl Ztrmver) {
- nan := cmplx.NaN()
for tc, test := range ztrmvTestCases {
n := len(test.x)
uplo := test.uplo
@@ -228,22 +226,9 @@ func ZtrmvTest(t *testing.T, impl Ztrmver) {
for _, incX := range []int{-11, -2, -1, 1, 2, 7} {
for _, lda := range []int{max(1, n), n + 11} {
a := makeZGeneral(test.a, n, n, lda)
- if uplo == blas.Upper {
- for i := 0; i < n; i++ {
- for j := 0; j < i; j++ {
- a[i*lda+j] = nan
- }
- }
- } else {
- for i := 0; i < n; i++ {
- for j := i + 1; j < n; j++ {
- a[i*lda+j] = nan
- }
- }
- }
if diag == blas.Unit {
for i := 0; i < n; i++ {
- a[i*lda+i] = nan
+ a[i*lda+i] = znan
}
}
aCopy := make([]complex128, len(a))

MODIFY
blas/testblas/ztrsv.go
blas/testblas/ztrsv.go
package testblas
import (
- "math/cmplx"
"testing"
"golang.org/x/exp/rand"
@@ -58,7 +57,7 @@ func ztrsvTest(t *testing.T, impl Ztrsver, uplo blas.Uplo, trans blas.Transpose,
}
if diag == blas.Unit {
for i := 0; i < n; i++ {
- a[i*lda+i] = cmplx.NaN()
+ a[i*lda+i] = znan
}
}
aCopy := make([]complex128, len(a))

blas/testblas: add znan variable and use it in tests