github.com/jingcheng-WU/gonum@v0.9.1-0.20210323123734-f1a2a11a8f7b/blas/testblas/dtrsv.go (about) 1 // Copyright ©2014 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 testblas 6 7 import ( 8 "testing" 9 10 "github.com/jingcheng-WU/gonum/blas" 11 "github.com/jingcheng-WU/gonum/floats" 12 ) 13 14 type Dtrsver interface { 15 Dtrsv(ul blas.Uplo, tA blas.Transpose, d blas.Diag, n int, a []float64, lda int, x []float64, incX int) 16 } 17 18 func DtrsvTest(t *testing.T, blasser Dtrsver) { 19 for i, test := range []struct { 20 n int 21 a [][]float64 22 ul blas.Uplo 23 tA blas.Transpose 24 d blas.Diag 25 x []float64 26 ans []float64 27 }{ 28 { 29 n: 3, 30 a: [][]float64{ 31 {1, 2, 3}, 32 {0, 8, 15}, 33 {0, 0, 8}, 34 }, 35 ul: blas.Upper, 36 tA: blas.NoTrans, 37 d: blas.NonUnit, 38 x: []float64{5, 6, 7}, 39 ans: []float64{4.15625, -0.890625, 0.875}, 40 }, 41 { 42 n: 3, 43 a: [][]float64{ 44 {1, 2, 3}, 45 {0, 1, 15}, 46 {0, 0, 1}, 47 }, 48 ul: blas.Upper, 49 tA: blas.NoTrans, 50 d: blas.Unit, 51 x: []float64{5, 6, 7}, 52 ans: []float64{182, -99, 7}, 53 }, 54 { 55 n: 3, 56 a: [][]float64{ 57 {1, 0, 0}, 58 {2, 8, 0}, 59 {3, 15, 8}, 60 }, 61 ul: blas.Lower, 62 tA: blas.NoTrans, 63 d: blas.NonUnit, 64 x: []float64{5, 6, 7}, 65 ans: []float64{5, -0.5, -0.0625}, 66 }, 67 { 68 n: 3, 69 a: [][]float64{ 70 {1, 0, 0}, 71 {2, 8, 0}, 72 {3, 15, 8}, 73 }, 74 ul: blas.Lower, 75 tA: blas.NoTrans, 76 d: blas.Unit, 77 x: []float64{5, 6, 7}, 78 ans: []float64{5, -4, 52}, 79 }, 80 { 81 n: 3, 82 a: [][]float64{ 83 {1, 2, 3}, 84 {0, 8, 15}, 85 {0, 0, 8}, 86 }, 87 ul: blas.Upper, 88 tA: blas.Trans, 89 d: blas.NonUnit, 90 x: []float64{5, 6, 7}, 91 ans: []float64{5, -0.5, -0.0625}, 92 }, 93 { 94 n: 3, 95 a: [][]float64{ 96 {1, 2, 3}, 97 {0, 8, 15}, 98 {0, 0, 8}, 99 }, 100 ul: blas.Upper, 101 tA: blas.Trans, 102 d: blas.Unit, 103 x: []float64{5, 6, 7}, 104 ans: []float64{5, -4, 52}, 105 }, 106 { 107 n: 3, 108 a: [][]float64{ 109 {1, 0, 0}, 110 {2, 8, 0}, 111 {3, 15, 8}, 112 }, 113 ul: blas.Lower, 114 tA: blas.Trans, 115 d: blas.NonUnit, 116 x: []float64{5, 6, 7}, 117 ans: []float64{4.15625, -0.890625, 0.875}, 118 }, 119 { 120 n: 3, 121 a: [][]float64{ 122 {1, 0, 0}, 123 {2, 1, 0}, 124 {3, 15, 1}, 125 }, 126 ul: blas.Lower, 127 tA: blas.Trans, 128 d: blas.Unit, 129 x: []float64{5, 6, 7}, 130 ans: []float64{182, -99, 7}, 131 }, 132 } { 133 incTest := func(incX, extra int) { 134 aFlat := flatten(test.a) 135 x := makeIncremented(test.x, incX, extra) 136 blasser.Dtrsv(test.ul, test.tA, test.d, test.n, aFlat, test.n, x, incX) 137 ans := makeIncremented(test.ans, incX, extra) 138 if !floats.EqualApprox(x, ans, 1e-14) { 139 t.Errorf("Case %v, incX = %v: Want %v, got %v.", i, incX, ans, x) 140 } 141 } 142 incTest(1, 0) 143 incTest(-2, 0) 144 incTest(3, 0) 145 incTest(-3, 8) 146 incTest(4, 2) 147 } 148 }