blas/testblas: add zEqualApprox

This commit is contained in:
Vladimir Chalupecky
2017-11-27 22:06:25 +01:00
committed by Vladimír Chalupecký
parent f74a50354d
commit 65c0b63e47

View File

@@ -254,22 +254,46 @@ func allPairs(x, y []int) [][2]int {
return p return p
} }
func sameFloat64(a, b float64) bool {
return a == b || math.IsNaN(a) && math.IsNaN(b)
}
func sameComplex128(x, y complex128) bool {
return sameFloat64(real(x), real(y)) && sameFloat64(imag(x), imag(y))
}
func zsame(x, y []complex128) bool { func zsame(x, y []complex128) bool {
if len(x) != len(y) { if len(x) != len(y) {
return false return false
} }
for i, v := range x { for i, v := range x {
w := y[i] w := y[i]
if math.IsNaN(real(v)) && math.IsNaN(imag(v)) && math.IsNaN(real(w)) && math.IsNaN(imag(w)) { if !sameComplex128(v, w) {
return false
}
}
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 {
if len(x) != len(y) {
return false
}
if inc < 0 {
inc = -inc
}
for i, v := range x {
w := y[i]
if i%inc == 0 {
if cmplx.Abs(v-w) > tol {
return false
}
continue continue
} }
if math.IsNaN(real(v)) && math.IsNaN(real(w)) && imag(v) == imag(w) { if !sameComplex128(v, w) {
continue
}
if math.IsNaN(imag(v)) && math.IsNaN(imag(w)) && real(v) == real(w) {
continue
}
if v != w {
return false return false
} }
} }