github.com/gopherd/gonum@v0.0.4/blas/testblas/zscal.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 Zscaler interface { 13 Zscal(n int, alpha complex128, x []complex128, incX int) 14 } 15 16 func ZscalTest(t *testing.T, impl Zscaler) { 17 for tc, test := range []struct { 18 alpha complex128 19 x []complex128 20 want []complex128 21 }{ 22 { 23 alpha: 2 + 5i, 24 x: nil, 25 want: nil, 26 }, 27 { 28 alpha: 2 + 5i, 29 x: []complex128{1 + 2i}, 30 want: []complex128{-8 + 9i}, 31 }, 32 { 33 alpha: 2 + 5i, 34 x: []complex128{1 + 2i, 3 + 4i}, 35 want: []complex128{-8 + 9i, -14 + 23i}, 36 }, 37 { 38 alpha: 2 + 5i, 39 x: []complex128{1 + 2i, 3 + 4i, 5 + 6i}, 40 want: []complex128{-8 + 9i, -14 + 23i, -20 + 37i}, 41 }, 42 { 43 alpha: 2 + 5i, 44 x: []complex128{1 + 2i, 3 + 4i, 5 + 6i, 7 + 8i}, 45 want: []complex128{-8 + 9i, -14 + 23i, -20 + 37i, -26 + 51i}, 46 }, 47 { 48 alpha: 2 + 5i, 49 x: []complex128{1 + 2i, 3 + 4i, 5 + 6i, 7 + 8i, 9 + 10i}, 50 want: []complex128{-8 + 9i, -14 + 23i, -20 + 37i, -26 + 51i, -32 + 65i}, 51 }, 52 { 53 alpha: 2 + 5i, 54 x: []complex128{1 + 2i, 3 + 4i, 5 + 6i, 7 + 8i, 9 + 10i, 11 + 12i}, 55 want: []complex128{-8 + 9i, -14 + 23i, -20 + 37i, -26 + 51i, -32 + 65i, -38 + 79i}, 56 }, 57 { 58 alpha: 2 + 5i, 59 x: []complex128{1 + 2i, 3 + 4i, 5 + 6i, 7 + 8i, 9 + 10i, 11 + 12i, 13 + 14i}, 60 want: []complex128{-8 + 9i, -14 + 23i, -20 + 37i, -26 + 51i, -32 + 65i, -38 + 79i, -44 + 93i}, 61 }, 62 { 63 alpha: 2 + 5i, 64 x: []complex128{1 + 2i, 3 + 4i, 5 + 6i, 7 + 8i, 9 + 10i, 11 + 12i, 13 + 14i, 15 + 16i}, 65 want: []complex128{-8 + 9i, -14 + 23i, -20 + 37i, -26 + 51i, -32 + 65i, -38 + 79i, -44 + 93i, -50 + 107i}, 66 }, 67 { 68 alpha: 2 + 5i, 69 x: []complex128{1 + 2i, 3 + 4i, 5 + 6i, 7 + 8i, 9 + 10i, 11 + 12i, 13 + 14i, 15 + 16i, 17 + 18i}, 70 want: []complex128{-8 + 9i, -14 + 23i, -20 + 37i, -26 + 51i, -32 + 65i, -38 + 79i, -44 + 93i, -50 + 107i, -56 + 121i}, 71 }, 72 { 73 alpha: 2 + 5i, 74 x: []complex128{1 + 2i, 3 + 4i, 5 + 6i, 7 + 8i, 9 + 10i, 11 + 12i, 13 + 14i, 15 + 16i, 17 + 18i, 19 + 20i}, 75 want: []complex128{-8 + 9i, -14 + 23i, -20 + 37i, -26 + 51i, -32 + 65i, -38 + 79i, -44 + 93i, -50 + 107i, -56 + 121i, -62 + 135i}, 76 }, 77 { 78 alpha: 2 + 5i, 79 x: []complex128{1 + 2i, 3 + 4i, 5 + 6i, 7 + 8i, 9 + 10i, 11 + 12i, 13 + 14i, 15 + 16i, 17 + 18i, 19 + 20i, 21 + 22i}, 80 want: []complex128{-8 + 9i, -14 + 23i, -20 + 37i, -26 + 51i, -32 + 65i, -38 + 79i, -44 + 93i, -50 + 107i, -56 + 121i, -62 + 135i, -68 + 149i}, 81 }, 82 { 83 alpha: 2 + 5i, 84 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}, 85 want: []complex128{-8 + 9i, -14 + 23i, -20 + 37i, -26 + 51i, -32 + 65i, -38 + 79i, -44 + 93i, -50 + 107i, -56 + 121i, -62 + 135i, -68 + 149i, -74 + 163i}, 86 }, 87 { 88 alpha: 0, 89 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}, 90 want: []complex128{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, 91 }, 92 } { 93 n := len(test.x) 94 if len(test.want) != n { 95 panic("bad test") 96 } 97 for _, incX := range []int{-3, -1, 1, 2, 4, 7, 10} { 98 x := makeZVector(test.x, incX) 99 xCopy := make([]complex128, len(x)) 100 copy(xCopy, x) 101 102 want := makeZVector(test.want, incX) 103 104 impl.Zscal(n, test.alpha, x, incX) 105 106 prefix := fmt.Sprintf("Case %v (n=%v,incX=%v):", tc, n, incX) 107 108 if incX < 0 { 109 if !zsame(x, xCopy) { 110 t.Errorf("%v: unexpected modification of x\nwant %v\ngot %v", prefix, want, x) 111 } 112 continue 113 } 114 if !zsame(x, want) { 115 t.Errorf("%v: unexpected result:\nwant: %v\ngot: %v", prefix, want, x) 116 } 117 } 118 } 119 }