blas/testblas: split zEqualApprox into 2 functions
MODIFY
blas/testblas/common.go
blas/testblas/common.go
@@ -275,10 +275,9 @@ func zsame(x, y []complex128) bool {
return true
}
-// zEqualApprox returns whether vectors x and y with stride inc
-// are approximately equal within tol. Elements at non-strided
-// positions must be same in both x and y.
-func zEqualApprox(x, y []complex128, inc int, tol float64) bool {
+// zSameAtNonstrided returns whether elements at non-stride positions of vectors
+// x and y are same.
+func zSameAtNonstrided(x, y []complex128, inc int) bool {
if len(x) != len(y) {
return false
}
@@ -286,13 +285,10 @@ func zEqualApprox(x, y []complex128, inc int, tol float64) bool {
inc = -inc
}
for i, v := range x {
- w := y[i]
if i%inc == 0 {
- if cmplx.Abs(v-w) > tol {
- return false
- }
continue
}
+ w := y[i]
if !sameComplex128(v, w) {
return false
}
@@ -300,6 +296,25 @@ func zEqualApprox(x, y []complex128, inc int, tol float64) bool {
return true
}
+// zEqualApprox returns whether elements at stride positions of vectors x and y
+// are approximately equal within tol.
+func zEqualApproxAtStrided(x, y []complex128, inc int, tol float64) bool {
+ if len(x) != len(y) {
+ return false
+ }
+ if inc < 0 {
+ inc = -inc
+ }
+ for i := 0; i < len(x); i += inc {
+ v := x[i]
+ w := y[i]
+ if !(cmplx.Abs(v-w) <= tol) {
+ return false
+ }
+ }
+ return true
+}
+
func makeZVector(data []complex128, inc int) []complex128 {
if inc == 0 {
panic("bad test")

MODIFY
blas/testblas/ztrsv.go
blas/testblas/ztrsv.go
@@ -80,7 +80,10 @@ func ztrsvTest(t *testing.T, impl Ztrsver, uplo blas.Uplo, trans blas.Transpose,
if !zsame(a, aCopy) {
t.Errorf("Case uplo=%v,trans=%v,diag=%v,n=%v,lda=%v,incX=%v: unexpected modification of A", uplo, trans, diag, n, lda, incX)
}
- if !zEqualApprox(x, want, incX, tol) {
+ if !zSameAtNonstrided(x, want, incX) {
+ t.Errorf("Case uplo=%v,trans=%v,diag=%v,n=%v,lda=%v,incX=%v: unexpected modification of x\nwant %v\ngot %v", uplo, trans, diag, n, lda, incX, want, x)
+ }
+ if !zEqualApproxAtStrided(x, want, incX, tol) {
t.Errorf("Case uplo=%v,trans=%v,diag=%v,n=%v,lda=%v,incX=%v: unexpected result\nwant %v\ngot %v", uplo, trans, diag, n, lda, incX, want, x)
}
}

blas/testblas: split zEqualApprox into 2 functions