-
Notifications
You must be signed in to change notification settings - Fork 19
/
daxpy.go
50 lines (45 loc) · 817 Bytes
/
daxpy.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 blas
// Compute the sum Y = \alpha X + Y for the vectors X and Y
func Daxpy(N int, alpha float64, X []float64, incX int, Y []float64, incY int)
func daxpy(N int, alpha float64, X []float64, incX int, Y []float64, incY int) {
var xi, yi int
switch alpha {
case 0:
case 1:
for ; N >= 2; N -= 2 {
Y[yi] += X[xi]
xi += incX
yi += incY
Y[yi] += X[xi]
xi += incX
yi += incY
}
if N != 0 {
Y[yi] += alpha * X[xi]
}
case -1:
for ; N >= 2; N -= 2 {
Y[yi] -= X[xi]
xi += incX
yi += incY
Y[yi] -= X[xi]
xi += incX
yi += incY
}
if N != 0 {
Y[yi] -= X[xi]
}
default:
for ; N >= 2; N -= 2 {
Y[yi] += alpha * X[xi]
xi += incX
yi += incY
Y[yi] += alpha * X[xi]
xi += incX
yi += incY
}
if N != 0 {
Y[yi] += alpha * X[xi]
}
}
}