gonum.org/v1/gonum@v0.14.0/blas/testblas/dspr2.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 Dspr2er interface { 15 Dspr2(ul blas.Uplo, n int, alpha float64, x []float64, incX int, y []float64, incY int, a []float64) 16 } 17 18 func Dspr2Test(t *testing.T, blasser Dspr2er) { 19 for i, test := range []struct { 20 n int 21 a [][]float64 22 ul blas.Uplo 23 x []float64 24 y []float64 25 alpha float64 26 ans [][]float64 27 }{ 28 { 29 n: 3, 30 a: [][]float64{ 31 {7, 2, 4}, 32 {0, 3, 5}, 33 {0, 0, 6}, 34 }, 35 x: []float64{2, 3, 4}, 36 y: []float64{5, 6, 7}, 37 alpha: 2, 38 ul: blas.Upper, 39 ans: [][]float64{ 40 {47, 56, 72}, 41 {0, 75, 95}, 42 {0, 0, 118}, 43 }, 44 }, 45 { 46 n: 3, 47 a: [][]float64{ 48 {7, 0, 0}, 49 {2, 3, 0}, 50 {4, 5, 6}, 51 }, 52 x: []float64{2, 3, 4}, 53 y: []float64{5, 6, 7}, 54 alpha: 2, 55 ul: blas.Lower, 56 ans: [][]float64{ 57 {47, 0, 0}, 58 {56, 75, 0}, 59 {72, 95, 118}, 60 }, 61 }, 62 } { 63 incTest := func(incX, incY, extra int) { 64 aFlat := flattenTriangular(test.a, test.ul) 65 x := makeIncremented(test.x, incX, extra) 66 y := makeIncremented(test.y, incY, extra) 67 blasser.Dspr2(test.ul, test.n, test.alpha, x, incX, y, incY, aFlat) 68 ansFlat := flattenTriangular(test.ans, test.ul) 69 if !floats.EqualApprox(aFlat, ansFlat, 1e-14) { 70 t.Errorf("Case %v, incX = %v, incY = %v. Want %v, got %v.", i, incX, incY, ansFlat, aFlat) 71 } 72 } 73 incTest(1, 1, 0) 74 incTest(-2, 1, 0) 75 incTest(-2, 3, 0) 76 incTest(2, -3, 0) 77 incTest(3, -2, 0) 78 incTest(-3, -4, 0) 79 } 80 }