github.com/jingcheng-WU/gonum@v0.9.1-0.20210323123734-f1a2a11a8f7b/blas/testblas/zher.go (about) 1 // Copyright ©2017 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 ) 12 13 var zherTestCases = []struct { 14 alpha float64 15 x []complex128 16 a []complex128 17 18 want []complex128 19 wantRev []complex128 // Result when incX is negative. 20 }{ 21 { 22 alpha: 1, 23 }, 24 { 25 alpha: 3, 26 x: []complex128{ 27 0 - 3i, 28 6 + 10i, 29 -2 - 7i, 30 }, 31 a: []complex128{ 32 -2 + 3i, -3 - 11i, 0 + 4i, 33 -3 + 11i, -6 + 3i, 7 + 2i, 34 0 - 4i, 7 - 2i, 18 + 3i, 35 }, 36 want: []complex128{ 37 25 + 0i, -93 - 65i, 63 + 22i, 38 -93 + 65i, 402 + 0i, -239 + 68i, 39 63 - 22i, -239 - 68i, 177 + 0i}, 40 wantRev: []complex128{ 41 157 + 0i, -249 - 77i, 63 - 14i, 42 -249 + 77i, 402 + 0i, -83 + 56i, 43 63 + 14i, -83 - 56i, 45 + 0i, 44 }, 45 }, 46 { 47 alpha: 3, 48 x: []complex128{ 49 -6 + 2i, 50 -2 - 4i, 51 0 + 0i, 52 0 + 7i, 53 }, 54 a: []complex128{ 55 2 + 3i, -9 + 7i, 3 + 11i, 10 - 1i, 56 -9 - 7i, 16 + 3i, -5 + 2i, -7 - 5i, 57 3 - 11i, -5 - 2i, 14 + 3i, 2 - 1i, 58 10 + 1i, -7 + 5i, 2 + 1i, 18 + 3i, 59 }, 60 want: []complex128{ 61 122 + 0i, 3 - 77i, 3 + 11i, 52 + 125i, 62 3 + 77i, 76 + 0i, -5 + 2i, -91 + 37i, 63 3 - 11i, -5 - 2i, 14 + 0i, 2 - 1i, 64 52 - 125i, -91 - 37i, 2 + 1i, 165 + 0i, 65 }, 66 wantRev: []complex128{ 67 149 + 0i, -9 + 7i, -81 - 31i, 52 - 127i, 68 -9 - 7i, 16 + 0i, -5 + 2i, -7 - 5i, 69 -81 + 31i, -5 - 2i, 74 + 0i, 14 + 83i, 70 52 + 127i, -7 + 5i, 14 - 83i, 138 + 0i, 71 }, 72 }, 73 { 74 alpha: 0, 75 x: []complex128{ 76 -6 + 2i, 77 -2 - 4i, 78 0 + 0i, 79 0 + 7i, 80 }, 81 a: []complex128{ 82 2 + 0i, -9 + 7i, 3 + 11i, 10 - 1i, 83 -9 - 7i, 16 + 0i, -5 + 2i, -7 - 5i, 84 3 - 11i, -5 - 2i, 14 + 0i, 2 - 1i, 85 10 + 1i, -7 + 5i, 2 + 1i, 18 + 0i, 86 }, 87 want: []complex128{ 88 2 + 0i, -9 + 7i, 3 + 11i, 10 - 1i, 89 -9 - 7i, 16 + 0i, -5 + 2i, -7 - 5i, 90 3 - 11i, -5 - 2i, 14 + 0i, 2 - 1i, 91 10 + 1i, -7 + 5i, 2 + 1i, 18 + 0i, 92 }, 93 wantRev: []complex128{ 94 2 + 0i, -9 + 7i, 3 + 11i, 10 - 1i, 95 -9 - 7i, 16 + 0i, -5 + 2i, -7 - 5i, 96 3 - 11i, -5 - 2i, 14 + 0i, 2 - 1i, 97 10 + 1i, -7 + 5i, 2 + 1i, 18 + 0i, 98 }, 99 }, 100 } 101 102 type Zherer interface { 103 Zher(uplo blas.Uplo, n int, alpha float64, x []complex128, incX int, a []complex128, lda int) 104 } 105 106 func ZherTest(t *testing.T, impl Zherer) { 107 for tc, test := range zherTestCases { 108 n := len(test.x) 109 for _, uplo := range []blas.Uplo{blas.Lower, blas.Upper} { 110 for _, incX := range []int{-11, -2, -1, 1, 2, 7} { 111 for _, lda := range []int{max(1, n), n + 11} { 112 x := makeZVector(test.x, incX) 113 xCopy := make([]complex128, len(x)) 114 copy(xCopy, x) 115 116 a := makeZGeneral(test.a, n, n, lda) 117 118 var want []complex128 119 if incX > 0 { 120 want = makeZGeneral(test.want, n, n, lda) 121 } else { 122 want = makeZGeneral(test.wantRev, n, n, lda) 123 } 124 125 if uplo == blas.Upper { 126 for i := 0; i < n; i++ { 127 for j := 0; j < i; j++ { 128 a[i*lda+j] = znan 129 want[i*lda+j] = znan 130 } 131 } 132 } else { 133 for i := 0; i < n; i++ { 134 for j := i + 1; j < n; j++ { 135 a[i*lda+j] = znan 136 want[i*lda+j] = znan 137 } 138 } 139 } 140 141 impl.Zher(uplo, n, test.alpha, x, incX, a, lda) 142 143 if !zsame(x, xCopy) { 144 t.Errorf("Case %v (uplo=%v,incX=%v,lda=%v,alpha=%v): unexpected modification of x", tc, uplo, incX, test.alpha, lda) 145 } 146 if !zsame(want, a) { 147 t.Errorf("Case %v (uplo=%v,incX=%v,lda=%v,alpha=%v): unexpected result\nwant: %v\ngot: %v", tc, uplo, incX, lda, test.alpha, want, a) 148 } 149 } 150 } 151 } 152 } 153 }