github.com/gopherd/gonum@v0.0.4/blas/testblas/dtxmv.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/gopherd/gonum/blas" 11 ) 12 13 type Dtxmver interface { 14 Dtrmv(ul blas.Uplo, tA blas.Transpose, d blas.Diag, n int, a []float64, lda int, x []float64, incX int) 15 Dtbmv(ul blas.Uplo, tA blas.Transpose, d blas.Diag, n, k int, a []float64, lda int, x []float64, incX int) 16 Dtpmv(ul blas.Uplo, tA blas.Transpose, d blas.Diag, n int, a []float64, x []float64, incX int) 17 } 18 19 type vec struct { 20 data []float64 21 inc int 22 } 23 24 var cases = []struct { 25 n, k int 26 ul blas.Uplo 27 d blas.Diag 28 ldab int 29 tr, tb, tp []float64 30 ins []vec 31 solNoTrans []float64 32 solTrans []float64 33 }{ 34 { 35 n: 3, 36 k: 1, 37 ul: blas.Upper, 38 d: blas.NonUnit, 39 tr: []float64{1, 2, 0, 0, 3, 4, 0, 0, 5}, 40 tb: []float64{1, 2, 3, 4, 5, 0}, 41 ldab: 2, 42 tp: []float64{1, 2, 0, 3, 4, 5}, 43 ins: []vec{ 44 {[]float64{2, 3, 4}, 1}, 45 {[]float64{2, 1, 3, 1, 4}, 2}, 46 {[]float64{4, 1, 3, 1, 2}, -2}, 47 }, 48 solNoTrans: []float64{8, 25, 20}, 49 solTrans: []float64{2, 13, 32}, 50 }, 51 { 52 n: 3, 53 k: 1, 54 ul: blas.Upper, 55 d: blas.Unit, 56 tr: []float64{1, 2, 0, 0, 3, 4, 0, 0, 5}, 57 tb: []float64{1, 2, 3, 4, 5, 0}, 58 ldab: 2, 59 tp: []float64{1, 2, 0, 3, 4, 5}, 60 ins: []vec{ 61 {[]float64{2, 3, 4}, 1}, 62 {[]float64{2, 1, 3, 1, 4}, 2}, 63 {[]float64{4, 1, 3, 1, 2}, -2}, 64 }, 65 solNoTrans: []float64{8, 19, 4}, 66 solTrans: []float64{2, 7, 16}, 67 }, 68 { 69 n: 3, 70 k: 1, 71 ul: blas.Lower, 72 d: blas.NonUnit, 73 tr: []float64{1, 0, 0, 2, 3, 0, 0, 4, 5}, 74 tb: []float64{0, 1, 2, 3, 4, 5}, 75 ldab: 2, 76 tp: []float64{1, 2, 3, 0, 4, 5}, 77 ins: []vec{ 78 {[]float64{2, 3, 4}, 1}, 79 {[]float64{2, 1, 3, 1, 4}, 2}, 80 {[]float64{4, 1, 3, 1, 2}, -2}, 81 }, 82 solNoTrans: []float64{2, 13, 32}, 83 solTrans: []float64{8, 25, 20}, 84 }, 85 { 86 n: 3, 87 k: 1, 88 ul: blas.Lower, 89 d: blas.Unit, 90 tr: []float64{1, 0, 0, 2, 3, 0, 0, 4, 5}, 91 tb: []float64{0, 1, 2, 3, 4, 5}, 92 ldab: 2, 93 tp: []float64{1, 2, 3, 0, 4, 5}, 94 ins: []vec{ 95 {[]float64{2, 3, 4}, 1}, 96 {[]float64{2, 1, 3, 1, 4}, 2}, 97 {[]float64{4, 1, 3, 1, 2}, -2}, 98 }, 99 solNoTrans: []float64{2, 7, 16}, 100 solTrans: []float64{8, 19, 4}, 101 }, 102 } 103 104 func DtxmvTest(t *testing.T, blasser Dtxmver) { 105 106 for nc, c := range cases { 107 for nx, x := range c.ins { 108 in := make([]float64, len(x.data)) 109 copy(in, x.data) 110 blasser.Dtrmv(c.ul, blas.NoTrans, c.d, c.n, c.tr, c.n, in, x.inc) 111 if !dStridedSliceTolEqual(c.n, in, x.inc, c.solNoTrans, 1) { 112 t.Error("Wrong Dtrmv result for: NoTrans in Case:", nc, "input:", nx) 113 } 114 115 in = make([]float64, len(x.data)) 116 copy(in, x.data) 117 blasser.Dtrmv(c.ul, blas.Trans, c.d, c.n, c.tr, c.n, in, x.inc) 118 if !dStridedSliceTolEqual(c.n, in, x.inc, c.solTrans, 1) { 119 t.Error("Wrong Dtrmv result for: Trans in Case:", nc, "input:", nx) 120 } 121 in = make([]float64, len(x.data)) 122 copy(in, x.data) 123 blasser.Dtbmv(c.ul, blas.NoTrans, c.d, c.n, c.k, c.tb, c.ldab, in, x.inc) 124 if !dStridedSliceTolEqual(c.n, in, x.inc, c.solNoTrans, 1) { 125 t.Error("Wrong Dtbmv result for: NoTrans in Case:", nc, "input:", nx) 126 } 127 128 in = make([]float64, len(x.data)) 129 copy(in, x.data) 130 blasser.Dtbmv(c.ul, blas.Trans, c.d, c.n, c.k, c.tb, c.ldab, in, x.inc) 131 if !dStridedSliceTolEqual(c.n, in, x.inc, c.solTrans, 1) { 132 t.Error("Wrong Dtbmv result for: Trans in Case:", nc, "input:", nx) 133 } 134 in = make([]float64, len(x.data)) 135 copy(in, x.data) 136 blasser.Dtpmv(c.ul, blas.NoTrans, c.d, c.n, c.tp, in, x.inc) 137 if !dStridedSliceTolEqual(c.n, in, x.inc, c.solNoTrans, 1) { 138 t.Error("Wrong Dtpmv result for: NoTrans in Case:", nc, "input:", nx) 139 } 140 141 in = make([]float64, len(x.data)) 142 copy(in, x.data) 143 blasser.Dtpmv(c.ul, blas.Trans, c.d, c.n, c.tp, in, x.inc) 144 if !dStridedSliceTolEqual(c.n, in, x.inc, c.solTrans, 1) { 145 t.Error("Wrong Dtpmv result for: Trans in Case:", nc, "input:", nx) 146 } 147 } 148 } 149 }