gonum.org/v1/gonum@v0.14.0/blas/testblas/dtpmv.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 "gonum.org/v1/gonum/blas" 11 "gonum.org/v1/gonum/floats" 12 ) 13 14 type Dtpmver interface { 15 Dtpmv(ul blas.Uplo, tA blas.Transpose, d blas.Diag, n int, ap []float64, x []float64, incX int) 16 } 17 18 func DtpmvTest(t *testing.T, blasser Dtpmver) { 19 for i, test := range []struct { 20 n int 21 a [][]float64 22 x []float64 23 d blas.Diag 24 ul blas.Uplo 25 tA blas.Transpose 26 ans []float64 27 }{ 28 { 29 n: 3, 30 a: [][]float64{ 31 {5, 6, 7}, 32 {0, 9, 10}, 33 {0, 0, 13}, 34 }, 35 x: []float64{3, 4, 5}, 36 d: blas.NonUnit, 37 ul: blas.Upper, 38 tA: blas.NoTrans, 39 ans: []float64{74, 86, 65}, 40 }, 41 { 42 n: 3, 43 a: [][]float64{ 44 {5, 6, 7}, 45 {0, 9, 10}, 46 {0, 0, 13}, 47 }, 48 x: []float64{3, 4, 5}, 49 d: blas.Unit, 50 ul: blas.Upper, 51 tA: blas.NoTrans, 52 ans: []float64{62, 54, 5}, 53 }, 54 { 55 n: 3, 56 a: [][]float64{ 57 {5, 0, 0}, 58 {6, 9, 0}, 59 {7, 10, 13}, 60 }, 61 x: []float64{3, 4, 5}, 62 d: blas.NonUnit, 63 ul: blas.Lower, 64 tA: blas.NoTrans, 65 ans: []float64{15, 54, 126}, 66 }, 67 { 68 n: 3, 69 a: [][]float64{ 70 {1, 0, 0}, 71 {6, 1, 0}, 72 {7, 10, 1}, 73 }, 74 x: []float64{3, 4, 5}, 75 d: blas.Unit, 76 ul: blas.Lower, 77 tA: blas.NoTrans, 78 ans: []float64{3, 22, 66}, 79 }, 80 { 81 n: 3, 82 a: [][]float64{ 83 {5, 6, 7}, 84 {0, 9, 10}, 85 {0, 0, 13}, 86 }, 87 x: []float64{3, 4, 5}, 88 d: blas.NonUnit, 89 ul: blas.Upper, 90 tA: blas.Trans, 91 ans: []float64{15, 54, 126}, 92 }, 93 { 94 n: 3, 95 a: [][]float64{ 96 {1, 6, 7}, 97 {0, 1, 10}, 98 {0, 0, 1}, 99 }, 100 x: []float64{3, 4, 5}, 101 d: blas.Unit, 102 ul: blas.Upper, 103 tA: blas.Trans, 104 ans: []float64{3, 22, 66}, 105 }, 106 { 107 n: 3, 108 a: [][]float64{ 109 {5, 0, 0}, 110 {6, 9, 0}, 111 {7, 10, 13}, 112 }, 113 x: []float64{3, 4, 5}, 114 d: blas.NonUnit, 115 ul: blas.Lower, 116 tA: blas.Trans, 117 ans: []float64{74, 86, 65}, 118 }, 119 } { 120 incTest := func(incX, extra int) { 121 aFlat := flattenTriangular(test.a, test.ul) 122 x := makeIncremented(test.x, incX, extra) 123 blasser.Dtpmv(test.ul, test.tA, test.d, test.n, aFlat, x, incX) 124 ans := makeIncremented(test.ans, incX, extra) 125 if !floats.EqualApprox(x, ans, 1e-14) { 126 t.Errorf("Case %v, idx %v: Want %v, got %v.", i, incX, ans, x) 127 } 128 } 129 incTest(1, 0) 130 incTest(-3, 3) 131 incTest(4, 3) 132 } 133 }