-
Notifications
You must be signed in to change notification settings - Fork 4
/
incr.go
138 lines (122 loc) · 3.15 KB
/
incr.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
package vecf64
import "math"
// IncrAdd performs a̅ + b̅ and then adds it elementwise to the incr slice
func IncrAdd(a, b, incr []float64) {
b = b[:len(a)]
incr = incr[:len(a)]
for i, v := range a {
incr[i] += v + b[i]
}
}
// IncrSub performs a̅ = b̅ and then adds it elementwise to the incr slice
func IncrSub(a, b, incr []float64) {
b = b[:len(a)]
incr = incr[:len(a)]
for i, v := range a {
incr[i] += v - b[i]
}
}
// IncrMul performs a̅ × b̅ and then adds it elementwise to the incr slice
func IncrMul(a, b, incr []float64) {
b = b[:len(a)]
incr = incr[:len(a)]
for i, v := range a {
incr[i] += v * b[i]
}
}
func IncrDiv(a, b, incr []float64) {
b = b[:len(a)]
incr = incr[:len(a)]
for i, v := range a {
if b[i] == 0 {
incr[i] = math.Inf(0)
continue
}
incr[i] += v / b[i]
}
}
// IncrDiv performs a̅ ÷ b̅. a̅ will be clobbered
func IncrPow(a, b, incr []float64) {
b = b[:len(a)]
incr = incr[:len(a)]
for i, v := range a {
switch b[i] {
case 0:
incr[i]++
case 1:
incr[i] += v
case 2:
incr[i] += v * v
case 3:
incr[i] += v * v * v
default:
incr[i] += math.Pow(v, b[i])
}
}
}
// IncrMod performs a̅ % b̅ then adds it to incr
func IncrMod(a, b, incr []float64) {
b = b[:len(a)]
incr = incr[:len(a)]
for i, v := range a {
incr[i] += math.Mod(v, b[i])
}
}
// Scale multiplies all values in the slice by the scalar and then increments the incr slice
// incr += a̅ * s
func IncrScale(a []float64, s float64, incr []float64) {
incr = incr[:len(a)]
for i, v := range a {
incr[i] += v * s
}
}
// IncrScaleInv divides all values in the slice by the scalar and then increments the incr slice
// incr += a̅ / s
func IncrScaleInv(a []float64, s float64, incr []float64) {
IncrScale(a, 1/s, incr)
}
/// IncrScaleInvR divides all numbers in the slice by a scalar and then increments the incr slice
// incr += s / a̅
func IncrScaleInvR(a []float64, s float64, incr []float64) {
incr = incr[:len(a)]
for i, v := range a {
incr[i] += s / v
}
}
// IncrTrans adds all the values in the slice by a scalar and then increments the incr slice
// incr += a̅ + s
func IncrTrans(a []float64, s float64, incr []float64) {
incr = incr[:len(a)]
for i, v := range a {
incr[i] += v + s
}
}
// IncrTransInv subtracts all the values in the slice by a scalar and then increments the incr slice
// incr += a̅ - s
func IncrTransInv(a []float64, s float64, incr []float64) {
IncrTrans(a, -s, incr)
}
// IncrTransInvR subtracts all the numbers in a slice from a scalar and then increments the incr slice
// incr += s - a̅
func IncrTransInvR(a []float64, s float64, incr []float64) {
incr = incr[:len(a)]
for i, v := range a {
incr[i] += s - v
}
}
// IncrPowOf performs elementwise power function and then increments the incr slice
// incr += a̅ ^ s
func IncrPowOf(a []float64, s float64, incr []float64) {
incr = incr[:len(a)]
for i, v := range a {
incr[i] += math.Pow(v, s)
}
}
// PowOfR performs elementwise power function below and then increments the incr slice.
// incr += s ^ a̅
func IncrPowOfR(a []float64, s float64, incr []float64) {
incr = incr[:len(a)]
for i, v := range a {
incr[i] += math.Pow(s, v)
}
}