OSDN Git Service

new repo
[bytom/vapor.git] / vendor / gonum.org / v1 / gonum / internal / asm / f32 / stubs_test.go
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.
4
5 package f32
6
7 import "testing"
8
9 var tests = []struct {
10         incX, incY, incDst uintptr
11         ix, iy, idst       uintptr
12         a                  float32
13         dst, x, y          []float32
14         ex                 []float32
15 }{
16         {incX: 2, incY: 2, incDst: 3, ix: 0, iy: 0, idst: 0,
17                 a:   3,
18                 dst: []float32{5},
19                 x:   []float32{2},
20                 y:   []float32{1},
21                 ex:  []float32{7}},
22         {incX: 2, incY: 2, incDst: 3, ix: 0, iy: 0, idst: 0,
23                 a:   5,
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,
29                 a:   5,
30                 dst: []float32{0, 0, 0},
31                 x:   []float32{0, 0},
32                 y:   []float32{1, 1, 1},
33                 ex:  []float32{1, 1}},
34         {incX: 2, incY: 2, incDst: 3, ix: 0, iy: 0, idst: 0,
35                 a:   -1,
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,
41                 a:   -1,
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,
47                 a:   2.5,
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.
53                 a:   16.5,
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,
59                 a:   16.5,
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}},
64 }
65
66 func TestAxpyUnitary(t *testing.T) {
67         for j, v := range tests {
68                 gdLn := 4 + j%2
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)
72                 for i := range v.ex {
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])
75                         }
76                 }
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:])
79                 }
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:])
82                 }
83         }
84 }
85
86 func TestAxpyUnitaryTo(t *testing.T) {
87         for j, v := range tests {
88                 gdLn := 4 + j%2
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)
94                 for i := range v.ex {
95                         if !same(v.ex[i], dst[i]) {
96                                 t.Error("Test", j, "Unexpected result at", i, "Got:", dst[i], "Expected:", v.ex[i])
97                         }
98                 }
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:])
101                 }
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:])
104                 }
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:])
107                 }
108         }
109 }
110
111 func TestAxpyInc(t *testing.T) {
112         for j, v := range tests {
113                 gdLn := 4 + j%2
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)
122                         }
123                 }
124                 checkValidIncGuard(t, v.x, 1, int(v.incX), gdLn)
125                 checkValidIncGuard(t, v.y, 1, int(v.incY), gdLn)
126         }
127 }
128
129 func TestAxpyIncTo(t *testing.T) {
130         for j, v := range tests {
131                 gdLn := 4 + j%2
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])
140                                 t.Error(v.dst)
141                                 t.Error(v.ex)
142                         }
143                 }
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)
147         }
148 }