8 type Dgerer interface {
9 Dger(m, n int, alpha float64, x []float64, incX int, y []float64, incY int, a []float64, lda int)
12 func DgerTest(t *testing.T, blasser Dgerer) {
13 for _, test := range []struct {
36 x: []float64{-2, -3, 0, 1, 2},
37 y: []float64{-1.1, 5, 0},
40 trueAns: [][]float64{{3.5, -7.6, 3.5}, {5.9, -12.2, 3.3}, {-1.3, -4.3, -9.7}, {6.9, 14, -10}, {-14.2, -4, -6}},
51 x: []float64{-2, -3, 0},
52 y: []float64{-1.1, 5, 0},
55 trueAns: [][]float64{{3.5, -7.6, 3.5}, {5.9, -12.2, 3.3}, {-1.3, -4.3, -9.7}},
63 {1.3, 2.4, 3.5, 4.8, 1.11, -9},
64 {2.6, 2.8, 3.3, -3.4, 6.2, -8.7},
65 {-1.3, -4.3, -9.7, -3.1, 8.9, 8.9},
67 x: []float64{-2, -3, 0},
68 y: []float64{-1.1, 5, 0, 9, 19, 22},
71 trueAns: [][]float64{{3.5, -7.6, 3.5, -13.2, -36.89, -53}, {5.9, -12.2, 3.3, -30.4, -50.8, -74.7}, {-1.3, -4.3, -9.7, -3.1, 8.9, 8.9}},
74 name: "M gt N inc not 1",
84 x: []float64{-2, -3, 0, 1, 2, 6, 0, 9, 7},
85 y: []float64{-1.1, 5, 0, 8, 7, -5, 7},
88 trueAns: [][]float64{{3.5, -13.6, -10.5}, {2.6, 2.8, 3.3}, {-3.5, 11.7, 4.3}, {8, 9, -10}, {-19.700000000000003, 42, 43}},
91 name: "M eq N inc not 1",
99 x: []float64{-2, -3, 0, 8, 7, -9, 7, -6, 12, 6, 6, 6, -11},
100 y: []float64{-1.1, 5, 0, 0, 9, 8, 6},
103 trueAns: [][]float64{{3.5, 2.4, -8.5}, {-5.1, 2.8, 45.3}, {-14.5, -4.3, 62.3}},
106 name: "M lt N inc not 1",
110 {1.3, 2.4, 3.5, 4.8, 1.11, -9},
111 {2.6, 2.8, 3.3, -3.4, 6.2, -8.7},
112 {-1.3, -4.3, -9.7, -3.1, 8.9, 8.9},
114 x: []float64{-2, -3, 0, 0, 8, 0, 9, -3},
115 y: []float64{-1.1, 5, 0, 9, 19, 22, 11, -8.11, -9.22, 9.87, 7},
118 trueAns: [][]float64{{3.5, 2.4, -34.5, -17.2, 19.55, -23}, {2.6, 2.8, 3.3, -3.4, 6.2, -8.7}, {-11.2, -4.3, 161.3, 95.9, -74.08, 71.9}},
121 name: "Y NaN element",
124 a: [][]float64{{1.3}},
126 y: []float64{math.NaN()},
129 trueAns: [][]float64{{math.NaN()}},
132 // TODO: Add tests where a is longer
133 // TODO: Add panic tests
134 // TODO: Add negative increment tests
136 x := sliceCopy(test.x)
137 y := sliceCopy(test.y)
139 a := sliceOfSliceCopy(test.a)
141 // Test with row major
144 blasser.Dger(test.m, test.n, alpha, x, test.incX, y, test.incY, aFlat, test.n)
145 ans := unflatten(aFlat, test.m, test.n)
146 dgercomp(t, x, test.x, y, test.y, ans, test.trueAns, test.name+" row maj")
148 // Test with different alpha
151 blasser.Dger(test.m, test.n, alpha, x, test.incX, y, test.incY, aFlat, test.n)
152 ans = unflatten(aFlat, test.m, test.n)
153 trueCopy := sliceOfSliceCopy(test.trueAns)
154 for i := range trueCopy {
155 for j := range trueCopy[i] {
156 trueCopy[i][j] = alpha*(trueCopy[i][j]-a[i][j]) + a[i][j]
159 dgercomp(t, x, test.x, y, test.y, ans, trueCopy, test.name+" row maj alpha")
163 func dgercomp(t *testing.T, x, xCopy, y, yCopy []float64, ans [][]float64, trueAns [][]float64, name string) {
164 if !dSliceEqual(x, xCopy) {
165 t.Errorf("case %v: x modified during call to dger\n%v\n%v", name, x, xCopy)
167 if !dSliceEqual(y, yCopy) {
168 t.Errorf("case %v: y modified during call to dger\n%v\n%v", name, y, yCopy)
172 if !dSliceTolEqual(ans[i], trueAns[i]) {
173 t.Errorf("case %v: answer mismatch at %v. Expected %v, Found %v", name, i, trueAns, ans)