gonum.org/v1/gonum@v0.14.0/blas/testblas/zdscal.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 Zdscaler interface { 13 Zdscal(n int, alpha float64, x []complex128, incX int) 14 } 15 16 func ZdscalTest(t *testing.T, impl Zdscaler) { 17 for tc, test := range []struct { 18 alpha float64 19 x []complex128 20 want []complex128 21 }{ 22 { 23 alpha: 3, 24 x: nil, 25 want: nil, 26 }, 27 { 28 alpha: 3, 29 x: []complex128{1 + 2i}, 30 want: []complex128{3 + 6i}, 31 }, 32 { 33 alpha: 3, 34 x: []complex128{1 + 2i, 3 + 4i}, 35 want: []complex128{3 + 6i, 9 + 12i}, 36 }, 37 { 38 alpha: 3, 39 x: []complex128{1 + 2i, 3 + 4i, 5 + 6i}, 40 want: []complex128{3 + 6i, 9 + 12i, 15 + 18i}, 41 }, 42 { 43 alpha: 3, 44 x: []complex128{1 + 2i, 3 + 4i, 5 + 6i, 7 + 8i}, 45 want: []complex128{3 + 6i, 9 + 12i, 15 + 18i, 21 + 24i}, 46 }, 47 { 48 alpha: 3, 49 x: []complex128{1 + 2i, 3 + 4i, 5 + 6i, 7 + 8i, 9 + 10i}, 50 want: []complex128{3 + 6i, 9 + 12i, 15 + 18i, 21 + 24i, 27 + 30i}, 51 }, 52 { 53 alpha: 3, 54 x: []complex128{1 + 2i, 3 + 4i, 5 + 6i, 7 + 8i, 9 + 10i, 11 + 12i}, 55 want: []complex128{3 + 6i, 9 + 12i, 15 + 18i, 21 + 24i, 27 + 30i, 33 + 36i}, 56 }, 57 { 58 alpha: 3, 59 x: []complex128{1 + 2i, 3 + 4i, 5 + 6i, 7 + 8i, 9 + 10i, 11 + 12i, 13 + 14i}, 60 want: []complex128{3 + 6i, 9 + 12i, 15 + 18i, 21 + 24i, 27 + 30i, 33 + 36i, 39 + 42i}, 61 }, 62 { 63 alpha: 3, 64 x: []complex128{1 + 2i, 3 + 4i, 5 + 6i, 7 + 8i, 9 + 10i, 11 + 12i, 13 + 14i, 15 + 16i}, 65 want: []complex128{3 + 6i, 9 + 12i, 15 + 18i, 21 + 24i, 27 + 30i, 33 + 36i, 39 + 42i, 45 + 48i}, 66 }, 67 { 68 alpha: 3, 69 x: []complex128{1 + 2i, 3 + 4i, 5 + 6i, 7 + 8i, 9 + 10i, 11 + 12i, 13 + 14i, 15 + 16i, 17 + 18i}, 70 want: []complex128{3 + 6i, 9 + 12i, 15 + 18i, 21 + 24i, 27 + 30i, 33 + 36i, 39 + 42i, 45 + 48i, 51 + 54i}, 71 }, 72 { 73 alpha: 3, 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{3 + 6i, 9 + 12i, 15 + 18i, 21 + 24i, 27 + 30i, 33 + 36i, 39 + 42i, 45 + 48i, 51 + 54i, 57 + 60i}, 76 }, 77 { 78 alpha: 3, 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{3 + 6i, 9 + 12i, 15 + 18i, 21 + 24i, 27 + 30i, 33 + 36i, 39 + 42i, 45 + 48i, 51 + 54i, 57 + 60i, 63 + 66i}, 81 }, 82 { 83 alpha: 3, 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{3 + 6i, 9 + 12i, 15 + 18i, 21 + 24i, 27 + 30i, 33 + 36i, 39 + 42i, 45 + 48i, 51 + 54i, 57 + 60i, 63 + 66i, 69 + 72i}, 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.Zdscal(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 }