Skip to content
Browse files

Idamax and Dswap added

  • Loading branch information...
1 parent 7845a0f commit 70ca8385efe9f8aa43ba43978917376bf48b7435 @ziutek committed Oct 26, 2011
Showing with 129 additions and 20 deletions.
  1. +2 −0 Makefile
  2. +13 −0 common.go
  3. +65 −1 d_test.go
  4. +1 −1 dasum.go
  5. +1 −1 dasum_amd64.s
  6. +1 −1 ddot.go
  7. +1 −1 ddot_amd64.s
  8. +7 −0 dgemv.go
  9. +1 −1 dnrm2_amd64.s
  10. +11 −0 dswap.go
  11. +22 −0 idamax.go
  12. +1 −1 sdot.go
  13. +1 −1 sdot_amd64.s
  14. +1 −1 sdsdot.go
  15. +1 −1 sdsdot_amd64.s
  16. +0 −10 todo.go
View
2 Makefile
@@ -13,12 +13,14 @@ OFILES=\
$(OFILES_$(GOARCH))
ALLGOFILES=\
+ common.go\
sdsdot.go\
sdot.go\
ddot.go\
dnrm2.go\
dasum.go\
idamax.go\
+ dswap.go\
NOGOFILES=\
$(subst _$(GOARCH).$O,.go,$(OFILES_$(GOARCH)))
View
13 common.go
@@ -0,0 +1,13 @@
+package blas
+
+type Order int
+const (
+ RowMajor = Order(101)
+ ColMajor = Order(102)
+)
+
+type Transpose int
+const (
+ NoTrans = Transpose(111)
+ Trans = Transpose(112)
+)
View
66 d_test.go
@@ -6,6 +6,13 @@ import (
"math"
)
+func iCheck(t *testing.T, inc, N, r, e int) {
+ t.Logf("inc=%d N=%d : r=%d e=%d", inc, N, r, e)
+ if r != e {
+ t.FailNow()
+ }
+}
+
func dCheck(t *testing.T, inc, N int, r, e float64) {
t.Logf("inc=%d N=%d : r=%f e=%f e-r=%g", inc, N, r, e, e-r)
if r != e {
@@ -45,7 +52,7 @@ func TestDnrm2(t *testing.T) {
}
func TestDasum(t *testing.T) {
- xd := []float64{-1, -2, 3, -4, -5, -6, 7, -8, 9}
+ xd := []float64{-1, -2, 3, -4, -5, -6, 7, -8, 9, 1, -2, 3, -4, 5, -6, -7, 8}
for inc := 1; inc < 9; inc++ {
e := 0.0
k := 0
@@ -60,6 +67,47 @@ func TestDasum(t *testing.T) {
}
}
+func TestIdamax(t *testing.T) {
+ xd := []float64{-1, -2, 3, -4, -5, 0, -5, 0, 4, 2, 3, -1, 4, 2}
+ for inc := 1; inc < 9; inc++ {
+ for N := 0; N <= len(xd) / inc; N++ {
+ i_max := -1
+ x_max := 0.0
+ for i := 0; i < N; i++ {
+ x := math.Abs(xd[i * inc])
+ if x > x_max {
+ x_max = x
+ i_max = i
+ }
+ }
+ r := Idamax(N, xd, inc)
+ iCheck(t, inc, N, r, i_max)
+ }
+ }
+}
+
+func TestDswap(t *testing.T) {
+ a := make([]float64, len(xd))
+ b := make([]float64, len(yd))
+ for inc := 1; inc < 9; inc++ {
+ for N := 0; N <= len(xd) / inc; N++ {
+ copy(a, xd)
+ copy(b, yd)
+ Dswap(N, a, inc, b, inc)
+ for i := 0; i < len(a); i++ {
+ if i <= inc * (N-1) && i % inc == 0 {
+ if a[i] != yd[i] || b[i] != xd[i] {
+ t.Fatalf("inc=%d N=%d", inc, N)
+ }
+ } else {
+ if a[i] != xd[i] || b[i] != yd[i] {
+ t.Fatalf("inc=%d N=%d", inc, N)
+ }
+ }
+ }
+ }
+ }
+}
var vd, wd []float64
@@ -89,3 +137,19 @@ func BenchmarkDasum(b *testing.B) {
Dasum(len(vd), vd, 1)
}
}
+
+func BenchmarkIdamax(b *testing.B) {
+ for i := 0; i < b.N; i++ {
+ Idamax(len(vd), vd, 1)
+ }
+}
+
+func BenchmarkDswap(b *testing.B) {
+ b.StopTimer()
+ x := make([]float64, len(vd))
+ y := make([]float64, len(vd))
+ b.StartTimer()
+ for i := 0; i < b.N; i++ {
+ Dswap(len(x), x, 1, y, 1)
+ }
+}
View
2 dasum.go
@@ -1,6 +1,6 @@
package blas
-// Absolute sum: \sum |x_i|
+// Absolute sum: \sum |X_i|
func Dasum(N int, X []float64, incX int) float64 {
var (
a float64
View
2 dasum_amd64.s
@@ -115,5 +115,5 @@ end:
RET
panic:
- CALL runtime·panicslice(SB)
+ CALL runtime·panicindex(SB)
RET
View
2 ddot.go
@@ -1,6 +1,6 @@
package blas
-// Scalar product: x^T y
+// Scalar product: X^T Y
func Ddot(N int, X []float64, incX int, Y []float64, incY int) float64 {
var (
a, b, c, d float64
View
2 ddot_amd64.s
@@ -132,5 +132,5 @@ end:
RET
panic:
- CALL runtime·panicslice(SB)
+ CALL runtime·panicindex(SB)
RET
View
7 dgemv.go
@@ -0,0 +1,7 @@
+package blas
+
+/*func Dgemv(order Order, TransA Transpose, N, M, KL, KU int,
+ alpha float64, A []float64, lda int, X []float64, incX int,
+ beta float64, Y []float64, incY int) {
+
+}*/
View
2 dnrm2_amd64.s
@@ -112,5 +112,5 @@ end:
RET
panic:
- CALL runtime·panicslice(SB)
+ CALL runtime·panicindex(SB)
RET
View
11 dswap.go
@@ -0,0 +1,11 @@
+package blas
+
+// exchange the elements of the vectors X and Y.
+func Dswap(N int, X []float64, incX int, Y []float64, incY int) {
+ var xi, yi int
+ for ; N > 0; N-- {
+ X[xi], Y[yi] = Y[yi], X[xi]
+ xi += incX
+ yi += incY
+ }
+}
View
22 idamax.go
@@ -0,0 +1,22 @@
+package blas
+
+// Index of largest (absoulute) element of the vector X
+func Idamax(N int, X []float64, incX int) int {
+ var (
+ max_x float64
+ xi int
+ )
+ max_n := -1
+ for n := 0; n < N; n++ {
+ x := X[xi]
+ if x < 0 {
+ x = -x
+ }
+ if x > max_x {
+ max_x = x
+ max_n = n
+ }
+ xi += incX
+ }
+ return max_n
+}
View
2 sdot.go
@@ -1,6 +1,6 @@
package blas
-// Scalar product: x^T y
+// Scalar product: X^T Y
func Sdot(N int, X []float32, incX int, Y []float32, incY int) float32 {
var (
a, b, c, d float32
View
2 sdot_amd64.s
@@ -139,5 +139,5 @@ end:
RET
panic:
- CALL runtime·panicslice(SB)
+ CALL runtime·panicindex(SB)
RET
View
2 sdsdot.go
@@ -1,6 +1,6 @@
package blas
-// \alpha + x^T y computed using float64
+// \alpha + X^T Y computed using float64
func Sdsdot(N int, alpha float32, X []float32, incX int, Y []float32, incY int) float32 {
var (
a, b, c, d float64
View
2 sdsdot_amd64.s
@@ -164,5 +164,5 @@ end:
RET
panic:
- CALL runtime·panicslice(SB)
+ CALL runtime·panicindex(SB)
RET
View
10 todo.go
@@ -1,10 +0,0 @@
-package blas
-
-// Exchange the elements of the vectors Y and Y
-//func Dswap(N int, X []float64, incX int, Y []float64, incY int)
-
-// Copy the elements of the vector X into the vector Y
-//func Dcopy(N int, X []float64, incX int, Y []float64, incY int)
-
-// Compute the sum: Y = \alpha X + Y
-//func Daxpy(N int, alpha float64, X []float64, incX int, Y []float64, incY int)

0 comments on commit 70ca838

Please sign in to comment.
Something went wrong with that request. Please try again.