github.com/gopherd/gonum@v0.0.4/internal/asm/c64/util_test.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 c64 6 7 import ( 8 "testing" 9 10 "github.com/gopherd/gonum/cmplxs/cscalar" 11 ) 12 13 func same(x, y complex64) bool { 14 return cscalar.Same(complex128(x), complex128(y)) 15 } 16 17 func guardVector(vec []complex64, gdVal complex64, gdLen int) (guarded []complex64) { 18 guarded = make([]complex64, len(vec)+gdLen*2) 19 copy(guarded[gdLen:], vec) 20 for i := 0; i < gdLen; i++ { 21 guarded[i] = gdVal 22 guarded[len(guarded)-1-i] = gdVal 23 } 24 return guarded 25 } 26 27 func isValidGuard(vec []complex64, gdVal complex64, gdLen int) bool { 28 for i := 0; i < gdLen; i++ { 29 if !same(vec[i], gdVal) || !same(vec[len(vec)-1-i], gdVal) { 30 return false 31 } 32 } 33 return true 34 } 35 36 func guardIncVector(vec []complex64, gdVal complex64, inc, gdLen int) (guarded []complex64) { 37 if inc < 0 { 38 inc = -inc 39 } 40 inrLen := len(vec) * inc 41 guarded = make([]complex64, inrLen+gdLen*2) 42 for i := range guarded { 43 guarded[i] = gdVal 44 } 45 for i, v := range vec { 46 guarded[gdLen+i*inc] = v 47 } 48 return guarded 49 } 50 51 func checkValidIncGuard(t *testing.T, vec []complex64, gdVal complex64, inc, gdLen int) { 52 srcLen := len(vec) - 2*gdLen 53 if inc < 0 { 54 srcLen = len(vec) * -inc 55 } 56 57 for i := range vec { 58 switch { 59 case same(vec[i], gdVal): 60 // Correct value 61 case (i-gdLen)%inc == 0 && (i-gdLen)/inc < len(vec): 62 // Ignore input values 63 case i < gdLen: 64 t.Errorf("Front guard violated at %d %v", i, vec[:gdLen]) 65 case i > gdLen+srcLen: 66 t.Errorf("Back guard violated at %d %v", i-gdLen-srcLen, vec[gdLen+srcLen:]) 67 default: 68 t.Errorf("Internal guard violated at %d %v", i-gdLen, vec[gdLen:gdLen+srcLen]) 69 } 70 } 71 } 72 73 var ( // Offset sets for testing alignment handling in Unitary assembly functions. 74 align1 = []int{0, 1} 75 align2 = newIncSet(0, 1) 76 align3 = newIncToSet(0, 1) 77 ) 78 79 type incSet struct { 80 x, y int 81 } 82 83 // genInc will generate all (x,y) combinations of the input increment set. 84 func newIncSet(inc ...int) []incSet { 85 n := len(inc) 86 is := make([]incSet, n*n) 87 for x := range inc { 88 for y := range inc { 89 is[x*n+y] = incSet{inc[x], inc[y]} 90 } 91 } 92 return is 93 } 94 95 type incToSet struct { 96 dst, x, y int 97 } 98 99 // genIncTo will generate all (dst,x,y) combinations of the input increment set. 100 func newIncToSet(inc ...int) []incToSet { 101 n := len(inc) 102 is := make([]incToSet, n*n*n) 103 for i, dst := range inc { 104 for x := range inc { 105 for y := range inc { 106 is[i*n*n+x*n+y] = incToSet{dst, inc[x], inc[y]} 107 } 108 } 109 } 110 return is 111 }