blas/testblas:  Added Sger benchmarking.
MODIFY
blas/testblas/common.go
blas/testblas/common.go
@@ -200,7 +200,7 @@ func flattenBanded(a [][]float64, ku, kl int) []float64 {
return aflat
}
-// makeIncremented takes a slice with inc == 1 and makes an incremented version
+// makeIncremented takes a float64 slice with inc == 1 and makes an incremented version
// and adds extra values on the end
func makeIncremented(x []float64, inc int, extra int) []float64 {
if inc == 0 {
@@ -239,6 +239,45 @@ func makeIncremented(x []float64, inc int, extra int) []float64 {
return xnew
}
+// makeIncremented32 takes a float32 slice with inc == 1 and makes an incremented version
+// and adds extra values on the end
+func makeIncremented32(x []float32, inc int, extra int) []float32 {
+ if inc == 0 {
+ panic("zero inc")
+ }
+ absinc := inc
+ if absinc < 0 {
+ absinc = -inc
+ }
+ xcopy := make([]float32, len(x))
+ if inc > 0 {
+ copy(xcopy, x)
+ } else {
+ for i := 0; i < len(x); i++ {
+ xcopy[i] = x[len(x)-i-1]
+ }
+ }
+
+ // don't use NaN because it makes comparison hard
+ // Do use a weird unique value for easier debugging
+ var counter float32 = 100.0
+ var xnew []float32
+ for i, v := range xcopy {
+ xnew = append(xnew, v)
+ if i != len(x)-1 {
+ for j := 0; j < absinc-1; j++ {
+ xnew = append(xnew, counter)
+ counter++
+ }
+ }
+ }
+ for i := 0; i < extra; i++ {
+ xnew = append(xnew, counter)
+ counter++
+ }
+ return xnew
+}
+
func abs(x int) int {
if x < 0 {
return -x

MODIFY
blas/testblas/level2bench.go
blas/testblas/level2bench.go
@@ -8,7 +8,7 @@ import (
"gonum.org/v1/gonum/blas"
)
-func DgemvBenchmark(b *testing.B, blasser Dgemver, tA blas.Transpose, m, n, incX, incY int) {
+func DgemvBenchmark(b *testing.B, impl Dgemver, tA blas.Transpose, m, n, incX, incY int) {
var lenX, lenY int
if tA == blas.NoTrans {
lenX = n
@@ -34,11 +34,11 @@ func DgemvBenchmark(b *testing.B, blasser Dgemver, tA blas.Transpose, m, n, incX
b.ResetTimer()
for i := 0; i < b.N; i++ {
- blasser.Dgemv(tA, m, n, 2, a, n, x, incX, 3, y, incY)
+ impl.Dgemv(tA, m, n, 2, a, n, x, incX, 3, y, incY)
}
}
-func DgerBenchmark(b *testing.B, blasser Dgerer, m, n, incX, incY int) {
+func DgerBenchmark(b *testing.B, impl Dgerer, m, n, incX, incY int) {
xr := make([]float64, m)
for i := range xr {
xr[i] = rand.Float64()
@@ -56,6 +56,32 @@ func DgerBenchmark(b *testing.B, blasser Dgerer, m, n, incX, incY int) {
b.ResetTimer()
for i := 0; i < b.N; i++ {
- blasser.Dger(m, n, 2, x, incX, y, incY, a, n)
+ impl.Dger(m, n, 2, x, incX, y, incY, a, n)
+ }
+}
+
+type Sgerer interface {
+ Sger(m, n int, alpha float32, x []float32, incX int, y []float32, incY int, a []float32, lda int)
+}
+
+func SgerBenchmark(b *testing.B, blasser Sgerer, m, n, incX, incY int) {
+ xr := make([]float32, m)
+ for i := range xr {
+ xr[i] = rand.Float32()
+ }
+ x := makeIncremented32(xr, incX, 0)
+ yr := make([]float32, n)
+ for i := range yr {
+ yr[i] = rand.Float32()
+ }
+ y := makeIncremented32(yr, incY, 0)
+ a := make([]float32, m*n)
+ for i := range a {
+ a[i] = rand.Float32()
+ }
+
+ b.ResetTimer()
+ for i := 0; i < b.N; i++ {
+ blasser.Sger(m, n, 2, x, incX, y, incY, a, n)
}
}

blas/testblas:  Added Sger benchmarking.