OSDN Git Service

new repo
[bytom/vapor.git] / vendor / gonum.org / v1 / gonum / internal / asm / c128 / util_test.go
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.
4
5 package c128
6
7 import (
8         "math"
9         "testing"
10 )
11
12 const (
13         msgVal   = "%v: unexpected value at %v Got: %v Expected: %v"
14         msgGuard = "%v: Guard violated in %s vector %v %v"
15 )
16
17 var (
18         inf       = math.Inf(1)
19         benchSink complex128
20 )
21
22 func same(x, y complex128) bool {
23         return (x == y ||
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)))
27 }
28
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
35         }
36         return guarded
37 }
38
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 {
42                         return false
43                 }
44         }
45         return true
46 }
47
48 func guardIncVector(vec []complex128, guard_val complex128, inc, guard_len int) (guarded []complex128) {
49         s_ln := len(vec) * inc
50         if inc < 0 {
51                 s_ln = len(vec) * -inc
52         }
53         guarded = make([]complex128, s_ln+guard_len*2)
54         for i, cas := 0, 0; i < len(guarded); i++ {
55                 switch {
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):
59                         guarded[i] = vec[cas]
60                         cas++
61                 default:
62                         guarded[i] = guard_val
63                 }
64         }
65         return guarded
66 }
67
68 func checkValidIncGuard(t *testing.T, vec []complex128, guard_val complex128, inc, guard_len int) {
69         s_ln := len(vec) - 2*guard_len
70         if inc < 0 {
71                 s_ln = len(vec) * -inc
72         }
73
74         for i := range vec {
75                 switch {
76                 case vec[i] == guard_val:
77                         // Correct value
78                 case i < guard_len:
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
84                 default:
85                         t.Errorf("Internal guard violated at %d %v", i-guard_len, vec[guard_len:guard_len+s_ln])
86                 }
87         }
88 }
89
90 var ( // Offset sets for testing alignment handling in Unitary assembly functions.
91         align1 = []int{0, 1}
92         align2 = newIncSet(0, 1)
93         align3 = newIncToSet(0, 1)
94 )
95
96 type incSet struct {
97         x, y int
98 }
99
100 // genInc will generate all (x,y) combinations of the input increment set.
101 func newIncSet(inc ...int) []incSet {
102         n := len(inc)
103         is := make([]incSet, n*n)
104         for x := range inc {
105                 for y := range inc {
106                         is[x*n+y] = incSet{inc[x], inc[y]}
107                 }
108         }
109         return is
110 }
111
112 type incToSet struct {
113         dst, x, y int
114 }
115
116 // genIncTo will generate all (dst,x,y) combinations of the input increment set.
117 func newIncToSet(inc ...int) []incToSet {
118         n := len(inc)
119         is := make([]incToSet, n*n*n)
120         for i, dst := range inc {
121                 for x := range inc {
122                         for y := range inc {
123                                 is[i*n*n+x*n+y] = incToSet{dst, inc[x], inc[y]}
124                         }
125                 }
126         }
127         return is
128 }