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.
12 var dotTests = []struct {
14 wantu, wantc complex128
15 wantuRev, wantcRev complex128
23 wantuRev: 0, wantcRev: 0,
26 x: []complex128{1 + 1i},
27 y: []complex128{1 + 1i},
29 wantu: 0 + 2i, wantc: 2,
30 wantuRev: 0 + 2i, wantcRev: 2,
33 x: []complex128{1 + 2i},
34 y: []complex128{1 + 1i},
36 wantu: -1 + 3i, wantc: 3 - 1i,
37 wantuRev: -1 + 3i, wantcRev: 3 - 1i,
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},
43 wantu: -210 + 2860i, wantc: 2870 + 0i,
44 wantuRev: -210 + 1540i, wantcRev: 1550 + 0i,
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},
50 wantu: -22 + 36i, wantc: 42 + 4i,
51 wantuRev: -22 + 36i, wantcRev: 42 + 4i,
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},
57 wantu: -10 + 37i, wantc: 34 + 17i,
58 wantuRev: -10 + 36i, wantcRev: 34 + 16i,
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},
64 wantu: complex(inf, inf), wantc: complex(inf, inf),
65 wantuRev: complex(inf, inf), wantcRev: complex(inf, inf),
69 func TestDotcUnitary(t *testing.T) {
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)
81 if !isValidGuard(xg, gd, xgLn) {
82 t.Errorf(msgGuard, prefix, "x", xg[:xgLn], xg[len(xg)-xgLn:])
84 if !isValidGuard(yg, gd, ygLn) {
85 t.Errorf(msgGuard, prefix, "y", yg[:ygLn], yg[len(yg)-ygLn:])
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]
100 ix, want = -inc.x*(test.n-1), test.wantcRev
103 iy, want = -inc.y*(test.n-1), test.wantcRev
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))
110 if !same(res, want) {
111 t.Errorf(msgVal, prefix, i, res, want)
114 checkValidIncGuard(t, xg, gd, inc.x, gdLn)
115 checkValidIncGuard(t, yg, gd, inc.y, gdLn)
120 func TestDotuUnitary(t *testing.T) {
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)
132 if !isValidGuard(xg, gd, xgLn) {
133 t.Errorf(msgGuard, prefix, "x", xg[:xgLn], xg[len(xg)-xgLn:])
135 if !isValidGuard(yg, gd, ygLn) {
136 t.Errorf(msgGuard, prefix, "y", yg[:ygLn], yg[len(yg)-ygLn:])
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]
152 ix, want = -inc.x*(test.n-1), test.wantuRev
155 iy, want = -inc.y*(test.n-1), test.wantuRev
157 res := DotuInc(x, y, uintptr(test.n), uintptr(inc.x), uintptr(inc.y), uintptr(ix), uintptr(iy))
161 if !same(res, want) {
162 t.Errorf(msgVal, prefix, i, res, want)
164 checkValidIncGuard(t, xg, gd, inc.x, gdLn)
165 checkValidIncGuard(t, yg, gd, inc.y, gdLn)