gonum.org/v1/gonum@v0.14.0/blas/testblas/zcopy.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 "golang.org/x/exp/rand" 12 ) 13 14 type Zcopyer interface { 15 Zcopy(n int, x []complex128, incX int, y []complex128, incY int) 16 } 17 18 func ZcopyTest(t *testing.T, impl Zcopyer) { 19 rnd := rand.New(rand.NewSource(1)) 20 for n := 0; n <= 20; n++ { 21 for _, inc := range allPairs([]int{-7, -3, 1, 13}, []int{-11, -5, 1, 17}) { 22 incX := inc[0] 23 incY := inc[1] 24 aincX := abs(incX) 25 aincY := abs(incY) 26 27 var x []complex128 28 if n > 0 { 29 x = make([]complex128, (n-1)*aincX+1) 30 } 31 for i := range x { 32 x[i] = znan 33 } 34 for i := 0; i < n; i++ { 35 x[i*aincX] = complex(rnd.NormFloat64(), rnd.NormFloat64()) 36 } 37 xCopy := make([]complex128, len(x)) 38 copy(xCopy, x) 39 40 var y []complex128 41 if n > 0 { 42 y = make([]complex128, (n-1)*aincY+1) 43 } 44 for i := range y { 45 y[i] = znan 46 } 47 48 want := make([]complex128, len(y)) 49 for i := range want { 50 want[i] = znan 51 } 52 if incX*incY > 0 { 53 for i := 0; i < n; i++ { 54 want[i*aincY] = x[i*aincX] 55 } 56 } else { 57 for i := 0; i < n; i++ { 58 want[i*aincY] = x[(n-1-i)*aincX] 59 } 60 } 61 62 impl.Zcopy(n, x, incX, y, incY) 63 64 prefix := fmt.Sprintf("Case n=%v,incX=%v,incY=%v:", n, incX, incY) 65 66 if !zsame(x, xCopy) { 67 t.Errorf("%v: unexpected modification of x", prefix) 68 } 69 if !zsame(y, want) { 70 t.Errorf("%v: unexpected y:\nwant %v\ngot %v", prefix, want, y) 71 } 72 } 73 } 74 }