6 "gonum.org/v1/gonum/blas"
9 type Dtbsver interface {
10 Dtbsv(ul blas.Uplo, tA blas.Transpose, d blas.Diag, n, k int, a []float64, lda int, x []float64, incX int)
11 Dtrsv(ul blas.Uplo, tA blas.Transpose, d blas.Diag, n int, a []float64, lda int, x []float64, incX int)
14 func DtbsvTest(t *testing.T, blasser Dtbsver) {
15 for i, test := range []struct {
38 x: []float64{1, 2, 3, 4, 5},
40 ans: []float64{2.479166666666667, -0.493055555555556, 0.708333333333333, 1.583333333333333, -5.000000000000000},
55 x: []float64{1, 2, 3, 4, 5},
57 ans: []float64{-15.854166666666664, -16.395833333333336, 13.208333333333334, 1.583333333333333, -5.000000000000000},
72 x: []float64{1, -101, 2, -201, 3, -301, 4, -401, 5, -501, -601, -701},
74 ans: []float64{2.479166666666667, -101, -0.493055555555556, -201, 0.708333333333333, -301, 1.583333333333333, -401, -5.000000000000000, -501, -601, -701},
89 x: []float64{1, -101, 2, -201, 3, -301, 4, -401, 5, -501, -601, -701},
91 ans: []float64{-15.854166666666664, -101, -16.395833333333336, -201, 13.208333333333334, -301, 1.583333333333333, -401, -5.000000000000000, -501, -601, -701},
106 x: []float64{1, 2, 3, 4, 5},
108 ans: []float64{1, -0.166666666666667, -0.416666666666667, 0.437500000000000, -5.770833333333334},
123 x: []float64{1, -101, 2, -201, 3, -301, 4, -401, 5, -501, -601, -701},
125 ans: []float64{1, -101, -0.166666666666667, -201, -0.416666666666667, -301, 0.437500000000000, -401, -5.770833333333334, -501, -601, -701},
140 x: []float64{1, 2, 3, 4, 5},
142 ans: []float64{1, -0.166666666666667, -0.416666666666667, 0.437500000000000, -5.770833333333334},
157 x: []float64{1, -101, 2, -201, 3, -301, 4, -401, 5, -501, -601, -701},
159 ans: []float64{1, -101, -0.166666666666667, -201, -0.416666666666667, -301, 0.437500000000000, -401, -5.770833333333334, -501, -601, -701},
174 x: []float64{1, 2, 3, 4, 5},
176 ans: []float64{-15.854166666666664, -16.395833333333336, 13.208333333333334, 1.583333333333333, -5.000000000000000},
191 x: []float64{1, -101, 2, -201, 3, -301, 4, -401, 5, -501, -601, -701},
193 ans: []float64{-15.854166666666664, -101, -16.395833333333336, -201, 13.208333333333334, -301, 1.583333333333333, -401, -5.000000000000000, -501, -601, -701},
197 if test.ul == blas.Upper {
198 aFlat = flattenBanded(test.a, test.k, 0)
200 aFlat = flattenBanded(test.a, 0, test.k)
202 xCopy := sliceCopy(test.x)
203 // TODO: Have tests where the banded matrix is constructed explicitly
204 // to allow testing for lda =! k+1
205 blasser.Dtbsv(test.ul, test.tA, test.d, test.n, test.k, aFlat, test.k+1, xCopy, test.incX)
206 if !dSliceTolEqual(test.ans, xCopy) {
207 t.Errorf("Case %v: Want %v, got %v", i, test.ans, xCopy)
212 // TODO: Uncomment when Dtrsv is fixed
213 // Compare with dense for larger matrices
214 for _, ul := range [...]blas.Uplo{blas.Upper, blas.Lower} {
215 for _, tA := range [...]blas.Transpose{blas.NoTrans, blas.Trans} {
216 for _, n := range [...]int{7, 8, 11} {
217 for _, d := range [...]blas.Diag{blas.NonUnit, blas.Unit} {
218 for _, k := range [...]int{0, 1, 3} {
219 for _, incX := range [...]int{1, 3} {
220 a := make([][]float64, n)
222 a[i] = make([]float64, n)
223 for j := range a[i] {
224 a[i][j] = rand.Float64()
227 x := make([]float64, n)
229 x[i] = rand.Float64()
232 xinc := makeIncremented(x, incX, extra)
233 bandX := sliceCopy(xinc)
234 var aFlatBand []float64
235 if ul == blas.Upper {
236 aFlatBand = flattenBanded(a, k, 0)
238 aFlatBand = flattenBanded(a, 0, k)
240 blasser.Dtbsv(ul, tA, d, n, k, aFlatBand, k+1, bandX, incX)
242 aFlatDense := flatten(a)
243 denseX := sliceCopy(xinc)
244 blasser.Dtrsv(ul, tA, d, n, aFlatDense, n, denseX, incX)
245 if !dSliceTolEqual(denseX, bandX) {
246 t.Errorf("Case %v: dense banded mismatch")