-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdaddto.go
50 lines (49 loc) · 855 Bytes
/
daddto.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
package matrix
// AddTo performs: d += a * s
func (d Dense) AddTo(a Dense, s float64) {
d.checkDim(a)
switch s {
case 1:
for i := 0; i < d.numrow; i++ {
dr := d.v[i*d.stride:]
ar := a.v[i*a.stride:]
k, n := 0, d.numcol-1
for k < n {
dr[k+0] += ar[k+0]
dr[k+1] += ar[k+1]
k += 2
}
if k == n {
dr[k] += ar[k]
}
}
case -1:
for i := 0; i < d.numrow; i++ {
dr := d.v[i*d.stride:]
ar := a.v[i*a.stride:]
k, n := 0, d.numcol-1
for k < n {
dr[k+0] -= ar[k+0]
dr[k+1] -= ar[k+1]
k += 2
}
if k == n {
dr[k] -= ar[k]
}
}
default:
for i := 0; i < d.numrow; i++ {
dr := d.v[i*d.stride:]
ar := a.v[i*a.stride:]
k, n := 0, d.numcol-1
for k < n {
dr[k+0] += ar[k+0] * s
dr[k+1] += ar[k+1] * s
k += 2
}
if k == n {
dr[k] += ar[k] * s
}
}
}
}