github.com/jingcheng-WU/gonum@v0.9.1-0.20210323123734-f1a2a11a8f7b/blas/testblas/zdotc.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 "fmt" 9 "testing" 10 ) 11 12 type Zdotcer interface { 13 Zdotc(n int, x []complex128, incX int, y []complex128, incY int) complex128 14 } 15 16 func ZdotcTest(t *testing.T, impl Zdotcer) { 17 for tc, test := range []struct { 18 x, y []complex128 19 20 want complex128 // Result when both increments have the same sign. 21 wantRev complex128 // Result when the increments have opposite sign. 22 }{ 23 { 24 x: nil, 25 y: nil, 26 want: 0, 27 wantRev: 0, 28 }, 29 { 30 x: []complex128{1 + 2i}, 31 y: []complex128{30 + 31i}, 32 want: 92 - 29i, 33 wantRev: 92 - 29i, 34 }, 35 { 36 x: []complex128{1 + 2i, 3 + 4i}, 37 y: []complex128{30 + 31i, 33 + 34i}, 38 want: 327 - 59i, 39 wantRev: 315 - 59i, 40 }, 41 { 42 x: []complex128{1 + 2i, 3 + 4i, 5 + 6i}, 43 y: []complex128{30 + 31i, 33 + 34i, 36 + 37i}, 44 want: 729 - 90i, 45 wantRev: 681 - 90i, 46 }, 47 { 48 x: []complex128{1 + 2i, 3 + 4i, 5 + 6i, 7 + 8i}, 49 y: []complex128{30 + 31i, 33 + 34i, 36 + 37i, 39 + 40i}, 50 want: 1322 - 122i, 51 wantRev: 1202 - 122i, 52 }, 53 { 54 x: []complex128{1 + 2i, 3 + 4i, 5 + 6i, 7 + 8i, 9 + 10i}, 55 y: []complex128{30 + 31i, 33 + 34i, 36 + 37i, 39 + 40i, 42 + 43i}, 56 want: 2130 - 155i, 57 wantRev: 1890 - 155i, 58 }, 59 { 60 x: []complex128{1 + 2i, 3 + 4i, 5 + 6i, 7 + 8i, 9 + 10i, 11 + 12i}, 61 y: []complex128{30 + 31i, 33 + 34i, 36 + 37i, 39 + 40i, 42 + 43i, 45 + 46i}, 62 want: 3177 - 189i, 63 wantRev: 2757 - 189i, 64 }, 65 { 66 x: []complex128{1 + 2i, 3 + 4i, 5 + 6i, 7 + 8i, 9 + 10i, 11 + 12i, 13 + 14i}, 67 y: []complex128{30 + 31i, 33 + 34i, 36 + 37i, 39 + 40i, 42 + 43i, 45 + 46i, 48 + 49i}, 68 want: 4487 - 224i, 69 wantRev: 3815 - 224i, 70 }, 71 { 72 x: []complex128{1 + 2i, 3 + 4i, 5 + 6i, 7 + 8i, 9 + 10i, 11 + 12i, 13 + 14i, 15 + 16i}, 73 y: []complex128{30 + 31i, 33 + 34i, 36 + 37i, 39 + 40i, 42 + 43i, 45 + 46i, 48 + 49i, 51 + 52i}, 74 want: 6084 - 260i, 75 wantRev: 5076 - 260i, 76 }, 77 { 78 x: []complex128{1 + 2i, 3 + 4i, 5 + 6i, 7 + 8i, 9 + 10i, 11 + 12i, 13 + 14i, 15 + 16i, 17 + 18i}, 79 y: []complex128{30 + 31i, 33 + 34i, 36 + 37i, 39 + 40i, 42 + 43i, 45 + 46i, 48 + 49i, 51 + 52i, 54 + 55i}, 80 want: 7992 - 297i, 81 wantRev: 6552 - 297i, 82 }, 83 { 84 x: []complex128{1 + 2i, 3 + 4i, 5 + 6i, 7 + 8i, 9 + 10i, 11 + 12i, 13 + 14i, 15 + 16i, 17 + 18i, 19 + 20i}, 85 y: []complex128{30 + 31i, 33 + 34i, 36 + 37i, 39 + 40i, 42 + 43i, 45 + 46i, 48 + 49i, 51 + 52i, 54 + 55i, 57 + 58i}, 86 want: 10235 - 335i, 87 wantRev: 8255 - 335i, 88 }, 89 { 90 x: []complex128{1 + 2i, 3 + 4i, 5 + 6i, 7 + 8i, 9 + 10i, 11 + 12i, 13 + 14i, 15 + 16i, 17 + 18i, 19 + 20i, 21 + 22i}, 91 y: []complex128{30 + 31i, 33 + 34i, 36 + 37i, 39 + 40i, 42 + 43i, 45 + 46i, 48 + 49i, 51 + 52i, 54 + 55i, 57 + 58i, 60 + 61i}, 92 want: 12837 - 374i, 93 wantRev: 10197 - 374i, 94 }, 95 { 96 x: []complex128{1 + 2i, 3 + 4i, 5 + 6i, 7 + 8i, 9 + 10i, 11 + 12i, 13 + 14i, 15 + 16i, 17 + 18i, 19 + 20i, 21 + 22i, 23 + 24i}, 97 y: []complex128{30 + 31i, 33 + 34i, 36 + 37i, 39 + 40i, 42 + 43i, 45 + 46i, 48 + 49i, 51 + 52i, 54 + 55i, 57 + 58i, 60 + 61i, 63 + 64i}, 98 want: 15822 - 414i, 99 wantRev: 12390 - 414i, 100 }, 101 } { 102 n := len(test.x) 103 if len(test.y) != n { 104 panic("bad test") 105 } 106 for _, inc := range allPairs([]int{-7, -3, 1, 13}, []int{-11, -5, 1, 17}) { 107 incX := inc[0] 108 incY := inc[1] 109 110 x := makeZVector(test.x, incX) 111 xCopy := make([]complex128, len(x)) 112 copy(xCopy, x) 113 114 y := makeZVector(test.y, incY) 115 yCopy := make([]complex128, len(y)) 116 copy(yCopy, y) 117 118 want := test.want 119 if incX*incY < 0 { 120 want = test.wantRev 121 } 122 123 got := impl.Zdotc(n, x, incX, y, incY) 124 125 prefix := fmt.Sprintf("Case %v (incX=%v,incY=%v):", tc, incX, incY) 126 127 if !zsame(x, xCopy) { 128 t.Errorf("%v: unexpected modification of x", prefix) 129 } 130 if !zsame(y, yCopy) { 131 t.Errorf("%v: unexpected modification of y", prefix) 132 } 133 134 if got != want { 135 t.Errorf("%v: unexpected result. want %v, got %v", prefix, want, got) 136 } 137 } 138 } 139 }