1 // Copyright ©2015 The Gonum Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
13 nan = float32(math.NaN())
14 inf = float32(math.Inf(1))
17 func same(x, y float32) bool {
18 a, b := float64(x), float64(y)
19 return a == b || (math.IsNaN(a) && math.IsNaN(b))
22 func same64(a, b float64) bool {
23 return a == b || (math.IsNaN(a) && math.IsNaN(b))
26 func guardVector(v []float32, g float32, gdLn int) (guarded []float32) {
27 guarded = make([]float32, len(v)+gdLn*2)
28 copy(guarded[gdLn:], v)
29 for i := 0; i < gdLn; i++ {
31 guarded[len(guarded)-1-i] = g
36 func isValidGuard(v []float32, g float32, gdLn int) bool {
37 for i := 0; i < gdLn; i++ {
38 if !same(v[i], g) || !same(v[len(v)-1-i], g) {
45 func guardIncVector(vec []float32, gdVal float32, inc, gdLen int) (guarded []float32) {
49 inrLen := len(vec) * inc
50 guarded = make([]float32, inrLen+gdLen*2)
51 for i := range guarded {
54 for i, v := range vec {
55 guarded[gdLen+i*inc] = v
60 func checkValidIncGuard(t *testing.T, v []float32, g float32, inc, gdLn int) {
61 srcLn := len(v) - 2*gdLn
67 t.Error("Front guard violated at", i, v[:gdLn])
69 t.Error("Back guard violated at", i-gdLn-srcLn, v[gdLn+srcLn:])
70 case (i-gdLn)%inc == 0 && (i-gdLn)/inc < len(v):
72 t.Error("Internal guard violated at", i-gdLn, v[gdLn:gdLn+srcLn])
77 var ( // Offset sets for testing alignment handling in Unitary assembly functions.
78 align2 = newIncSet(0, 1, 2, 3)
79 align3 = newIncToSet(0, 1, 2, 3)
86 // genInc will generate all (x,y) combinations of the input increment set.
87 func newIncSet(inc ...int) []incSet {
89 is := make([]incSet, n*n)
92 is[x*n+y] = incSet{inc[x], inc[y]}
98 type incToSet struct {
102 // genIncTo will generate all (dst,x,y) combinations of the input increment set.
103 func newIncToSet(inc ...int) []incToSet {
105 is := make([]incToSet, n*n*n)
106 for i, dst := range inc {
109 is[i*n*n+x*n+y] = incToSet{dst, inc[x], inc[y]}