gonum.org/v1/gonum@v0.14.0/blas/testblas/dspr.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 ) 12 13 type Dsprer interface { 14 Dspr(ul blas.Uplo, n int, alpha float64, x []float64, incX int, a []float64) 15 } 16 17 func DsprTest(t *testing.T, blasser Dsprer) { 18 for i, test := range []struct { 19 ul blas.Uplo 20 n int 21 a [][]float64 22 x []float64 23 alpha float64 24 ans [][]float64 25 }{ 26 { 27 ul: blas.Upper, 28 n: 4, 29 a: [][]float64{ 30 {10, 2, 0, 1}, 31 {0, 1, 2, 3}, 32 {0, 0, 9, 15}, 33 {0, 0, 0, -6}, 34 }, 35 x: []float64{1, 2, 0, 5}, 36 alpha: 8, 37 ans: [][]float64{ 38 {18, 18, 0, 41}, 39 {0, 33, 2, 83}, 40 {0, 0, 9, 15}, 41 {0, 0, 0, 194}, 42 }, 43 }, 44 { 45 ul: blas.Lower, 46 n: 3, 47 a: [][]float64{ 48 {10, 2, 0}, 49 {4, 1, 2}, 50 {2, 7, 9}, 51 }, 52 x: []float64{3, 0, 5}, 53 alpha: 8, 54 ans: [][]float64{ 55 {82, 2, 0}, 56 {4, 1, 2}, 57 {122, 7, 209}, 58 }, 59 }, 60 } { 61 incTest := func(incX, extra int) { 62 xnew := makeIncremented(test.x, incX, extra) 63 aFlat := flattenTriangular(test.a, test.ul) 64 ans := flattenTriangular(test.ans, test.ul) 65 blasser.Dspr(test.ul, test.n, test.alpha, xnew, incX, aFlat) 66 if !dSliceTolEqual(aFlat, ans) { 67 t.Errorf("Case %v, idx %v: Want %v, got %v.", i, incX, ans, aFlat) 68 } 69 } 70 incTest(1, 3) 71 incTest(1, 0) 72 incTest(3, 2) 73 incTest(-2, 2) 74 } 75 }