forked from openshift/origin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
dtbmv.go
123 lines (119 loc) · 2.33 KB
/
dtbmv.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
package testblas
import (
"testing"
"github.com/gonum/blas"
)
type Dtbmver interface {
Dtbmv(ul blas.Uplo, tA blas.Transpose, d blas.Diag, n, k int, a []float64, lda int, x []float64, incX int)
}
func DtbmvTest(t *testing.T, blasser Dtbmver) {
for i, test := range []struct {
ul blas.Uplo
tA blas.Transpose
d blas.Diag
n int
k int
a [][]float64
x []float64
ans []float64
}{
{
ul: blas.Upper,
tA: blas.NoTrans,
d: blas.Unit,
n: 3,
k: 1,
a: [][]float64{
{1, 2, 0},
{0, 1, 4},
{0, 0, 1},
},
x: []float64{2, 3, 4},
ans: []float64{8, 19, 4},
},
{
ul: blas.Upper,
tA: blas.NoTrans,
d: blas.NonUnit,
n: 5,
k: 1,
a: [][]float64{
{1, 3, 0, 0, 0},
{0, 6, 7, 0, 0},
{0, 0, 2, 1, 0},
{0, 0, 0, 12, 3},
{0, 0, 0, 0, -1},
},
x: []float64{1, 2, 3, 4, 5},
ans: []float64{7, 33, 10, 63, -5},
},
{
ul: blas.Lower,
tA: blas.NoTrans,
d: blas.NonUnit,
n: 5,
k: 1,
a: [][]float64{
{7, 0, 0, 0, 0},
{3, 6, 0, 0, 0},
{0, 7, 2, 0, 0},
{0, 0, 1, 12, 0},
{0, 0, 0, 3, -1},
},
x: []float64{1, 2, 3, 4, 5},
ans: []float64{7, 15, 20, 51, 7},
},
{
ul: blas.Upper,
tA: blas.Trans,
d: blas.NonUnit,
n: 5,
k: 2,
a: [][]float64{
{7, 3, 9, 0, 0},
{0, 6, 7, 10, 0},
{0, 0, 2, 1, 11},
{0, 0, 0, 12, 3},
{0, 0, 0, 0, -1},
},
x: []float64{1, 2, 3, 4, 5},
ans: []float64{7, 15, 29, 71, 40},
},
{
ul: blas.Lower,
tA: blas.Trans,
d: blas.NonUnit,
n: 5,
k: 2,
a: [][]float64{
{7, 0, 0, 0, 0},
{3, 6, 0, 0, 0},
{9, 7, 2, 0, 0},
{0, 10, 1, 12, 0},
{0, 0, 11, 3, -1},
},
x: []float64{1, 2, 3, 4, 5},
ans: []float64{40, 73, 65, 63, -5},
},
} {
extra := 0
var aFlat []float64
if test.ul == blas.Upper {
aFlat = flattenBanded(test.a, test.k, 0)
} else {
aFlat = flattenBanded(test.a, 0, test.k)
}
incTest := func(incX, extra int) {
xnew := makeIncremented(test.x, incX, extra)
ans := makeIncremented(test.ans, incX, extra)
lda := test.k + 1
blasser.Dtbmv(test.ul, test.tA, test.d, test.n, test.k, aFlat, lda, xnew, incX)
if !dSliceTolEqual(ans, xnew) {
t.Errorf("Case %v, Inc %v: Want %v, got %v", i, incX, ans, xnew)
}
}
incTest(1, extra)
incTest(3, extra)
incTest(-2, extra)
}
}