OSDN Git Service

test (#52)
[bytom/vapor.git] / vendor / gonum.org / v1 / gonum / internal / asm / c128 / dot_test.go
1 // Copyright ©2017 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         "fmt"
9         "testing"
10 )
11
12 var dotTests = []struct {
13         x, y               []complex128
14         wantu, wantc       complex128
15         wantuRev, wantcRev complex128
16         n                  int
17 }{
18         {
19                 x:     []complex128{},
20                 y:     []complex128{},
21                 n:     0,
22                 wantu: 0, wantc: 0,
23                 wantuRev: 0, wantcRev: 0,
24         },
25         {
26                 x:     []complex128{1 + 1i},
27                 y:     []complex128{1 + 1i},
28                 n:     1,
29                 wantu: 0 + 2i, wantc: 2,
30                 wantuRev: 0 + 2i, wantcRev: 2,
31         },
32         {
33                 x:     []complex128{1 + 2i},
34                 y:     []complex128{1 + 1i},
35                 n:     1,
36                 wantu: -1 + 3i, wantc: 3 - 1i,
37                 wantuRev: -1 + 3i, wantcRev: 3 - 1i,
38         },
39         {
40                 x:     []complex128{1 + 2i, 3 + 4i, 5 + 6i, 7 + 8i, 9 + 10i, 11 + 12i, 13 + 14i, 15 + 16i, 17 + 18i, 19 + 20i},
41                 y:     []complex128{1 + 2i, 3 + 4i, 5 + 6i, 7 + 8i, 9 + 10i, 11 + 12i, 13 + 14i, 15 + 16i, 17 + 18i, 19 + 20i},
42                 n:     10,
43                 wantu: -210 + 2860i, wantc: 2870 + 0i,
44                 wantuRev: -210 + 1540i, wantcRev: 1550 + 0i,
45         },
46         {
47                 x:     []complex128{1 + 1i, 1 + 1i, 1 + 2i, 1 + 1i, 1 + 1i, 1 + 1i, 1 + 3i, 1 + 1i, 1 + 1i, 1 + 4i},
48                 y:     []complex128{1 + 2i, 1 + 2i, 1 + 2i, 1 + 2i, 1 + 2i, 1 + 2i, 1 + 2i, 1 + 2i, 1 + 2i, 1 + 2i},
49                 n:     10,
50                 wantu: -22 + 36i, wantc: 42 + 4i,
51                 wantuRev: -22 + 36i, wantcRev: 42 + 4i,
52         },
53         {
54                 x:     []complex128{1 + 1i, 1 + 1i, 2 + 1i, 1 + 1i, 1 + 1i, 1 + 1i, 1 + 1i, 1 + 1i, 1 + 1i, 2 + 1i},
55                 y:     []complex128{1 + 2i, 1 + 2i, 1 + 3i, 1 + 2i, 1 + 3i, 1 + 2i, 1 + 2i, 1 + 2i, 1 + 2i, 1 + 2i},
56                 n:     10,
57                 wantu: -10 + 37i, wantc: 34 + 17i,
58                 wantuRev: -10 + 36i, wantcRev: 34 + 16i,
59         },
60         {
61                 x:     []complex128{1 + 1i, 1 + 1i, 1 + 1i, 1 + 1i, complex(inf, 1), 1 + 1i, 1 + 1i, 1 + 1i, 1 + 1i, 1 + 1i},
62                 y:     []complex128{1 + 2i, 1 + 2i, 1 + 2i, 1 + 2i, 1 + 2i, 1 + 2i, 1 + 2i, 1 + 2i, 1 + 2i, 1 + 2i},
63                 n:     10,
64                 wantu: complex(inf, inf), wantc: complex(inf, inf),
65                 wantuRev: complex(inf, inf), wantcRev: complex(inf, inf),
66         },
67 }
68
69 func TestDotcUnitary(t *testing.T) {
70         const gd = 1 + 5i
71         for i, test := range dotTests {
72                 for _, align := range align2 {
73                         prefix := fmt.Sprintf("Test %v (x:%v y:%v)", i, align.x, align.y)
74                         xgLn, ygLn := 4+align.x, 4+align.y
75                         xg, yg := guardVector(test.x, gd, xgLn), guardVector(test.y, gd, ygLn)
76                         x, y := xg[xgLn:len(xg)-xgLn], yg[ygLn:len(yg)-ygLn]
77                         res := DotcUnitary(x, y)
78                         if !same(res, test.wantc) {
79                                 t.Errorf(msgVal, prefix, i, res, test.wantc)
80                         }
81                         if !isValidGuard(xg, gd, xgLn) {
82                                 t.Errorf(msgGuard, prefix, "x", xg[:xgLn], xg[len(xg)-xgLn:])
83                         }
84                         if !isValidGuard(yg, gd, ygLn) {
85                                 t.Errorf(msgGuard, prefix, "y", yg[:ygLn], yg[len(yg)-ygLn:])
86                         }
87                 }
88         }
89 }
90
91 func TestDotcInc(t *testing.T) {
92         const gd, gdLn = 2 + 5i, 4
93         for i, test := range dotTests {
94                 for _, inc := range newIncSet(1, 2, 5, 10, -1, -2, -5, -10) {
95                         xg, yg := guardIncVector(test.x, gd, inc.x, gdLn), guardIncVector(test.y, gd, inc.y, gdLn)
96                         x, y := xg[gdLn:len(xg)-gdLn], yg[gdLn:len(yg)-gdLn]
97                         want := test.wantc
98                         var ix, iy int
99                         if inc.x < 0 {
100                                 ix, want = -inc.x*(test.n-1), test.wantcRev
101                         }
102                         if inc.y < 0 {
103                                 iy, want = -inc.y*(test.n-1), test.wantcRev
104                         }
105                         prefix := fmt.Sprintf("Test %v (x:%v y:%v) (ix:%v iy:%v)", i, inc.x, inc.y, ix, iy)
106                         res := DotcInc(x, y, uintptr(test.n), uintptr(inc.x), uintptr(inc.y), uintptr(ix), uintptr(iy))
107                         if inc.x*inc.y > 0 {
108                                 want = test.wantc
109                         }
110                         if !same(res, want) {
111                                 t.Errorf(msgVal, prefix, i, res, want)
112                                 t.Error(x, y)
113                         }
114                         checkValidIncGuard(t, xg, gd, inc.x, gdLn)
115                         checkValidIncGuard(t, yg, gd, inc.y, gdLn)
116                 }
117         }
118 }
119
120 func TestDotuUnitary(t *testing.T) {
121         const gd = 1 + 5i
122         for i, test := range dotTests {
123                 for _, align := range align2 {
124                         prefix := fmt.Sprintf("Test %v (x:%v y:%v)", i, align.x, align.y)
125                         xgLn, ygLn := 4+align.x, 4+align.y
126                         xg, yg := guardVector(test.x, gd, xgLn), guardVector(test.y, gd, ygLn)
127                         x, y := xg[xgLn:len(xg)-xgLn], yg[ygLn:len(yg)-ygLn]
128                         res := DotuUnitary(x, y)
129                         if !same(res, test.wantu) {
130                                 t.Errorf(msgVal, prefix, i, res, test.wantu)
131                         }
132                         if !isValidGuard(xg, gd, xgLn) {
133                                 t.Errorf(msgGuard, prefix, "x", xg[:xgLn], xg[len(xg)-xgLn:])
134                         }
135                         if !isValidGuard(yg, gd, ygLn) {
136                                 t.Errorf(msgGuard, prefix, "y", yg[:ygLn], yg[len(yg)-ygLn:])
137                         }
138                 }
139         }
140 }
141
142 func TestDotuInc(t *testing.T) {
143         const gd, gdLn = 1 + 5i, 4
144         for i, test := range dotTests {
145                 for _, inc := range newIncSet(1, 2, 5, 10, -1, -2, -5, -10) {
146                         prefix := fmt.Sprintf("Test %v (x:%v y:%v)", i, inc.x, inc.y)
147                         xg, yg := guardIncVector(test.x, gd, inc.x, gdLn), guardIncVector(test.y, gd, inc.y, gdLn)
148                         x, y := xg[gdLn:len(xg)-gdLn], yg[gdLn:len(yg)-gdLn]
149                         want := test.wantc
150                         var ix, iy int
151                         if inc.x < 0 {
152                                 ix, want = -inc.x*(test.n-1), test.wantuRev
153                         }
154                         if inc.y < 0 {
155                                 iy, want = -inc.y*(test.n-1), test.wantuRev
156                         }
157                         res := DotuInc(x, y, uintptr(test.n), uintptr(inc.x), uintptr(inc.y), uintptr(ix), uintptr(iy))
158                         if inc.x*inc.y > 0 {
159                                 want = test.wantu
160                         }
161                         if !same(res, want) {
162                                 t.Errorf(msgVal, prefix, i, res, want)
163                         }
164                         checkValidIncGuard(t, xg, gd, inc.x, gdLn)
165                         checkValidIncGuard(t, yg, gd, inc.y, gdLn)
166                 }
167         }
168 }