github.com/egonelbre/exp@v0.0.0-20240430123955-ed1d3aa93911/vector/define/op.go (about) 1 package define 2 3 import . "github.com/egonelbre/exp/vector/vector" 4 5 func AddConst[T float32 | float64 | complex64 | complex128](alpha T, xs []T, n uintptr) { 6 Apply1( 7 Vector[T]{Values: xs, Offset: 0, Inc: 1}, 8 n, func(x T) T { 9 return x + alpha 10 }) 11 } 12 13 func AddConstTo[T float32 | float64 | complex64 | complex128](dst []T, alpha T, xs []T, n uintptr) { 14 Apply1To( 15 Vector[T]{Values: dst, Offset: 0, Inc: 1}, 16 Vector[T]{Values: xs, Offset: 0, Inc: 1}, 17 n, func(x T) T { 18 return x + alpha 19 }) 20 } 21 22 func Add[T float32 | float64 | complex64 | complex128](xs, ys []T, n uintptr) { 23 Apply2( 24 Vector[T]{Values: xs, Offset: 0, Inc: 1}, 25 Vector[T]{Values: ys, Offset: 0, Inc: 1}, 26 n, func(x, y T) T { 27 return x + y 28 }) 29 } 30 31 func AddTo[T float32 | float64 | complex64 | complex128](dst, xs, ys []T, n uintptr) { 32 Apply2To( 33 Vector[T]{Values: dst, Offset: 0, Inc: 1}, 34 Vector[T]{Values: xs, Offset: 0, Inc: 1}, 35 Vector[T]{Values: ys, Offset: 0, Inc: 1}, 36 n, func(x, y T) T { 37 return x + y 38 }) 39 } 40 41 func Sub[T float32 | float64 | complex64 | complex128](xs, ys []T, n uintptr) { 42 Apply2( 43 Vector[T]{Values: xs, Offset: 0, Inc: 1}, 44 Vector[T]{Values: ys, Offset: 0, Inc: 1}, 45 n, func(x, y T) T { 46 return x - y 47 }) 48 } 49 50 func SubTo[T float32 | float64 | complex64 | complex128](dst, xs, ys []T, n uintptr) { 51 Apply2To( 52 Vector[T]{Values: dst, Offset: 0, Inc: 1}, 53 Vector[T]{Values: xs, Offset: 0, Inc: 1}, 54 Vector[T]{Values: ys, Offset: 0, Inc: 1}, 55 n, func(x, y T) T { 56 return x - y 57 }) 58 } 59 60 func Mul[T float32 | float64 | complex64 | complex128](xs, ys []T, n uintptr) { 61 Apply2( 62 Vector[T]{Values: xs, Offset: 0, Inc: 1}, 63 Vector[T]{Values: ys, Offset: 0, Inc: 1}, 64 n, func(x, y T) T { 65 return x * y 66 }) 67 } 68 69 func MulTo[T float32 | float64 | complex64 | complex128](dst, xs, ys []T, n uintptr) { 70 Apply2To( 71 Vector[T]{Values: dst, Offset: 0, Inc: 1}, 72 Vector[T]{Values: xs, Offset: 0, Inc: 1}, 73 Vector[T]{Values: ys, Offset: 0, Inc: 1}, 74 n, func(x, y T) T { 75 return x * y 76 }) 77 } 78 79 func Div[T float32 | float64 | complex64 | complex128](xs, ys []T, n uintptr) { 80 Apply2( 81 Vector[T]{Values: xs, Offset: 0, Inc: 1}, 82 Vector[T]{Values: ys, Offset: 0, Inc: 1}, 83 n, func(x, y T) T { 84 return x * y 85 }) 86 } 87 88 func DivTo[T float32 | float64 | complex64 | complex128](dst, xs, ys []T, n uintptr) { 89 Apply2To( 90 Vector[T]{Values: dst, Offset: 0, Inc: 1}, 91 Vector[T]{Values: xs, Offset: 0, Inc: 1}, 92 Vector[T]{Values: ys, Offset: 0, Inc: 1}, 93 n, func(x, y T) T { 94 return x / y 95 }) 96 }