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.
12 var tests = []struct {
13 incX, incY, incDst int
16 dst, x, y []complex128
19 {incX: 2, incY: 2, incDst: 3, ix: 0, iy: 0, idst: 0,
24 ex: []complex128{1 + 2i}},
25 {incX: 2, incY: 2, incDst: 3, ix: 0, iy: 0, idst: 0,
27 dst: []complex128{0, 0, 0},
28 x: []complex128{0, 0, 0},
29 y: []complex128{1, 1, 1},
30 ex: []complex128{1, 1, 1}},
31 {incX: 2, incY: 2, incDst: 3, ix: 0, iy: 0, idst: 0,
33 dst: []complex128{0, 0, 0},
34 x: []complex128{0, 0},
35 y: []complex128{1, 1, 1},
36 ex: []complex128{1, 1}},
37 {incX: 2, incY: 2, incDst: 3, ix: 0, iy: 0, idst: 0,
39 dst: []complex128{1i, 1i, 1i},
40 x: []complex128{1i, 1i, 1i},
41 y: []complex128{1, 2, 1},
42 ex: []complex128{-1 + 1i, 1i, -1 + 1i}},
43 {incX: 2, incY: 2, incDst: 3, ix: 0, iy: 0, idst: 0,
45 dst: []complex128{1i, 1i, 1i},
46 x: []complex128{1i, 1i, 1i},
47 y: []complex128{1, 2, 1},
48 ex: []complex128{2, 3, 2}},
49 {incX: 2, incY: 2, incDst: 3, ix: 0, iy: 0, idst: 0,
51 dst: []complex128{1i, 1i, 1i},
52 x: []complex128{1i, 1i, 1i, 1i, 1i}[1:4],
53 y: []complex128{1, 1, 2, 1, 1}[1:4],
54 ex: []complex128{2, 3, 2}},
55 {incX: 2, incY: 4, incDst: 3, ix: 0, iy: 0, idst: 0,
57 dst: []complex128{1i, 1i, 1i, 1i, 1i},
58 x: []complex128{2 + 1i, 2 + 1i, 2 + 1i, 2 + 1i, 2 + 1i},
59 y: []complex128{1, 1, 2, 1, 1},
60 ex: []complex128{-3 - 2i, -3 - 2i, -2 - 2i, -3 - 2i, -3 - 2i}},
61 // Run big test twice, once aligned once unaligned.
62 {incX: 2, incY: 2, incDst: 3, ix: 0, iy: 0, idst: 0,
64 dst: make([]complex128, 10),
65 x: []complex128{1i, 1i, 1i, 1i, 1i, 1i, 1i, 1i, 1i, 1i},
66 y: []complex128{1, 1, 2, 1, 1, 1, 1, 2, 1, 1},
67 ex: []complex128{2 + 1i, 2 + 1i, 3 + 1i, 2 + 1i, 2 + 1i, 2 + 1i, 2 + 1i, 3 + 1i, 2 + 1i, 2 + 1i}},
68 {incX: 2, incY: 2, incDst: 3, ix: 0, iy: 0, idst: 0,
70 dst: make([]complex128, 10),
71 x: []complex128{1i, 1i, 1i, 1i, 1i, 1i, 1i, 1i, 1i, 1i},
72 y: []complex128{1, 1, 2, 1, 1, 1, 1, 2, 1, 1},
73 ex: []complex128{2 + 1i, 2 + 1i, 3 + 1i, 2 + 1i, 2 + 1i, 2 + 1i, 2 + 1i, 3 + 1i, 2 + 1i, 2 + 1i}},
74 {incX: -2, incY: -2, incDst: -3, ix: 18, iy: 18, idst: 27,
76 dst: make([]complex128, 10),
77 x: []complex128{1i, 1i, 1i, 1i, 1i, 1i, 1i, 1i, 1i, 1i},
78 y: []complex128{1, 1, 2, 1, 1, 1, 1, 2, 1, 1},
79 ex: []complex128{2 + 1i, 2 + 1i, 3 + 1i, 2 + 1i, 2 + 1i, 2 + 1i, 2 + 1i, 3 + 1i, 2 + 1i, 2 + 1i}},
80 {incX: -2, incY: 2, incDst: -3, ix: 18, iy: 0, idst: 27,
82 dst: make([]complex128, 10),
83 x: []complex128{1i, 1i, 1i, 1i, 1i, 1i, 1i, 1i, 1i, 1i},
84 y: []complex128{1, 1, 2, 1, 1, 1, 1, 2, 1, 1},
85 ex: []complex128{2 + 1i, 2 + 1i, 3 + 1i, 2 + 1i, 2 + 1i, 2 + 1i, 2 + 1i, 3 + 1i, 2 + 1i, 2 + 1i}},
88 func TestAxpyUnitary(t *testing.T) {
89 const xGdVal, yGdVal = 1, 1
90 for cas, test := range tests {
91 xgLn, ygLn := 4+cas%2, 4+cas%3
92 test.x, test.y = guardVector(test.x, xGdVal, xgLn), guardVector(test.y, yGdVal, ygLn)
93 x, y := test.x[xgLn:len(test.x)-xgLn], test.y[ygLn:len(test.y)-ygLn]
94 AxpyUnitary(test.a, x, y)
95 for i := range test.ex {
96 if y[i] != test.ex[i] {
97 t.Errorf("Test %d Unexpected result at %d Got: %v Expected: %v", cas, i, y[i], test.ex[i])
100 if !isValidGuard(test.x, xGdVal, xgLn) {
101 t.Errorf("Test %d Guard violated in x vector %v %v", cas, test.x[:xgLn], test.x[len(test.x)-xgLn:])
103 if !isValidGuard(test.y, yGdVal, ygLn) {
104 t.Errorf("Test %d Guard violated in y vector %v %v", cas, test.y[:ygLn], test.y[len(test.y)-ygLn:])
109 func TestAxpyUnitaryTo(t *testing.T) {
110 const xGdVal, yGdVal, dstGdVal = 1, 1, 0
111 for cas, test := range tests {
112 xgLn, ygLn := 4+cas%2, 4+cas%3
113 test.x, test.y = guardVector(test.x, xGdVal, xgLn), guardVector(test.y, yGdVal, ygLn)
114 test.dst = guardVector(test.dst, dstGdVal, xgLn)
115 x, y := test.x[xgLn:len(test.x)-xgLn], test.y[ygLn:len(test.y)-ygLn]
116 dst := test.dst[xgLn : len(test.dst)-xgLn]
117 AxpyUnitaryTo(dst, test.a, x, y)
118 for i := range test.ex {
119 if dst[i] != test.ex[i] {
120 t.Errorf("Test %d Unexpected result at %d Got: %v Expected: %v", cas, i, dst[i], test.ex[i])
123 if !isValidGuard(test.x, xGdVal, xgLn) {
124 t.Errorf("Test %d Guard violated in x vector %v %v", cas, test.x[:xgLn], test.x[len(test.x)-xgLn:])
126 if !isValidGuard(test.y, yGdVal, ygLn) {
127 t.Errorf("Test %d Guard violated in y vector %v %v", cas, test.y[:ygLn], test.y[len(test.y)-ygLn:])
129 if !isValidGuard(test.dst, dstGdVal, xgLn) {
130 t.Errorf("Test %d Guard violated in dst vector %v %v", cas, test.dst[:xgLn], test.dst[len(test.dst)-xgLn:])
136 func TestAxpyInc(t *testing.T) {
137 const xGdVal, yGdVal = 1, 1
138 for cas, test := range tests {
139 xgLn, ygLn := 4+cas%2, 4+cas%3
140 test.x, test.y = guardIncVector(test.x, xGdVal, test.incX, xgLn), guardIncVector(test.y, yGdVal, test.incY, ygLn)
141 x, y := test.x[xgLn:len(test.x)-xgLn], test.y[ygLn:len(test.y)-ygLn]
142 AxpyInc(test.a, x, y, uintptr(len(test.ex)), uintptr(test.incX), uintptr(test.incY), test.ix, test.iy)
143 for i := range test.ex {
144 if y[int(test.iy)+i*int(test.incY)] != test.ex[i] {
145 t.Errorf("Test %d Unexpected result at %d Got: %v Expected: %v", cas, i, y[i*int(test.incY)], test.ex[i])
148 checkValidIncGuard(t, test.x, xGdVal, test.incX, xgLn)
149 checkValidIncGuard(t, test.y, yGdVal, test.incY, ygLn)
153 func TestAxpyIncTo(t *testing.T) {
154 const xGdVal, yGdVal, dstGdVal = 1, 1, 0
155 for cas, test := range tests {
156 xgLn, ygLn := 4+cas%2, 4+cas%3
157 test.x, test.y = guardIncVector(test.x, xGdVal, test.incX, xgLn), guardIncVector(test.y, yGdVal, test.incY, ygLn)
158 test.dst = guardIncVector(test.dst, dstGdVal, test.incDst, xgLn)
159 x, y := test.x[xgLn:len(test.x)-xgLn], test.y[ygLn:len(test.y)-ygLn]
160 dst := test.dst[xgLn : len(test.dst)-xgLn]
161 AxpyIncTo(dst, uintptr(test.incDst), test.idst, test.a, x, y, uintptr(len(test.ex)), uintptr(test.incX), uintptr(test.incY), test.ix, test.iy)
162 for i := range test.ex {
163 if dst[int(test.idst)+i*int(test.incDst)] != test.ex[i] {
164 t.Errorf("Test %d Unexpected result at %d Got: %v Expected: %v", cas, i, dst[i*int(test.incDst)], test.ex[i])
167 checkValidIncGuard(t, test.x, xGdVal, test.incX, xgLn)
168 checkValidIncGuard(t, test.y, yGdVal, test.incY, ygLn)
169 checkValidIncGuard(t, test.dst, dstGdVal, test.incDst, xgLn)
173 var dscalTests = []struct {
181 want: []complex128{},
185 x: []complex128{1 + 2i},
186 want: []complex128{1 + 2i},
190 x: []complex128{1 + 2i},
191 want: []complex128{2 + 4i},
195 x: []complex128{1 + 2i, 3 + 5i, 6 + 11i, 12 - 23i},
196 want: []complex128{2 + 4i, 6 + 10i, 12 + 22i, 24 - 46i},
200 x: []complex128{1 + 2i, 5 + 4i, 3 + 6i, 8 + 12i, -3 - 2i, -5 + 5i},
201 want: []complex128{3 + 6i, 15 + 12i, 9 + 18i, 24 + 36i, -9 - 6i, -15 + 15i},
205 x: []complex128{1 + 2i, 5 + 4i, 3 + 6i, 8 + 12i, -3 - 2i, -5 + 5i, 1 + 2i, 5 + 4i, 3 + 6i, 8 + 12i, -3 - 2i, -5 + 5i},
206 want: []complex128{5 + 10i, 25 + 20i, 15 + 30i, 40 + 60i, -15 - 10i, -25 + 25i, 5 + 10i, 25 + 20i, 15 + 30i, 40 + 60i, -15 - 10i, -25 + 25i},
210 func TestDscalUnitary(t *testing.T) {
212 for i, test := range dscalTests {
213 for _, align := range align1 {
214 prefix := fmt.Sprintf("Test %v (x:%v)", i, align)
216 xg := guardVector(test.x, xGdVal, xgLn)
217 x := xg[xgLn : len(xg)-xgLn]
219 DscalUnitary(test.alpha, x)
221 for i := range test.want {
222 if !same(x[i], test.want[i]) {
223 t.Errorf(msgVal, prefix, i, x[i], test.want[i])
226 if !isValidGuard(xg, xGdVal, xgLn) {
227 t.Errorf(msgGuard, prefix, "x", xg[:xgLn], xg[len(xg)-xgLn:])
233 func TestDscalInc(t *testing.T) {
236 for i, test := range dscalTests {
238 for _, incX := range []int{1, 2, 3, 4, 7, 10} {
239 prefix := fmt.Sprintf("Test %v (x:%v)", i, incX)
240 xg := guardIncVector(test.x, xGdVal, incX, gdLn)
241 x := xg[gdLn : len(xg)-gdLn]
243 DscalInc(test.alpha, x, uintptr(n), uintptr(incX))
245 for i := range test.want {
246 if !same(x[i*incX], test.want[i]) {
247 t.Errorf(msgVal, prefix, i, x[i*incX], test.want[i])
250 checkValidIncGuard(t, xg, xGdVal, incX, gdLn)
255 var scalTests = []struct {
263 want: []complex128{},
267 x: []complex128{1 + 2i},
268 want: []complex128{-1 + 3i},
272 x: []complex128{1 + 2i},
273 want: []complex128{-4 + 7i},
277 x: []complex128{1 + 2i},
278 want: []complex128{10},
282 x: []complex128{1 + 2i, 5 + 4i, 3 + 6i, 8 + 12i, -3 - 2i, -5 + 5i},
283 want: []complex128{-14 + 12i, -22 + 48i, -42 + 36i, -80 + 88i, 10 - 28i, -50 - 30i},
287 x: []complex128{1 + 2i, 5 + 4i, 3 + 6i, 8 + 12i, -3 - 2i, -5 + 5i, 1 + 2i, 5 + 4i, 3 + 6i, 8 + 12i, -3 - 2i, -5 + 5i},
288 want: []complex128{25, 65 - 30i, 75, 160 - 20i, -35 + 20i, 25 + 75i, 25, 65 - 30i, 75, 160 - 20i, -35 + 20i, 25 + 75i},
292 func TestScalUnitary(t *testing.T) {
294 for i, test := range scalTests {
295 for _, align := range align1 {
296 prefix := fmt.Sprintf("Test %v (x:%v)", i, align)
298 xg := guardVector(test.x, xGdVal, xgLn)
299 x := xg[xgLn : len(xg)-xgLn]
301 ScalUnitary(test.alpha, x)
303 for i := range test.want {
304 if !same(x[i], test.want[i]) {
305 t.Errorf(msgVal, prefix, i, x[i], test.want[i])
308 if !isValidGuard(xg, xGdVal, xgLn) {
309 t.Errorf(msgGuard, prefix, "x", xg[:xgLn], xg[len(xg)-xgLn:])
315 func TestScalInc(t *testing.T) {
318 for i, test := range scalTests {
320 for _, inc := range []int{1, 2, 3, 4, 7, 10} {
321 prefix := fmt.Sprintf("Test %v (x:%v)", i, inc)
322 xg := guardIncVector(test.x, xGdVal, inc, gdLn)
323 x := xg[gdLn : len(xg)-gdLn]
325 ScalInc(test.alpha, x, uintptr(n), uintptr(inc))
327 for i := range test.want {
328 if !same(x[i*inc], test.want[i]) {
329 t.Errorf(msgVal, prefix, i, x[i*inc], test.want[i])
332 checkValidIncGuard(t, xg, xGdVal, inc, gdLn)