1 // Copyright ©2016 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 msgVal = "%v: unexpected value at %v Got: %v Expected: %v"
14 msgGuard = "%v: Guard violated in %s vector %v %v"
22 func same(x, y complex128) bool {
24 math.IsNaN(real(x)) && math.IsNaN(real(y)) && imag(x) == imag(y) ||
25 math.IsNaN(imag(y)) && math.IsNaN(imag(x)) && real(y) == real(x) ||
26 math.IsNaN(real(x)) && math.IsNaN(real(y)) && math.IsNaN(imag(y)) && math.IsNaN(imag(x)))
29 func guardVector(vec []complex128, guard_val complex128, guard_len int) (guarded []complex128) {
30 guarded = make([]complex128, len(vec)+guard_len*2)
31 copy(guarded[guard_len:], vec)
32 for i := 0; i < guard_len; i++ {
33 guarded[i] = guard_val
34 guarded[len(guarded)-1-i] = guard_val
39 func isValidGuard(vec []complex128, guard_val complex128, guard_len int) bool {
40 for i := 0; i < guard_len; i++ {
41 if vec[i] != guard_val || vec[len(vec)-1-i] != guard_val {
48 func guardIncVector(vec []complex128, guard_val complex128, inc, guard_len int) (guarded []complex128) {
49 s_ln := len(vec) * inc
51 s_ln = len(vec) * -inc
53 guarded = make([]complex128, s_ln+guard_len*2)
54 for i, cas := 0, 0; i < len(guarded); i++ {
56 case i < guard_len, i > guard_len+s_ln:
57 guarded[i] = guard_val
58 case (i-guard_len)%(inc) == 0 && cas < len(vec):
62 guarded[i] = guard_val
68 func checkValidIncGuard(t *testing.T, vec []complex128, guard_val complex128, inc, guard_len int) {
69 s_ln := len(vec) - 2*guard_len
71 s_ln = len(vec) * -inc
76 case vec[i] == guard_val:
79 t.Errorf("Front guard violated at %d %v", i, vec[:guard_len])
80 case i > guard_len+s_ln:
81 t.Errorf("Back guard violated at %d %v", i-guard_len-s_ln, vec[guard_len+s_ln:])
82 case (i-guard_len)%inc == 0 && (i-guard_len)/inc < len(vec):
83 // Ignore input values
85 t.Errorf("Internal guard violated at %d %v", i-guard_len, vec[guard_len:guard_len+s_ln])
90 var ( // Offset sets for testing alignment handling in Unitary assembly functions.
92 align2 = newIncSet(0, 1)
93 align3 = newIncToSet(0, 1)
100 // genInc will generate all (x,y) combinations of the input increment set.
101 func newIncSet(inc ...int) []incSet {
103 is := make([]incSet, n*n)
106 is[x*n+y] = incSet{inc[x], inc[y]}
112 type incToSet struct {
116 // genIncTo will generate all (dst,x,y) combinations of the input increment set.
117 func newIncToSet(inc ...int) []incToSet {
119 is := make([]incToSet, n*n*n)
120 for i, dst := range inc {
123 is[i*n*n+x*n+y] = incToSet{dst, inc[x], inc[y]}