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.
10 "gonum.org/v1/gonum/blas"
13 var zherTestCases = []struct {
19 wantRev []complex128 // Result when incX is negative.
32 -2 + 3i, -3 - 11i, 0 + 4i,
33 -3 + 11i, -6 + 3i, 7 + 2i,
34 0 - 4i, 7 - 2i, 18 + 3i,
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,
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,
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,
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,
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,
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,
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,
102 type Zherer interface {
103 Zher(uplo blas.Uplo, n int, alpha float64, x []complex128, incX int, a []complex128, lda int)
106 func ZherTest(t *testing.T, impl Zherer) {
107 for tc, test := range zherTestCases {
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))
116 a := makeZGeneral(test.a, n, n, lda)
118 var want []complex128
120 want = makeZGeneral(test.want, n, n, lda)
122 want = makeZGeneral(test.wantRev, n, n, lda)
125 if uplo == blas.Upper {
126 for i := 0; i < n; i++ {
127 for j := 0; j < i; j++ {
133 for i := 0; i < n; i++ {
134 for j := i + 1; j < n; j++ {
141 impl.Zher(uplo, n, test.alpha, x, incX, a, lda)
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)
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)