1 // Copyright ©2015 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.
10 incX, incY, incDst uintptr
16 {incX: 2, incY: 2, incDst: 3, ix: 0, iy: 0, idst: 0,
22 {incX: 2, incY: 2, incDst: 3, ix: 0, iy: 0, idst: 0,
24 dst: []float32{0, 0, 0},
25 x: []float32{0, 0, 0},
26 y: []float32{1, 1, 1},
27 ex: []float32{1, 1, 1}},
28 {incX: 2, incY: 2, incDst: 3, ix: 0, iy: 0, idst: 0,
30 dst: []float32{0, 0, 0},
32 y: []float32{1, 1, 1},
34 {incX: 2, incY: 2, incDst: 3, ix: 0, iy: 0, idst: 0,
36 dst: []float32{-1, -1, -1},
37 x: []float32{1, 1, 1},
38 y: []float32{1, 2, 1},
39 ex: []float32{0, 1, 0}},
40 {incX: 2, incY: 2, incDst: 3, ix: 0, iy: 0, idst: 0,
42 dst: []float32{1, 1, 1},
43 x: []float32{1, 2, 1},
44 y: []float32{-1, -2, -1},
45 ex: []float32{-2, -4, -2}},
46 {incX: 2, incY: 2, incDst: 3, ix: 0, iy: 0, idst: 0,
48 dst: []float32{1, 1, 1, 1, 1},
49 x: []float32{1, 2, 3, 2, 1},
50 y: []float32{0, 0, 0, 0, 0},
51 ex: []float32{2.5, 5, 7.5, 5, 2.5}},
52 {incX: 2, incY: 2, incDst: 3, ix: 0, iy: 0, idst: 0, // Run big test twice, once aligned once unaligned.
54 dst: make([]float32, 20),
55 x: []float32{.5, .5, .5, .5, .5, .5, .5, .5, .5, .5, .5, .5, .5, .5, .5, .5, .5, .5, .5, .5},
56 y: []float32{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10},
57 ex: []float32{9.25, 10.25, 11.25, 12.25, 13.25, 14.25, 15.25, 16.25, 17.25, 18.25, 9.25, 10.25, 11.25, 12.25, 13.25, 14.25, 15.25, 16.25, 17.25, 18.25}},
58 {incX: 2, incY: 2, incDst: 3, ix: 0, iy: 0, idst: 0,
60 dst: make([]float32, 10),
61 x: []float32{.5, .5, .5, .5, .5, .5, .5, .5, .5, .5},
62 y: []float32{1, 2, 3, 4, 5, 6, 7, 8, 9, 10},
63 ex: []float32{9.25, 10.25, 11.25, 12.25, 13.25, 14.25, 15.25, 16.25, 17.25, 18.25}},
66 func TestAxpyUnitary(t *testing.T) {
67 for j, v := range tests {
69 v.x, v.y = guardVector(v.x, 1, gdLn), guardVector(v.y, 1, gdLn)
70 x, y := v.x[gdLn:len(v.x)-gdLn], v.y[gdLn:len(v.y)-gdLn]
71 AxpyUnitary(v.a, x, y)
73 if !same(y[i], v.ex[i]) {
74 t.Error("Test", j, "Unexpected result at", i, "Got:", int(y[i]), "Expected:", v.ex[i])
77 if !isValidGuard(v.x, 1, gdLn) {
78 t.Error("Test", j, "Guard violated in x vector", v.x[:gdLn], v.x[len(v.x)-gdLn:])
80 if !isValidGuard(v.y, 1, gdLn) {
81 t.Error("Test", j, "Guard violated in y vector", v.y[:gdLn], v.y[len(v.x)-gdLn:])
86 func TestAxpyUnitaryTo(t *testing.T) {
87 for j, v := range tests {
89 v.x, v.y = guardVector(v.x, 1, gdLn), guardVector(v.y, 1, gdLn)
90 v.dst = guardVector(v.dst, 0, gdLn)
91 x, y := v.x[gdLn:len(v.x)-gdLn], v.y[gdLn:len(v.y)-gdLn]
92 dst := v.dst[gdLn : len(v.dst)-gdLn]
93 AxpyUnitaryTo(dst, v.a, x, y)
95 if !same(v.ex[i], dst[i]) {
96 t.Error("Test", j, "Unexpected result at", i, "Got:", dst[i], "Expected:", v.ex[i])
99 if !isValidGuard(v.x, 1, gdLn) {
100 t.Error("Test", j, "Guard violated in x vector", v.x[:gdLn], v.x[len(v.x)-gdLn:])
102 if !isValidGuard(v.y, 1, gdLn) {
103 t.Error("Test", j, "Guard violated in y vector", v.y[:gdLn], v.y[len(v.x)-gdLn:])
105 if !isValidGuard(v.dst, 0, gdLn) {
106 t.Error("Test", j, "Guard violated in x vector", v.x[:gdLn], v.x[len(v.x)-gdLn:])
111 func TestAxpyInc(t *testing.T) {
112 for j, v := range tests {
114 v.x, v.y = guardIncVector(v.x, 1, int(v.incX), gdLn), guardIncVector(v.y, 1, int(v.incY), gdLn)
115 x, y := v.x[gdLn:len(v.x)-gdLn], v.y[gdLn:len(v.y)-gdLn]
116 AxpyInc(v.a, x, y, uintptr(len(v.ex)), v.incX, v.incY, v.ix, v.iy)
117 for i := range v.ex {
118 if !same(y[i*int(v.incY)], v.ex[i]) {
119 t.Error("Test", j, "Unexpected result at", i, "Got:", y[i*int(v.incY)], "Expected:", v.ex[i])
120 t.Error("Result:", y)
121 t.Error("Expect:", v.ex)
124 checkValidIncGuard(t, v.x, 1, int(v.incX), gdLn)
125 checkValidIncGuard(t, v.y, 1, int(v.incY), gdLn)
129 func TestAxpyIncTo(t *testing.T) {
130 for j, v := range tests {
132 v.x, v.y = guardIncVector(v.x, 1, int(v.incX), gdLn), guardIncVector(v.y, 1, int(v.incY), gdLn)
133 v.dst = guardIncVector(v.dst, 0, int(v.incDst), gdLn)
134 x, y := v.x[gdLn:len(v.x)-gdLn], v.y[gdLn:len(v.y)-gdLn]
135 dst := v.dst[gdLn : len(v.dst)-gdLn]
136 AxpyIncTo(dst, v.incDst, v.idst, v.a, x, y, uintptr(len(v.ex)), v.incX, v.incY, v.ix, v.iy)
137 for i := range v.ex {
138 if !same(dst[i*int(v.incDst)], v.ex[i]) {
139 t.Error("Test", j, "Unexpected result at", i, "Got:", dst[i*int(v.incDst)], "Expected:", v.ex[i])
144 checkValidIncGuard(t, v.x, 1, int(v.incX), gdLn)
145 checkValidIncGuard(t, v.y, 1, int(v.incY), gdLn)
146 checkValidIncGuard(t, v.dst, 0, int(v.incDst), gdLn)