gonum.org/v1/gonum@v0.14.0/blas/testblas/zaxpy.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 Zaxpyer interface { 13 Zaxpy(n int, alpha complex128, x []complex128, incX int, y []complex128, incY int) 14 } 15 16 func ZaxpyTest(t *testing.T, impl Zaxpyer) { 17 for tc, test := range []struct { 18 alpha complex128 19 x, y []complex128 20 21 want []complex128 // Result when both increments have the same sign. 22 wantRev []complex128 // Result when the increments have opposite sign. 23 }{ 24 { 25 alpha: 0, 26 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}, 27 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}, 28 want: []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}, 29 wantRev: []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}, 30 }, 31 { 32 alpha: 1, 33 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}, 34 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}, 35 want: []complex128{31 + 33i, 36 + 38i, 41 + 43i, 46 + 48i, 51 + 53i, 56 + 58i, 61 + 63i, 66 + 68i, 71 + 73i, 76 + 78i, 81 + 83i, 86 + 88i}, 36 wantRev: []complex128{53 + 55i, 54 + 56i, 55 + 57i, 56 + 58i, 57 + 59i, 58 + 60i, 59 + 61i, 60 + 62i, 61 + 63i, 62 + 64i, 63 + 65i, 64 + 66i}, 37 }, 38 { 39 alpha: 3 + 7i, 40 x: []complex128{1 + 2i}, 41 y: []complex128{30 + 31i}, 42 want: []complex128{19 + 44i}, 43 wantRev: []complex128{19 + 44i}, 44 }, 45 { 46 alpha: 3 + 7i, 47 x: []complex128{1 + 2i, 3 + 4i}, 48 y: []complex128{30 + 31i, 33 + 34i}, 49 want: []complex128{19 + 44i, 14 + 67i}, 50 wantRev: []complex128{11 + 64i, 22 + 47i}, 51 }, 52 { 53 alpha: 3 + 7i, 54 x: []complex128{1 + 2i, 3 + 4i, 5 + 6i}, 55 y: []complex128{30 + 31i, 33 + 34i, 36 + 37i}, 56 want: []complex128{19 + 44i, 14 + 67i, 9 + 90i}, 57 wantRev: []complex128{3 + 84i, 14 + 67i, 25 + 50i}, 58 }, 59 { 60 alpha: 3 + 7i, 61 x: []complex128{1 + 2i, 3 + 4i, 5 + 6i, 7 + 8i}, 62 y: []complex128{30 + 31i, 33 + 34i, 36 + 37i, 39 + 40i}, 63 want: []complex128{19 + 44i, 14 + 67i, 9 + 90i, 4 + 113i}, 64 wantRev: []complex128{-5 + 104i, 6 + 87i, 17 + 70i, 28 + 53i}, 65 }, 66 { 67 alpha: 3 + 7i, 68 x: []complex128{1 + 2i, 3 + 4i, 5 + 6i, 7 + 8i, 9 + 10i}, 69 y: []complex128{30 + 31i, 33 + 34i, 36 + 37i, 39 + 40i, 42 + 43i}, 70 want: []complex128{19 + 44i, 14 + 67i, 9 + 90i, 4 + 113i, -1 + 136i}, 71 wantRev: []complex128{-13 + 124i, -2 + 107i, 9 + 90i, 20 + 73i, 31 + 56i}, 72 }, 73 { 74 alpha: 3 + 7i, 75 x: []complex128{1 + 2i, 3 + 4i, 5 + 6i, 7 + 8i, 9 + 10i, 11 + 12i}, 76 y: []complex128{30 + 31i, 33 + 34i, 36 + 37i, 39 + 40i, 42 + 43i, 45 + 46i}, 77 want: []complex128{19 + 44i, 14 + 67i, 9 + 90i, 4 + 113i, -1 + 136i, -6 + 159i}, 78 wantRev: []complex128{-21 + 144i, -10 + 127i, 1 + 110i, 12 + 93i, 23 + 76i, 34 + 59i}, 79 }, 80 { 81 alpha: 3 + 7i, 82 x: []complex128{1 + 2i, 3 + 4i, 5 + 6i, 7 + 8i, 9 + 10i, 11 + 12i, 13 + 14i}, 83 y: []complex128{30 + 31i, 33 + 34i, 36 + 37i, 39 + 40i, 42 + 43i, 45 + 46i, 48 + 49i}, 84 want: []complex128{19 + 44i, 14 + 67i, 9 + 90i, 4 + 113i, -1 + 136i, -6 + 159i, -11 + 182i}, 85 wantRev: []complex128{-29 + 164i, -18 + 147i, -7 + 130i, 4 + 113i, 15 + 96i, 26 + 79i, 37 + 62i}, 86 }, 87 { 88 alpha: 3 + 7i, 89 x: []complex128{1 + 2i, 3 + 4i, 5 + 6i, 7 + 8i, 9 + 10i, 11 + 12i, 13 + 14i, 15 + 16i}, 90 y: []complex128{30 + 31i, 33 + 34i, 36 + 37i, 39 + 40i, 42 + 43i, 45 + 46i, 48 + 49i, 51 + 52i}, 91 want: []complex128{19 + 44i, 14 + 67i, 9 + 90i, 4 + 113i, -1 + 136i, -6 + 159i, -11 + 182i, -16 + 205i}, 92 wantRev: []complex128{-37 + 184i, -26 + 167i, -15 + 150i, -4 + 133i, 7 + 116i, 18 + 99i, 29 + 82i, 40 + 65i}, 93 }, 94 { 95 alpha: 3 + 7i, 96 x: []complex128{1 + 2i, 3 + 4i, 5 + 6i, 7 + 8i, 9 + 10i, 11 + 12i, 13 + 14i, 15 + 16i, 17 + 18i}, 97 y: []complex128{30 + 31i, 33 + 34i, 36 + 37i, 39 + 40i, 42 + 43i, 45 + 46i, 48 + 49i, 51 + 52i, 54 + 55i}, 98 want: []complex128{19 + 44i, 14 + 67i, 9 + 90i, 4 + 113i, -1 + 136i, -6 + 159i, -11 + 182i, -16 + 205i, -21 + 228i}, 99 wantRev: []complex128{-45 + 204i, -34 + 187i, -23 + 170i, -12 + 153i, -1 + 136i, 10 + 119i, 21 + 102i, 32 + 85i, 43 + 68i}, 100 }, 101 { 102 alpha: 3 + 7i, 103 x: []complex128{1 + 2i, 3 + 4i, 5 + 6i, 7 + 8i, 9 + 10i, 11 + 12i, 13 + 14i, 15 + 16i, 17 + 18i, 19 + 20i}, 104 y: []complex128{30 + 31i, 33 + 34i, 36 + 37i, 39 + 40i, 42 + 43i, 45 + 46i, 48 + 49i, 51 + 52i, 54 + 55i, 57 + 58i}, 105 want: []complex128{19 + 44i, 14 + 67i, 9 + 90i, 4 + 113i, -1 + 136i, -6 + 159i, -11 + 182i, -16 + 205i, -21 + 228i, -26 + 251i}, 106 wantRev: []complex128{-53 + 224i, -42 + 207i, -31 + 190i, -20 + 173i, -9 + 156i, 2 + 139i, 13 + 122i, 24 + 105i, 35 + 88i, 46 + 71i}, 107 }, 108 { 109 alpha: 3 + 7i, 110 x: []complex128{1 + 2i, 3 + 4i, 5 + 6i, 7 + 8i, 9 + 10i, 11 + 12i, 13 + 14i, 15 + 16i, 17 + 18i, 19 + 20i, 21 + 22i}, 111 y: []complex128{30 + 31i, 33 + 34i, 36 + 37i, 39 + 40i, 42 + 43i, 45 + 46i, 48 + 49i, 51 + 52i, 54 + 55i, 57 + 58i, 60 + 61i}, 112 want: []complex128{19 + 44i, 14 + 67i, 9 + 90i, 4 + 113i, -1 + 136i, -6 + 159i, -11 + 182i, -16 + 205i, -21 + 228i, -26 + 251i, -31 + 274i}, 113 wantRev: []complex128{-61 + 244i, -50 + 227i, -39 + 210i, -28 + 193i, -17 + 176i, -6 + 159i, 5 + 142i, 16 + 125i, 27 + 108i, 38 + 91i, 49 + 74i}, 114 }, 115 { 116 alpha: 3 + 7i, 117 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}, 118 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}, 119 want: []complex128{19 + 44i, 14 + 67i, 9 + 90i, 4 + 113i, -1 + 136i, -6 + 159i, -11 + 182i, -16 + 205i, -21 + 228i, -26 + 251i, -31 + 274i, -36 + 297i}, 120 wantRev: []complex128{-69 + 264i, -58 + 247i, -47 + 230i, -36 + 213i, -25 + 196i, -14 + 179i, -3 + 162i, 8 + 145i, 19 + 128i, 30 + 111i, 41 + 94i, 52 + 77i}, 121 }, 122 } { 123 n := len(test.x) 124 if len(test.y) != n || len(test.want) != n || len(test.wantRev) != n { 125 panic("bad test") 126 } 127 for _, inc := range allPairs([]int{-7, -3, 1, 13}, []int{-11, -5, 1, 17}) { 128 incX := inc[0] 129 incY := inc[1] 130 131 x := makeZVector(test.x, incX) 132 xCopy := make([]complex128, len(x)) 133 copy(xCopy, x) 134 135 y := makeZVector(test.y, incY) 136 137 var want []complex128 138 if incX*incY > 0 { 139 want = makeZVector(test.want, incY) 140 } else { 141 want = makeZVector(test.wantRev, incY) 142 } 143 144 impl.Zaxpy(n, test.alpha, x, incX, y, incY) 145 146 prefix := fmt.Sprintf("Case %v (incX=%v,incY=%v):", tc, incX, incY) 147 148 if !zsame(x, xCopy) { 149 t.Errorf("%v: unexpected modification of x", prefix) 150 } 151 152 if !zsame(y, want) { 153 t.Errorf("%v: unexpected y:\nwant %v\ngot %v", prefix, want, y) 154 } 155 } 156 } 157 }