blas/gonum: add checking functions for matrices and vectors
MODIFY
blas/gonum/dgemm.go
blas/gonum/dgemm.go
@@ -25,17 +25,17 @@ func (Implementation) Dgemm(tA, tB blas.Transpose, m, n, k int, alpha float64, a
}
aTrans := tA == blas.Trans || tA == blas.ConjTrans
if aTrans {
- checkMatrix64('a', k, m, a, lda)
+ checkDMatrix('a', k, m, a, lda)
} else {
- checkMatrix64('a', m, k, a, lda)
+ checkDMatrix('a', m, k, a, lda)
}
bTrans := tB == blas.Trans || tB == blas.ConjTrans
if bTrans {
- checkMatrix64('b', n, k, b, ldb)
+ checkDMatrix('b', n, k, b, ldb)
} else {
- checkMatrix64('b', k, n, b, ldb)
+ checkDMatrix('b', k, n, b, ldb)
}
- checkMatrix64('c', m, n, c, ldc)
+ checkDMatrix('c', m, n, c, ldc)
// scale c
if beta != 1 {
@@ -259,18 +259,3 @@ func dgemmSerialTransTrans(m, n, k int, a []float64, lda int, b []float64, ldb i
func sliceView64(a []float64, lda, i, j, r, c int) []float64 {
return a[i*lda+j : (i+r-1)*lda+j+c]
}
-
-func checkMatrix64(name byte, m, n int, a []float64, lda int) {
- if m < 0 {
- panic("blas: rows < 0")
- }
- if n < 0 {
- panic("blas: cols < 0")
- }
- if lda < n {
- panic("blas: illegal stride")
- }
- if len(a) < (m-1)*lda+n {
- panic("blas: index of " + string(name) + " out of range")
- }
-}

MODIFY
blas/gonum/gonum.go
blas/gonum/gonum.go
@@ -64,6 +64,63 @@ func min(a, b int) int {
return a
}
+func checkSMatrix(name byte, m, n int, a []float32, lda int) {
+ if m < 0 {
+ panic(mLT0)
+ }
+ if n < 0 {
+ panic(nLT0)
+ }
+ if lda < n {
+ panic("blas: illegal stride of " + string(name))
+ }
+ if len(a) < (m-1)*lda+n {
+ panic("blas: index of " + string(name) + " out of range")
+ }
+}
+
+func checkDMatrix(name byte, m, n int, a []float64, lda int) {
+ if m < 0 {
+ panic(mLT0)
+ }
+ if n < 0 {
+ panic(nLT0)
+ }
+ if lda < n {
+ panic("blas: illegal stride of " + string(name))
+ }
+ if len(a) < (m-1)*lda+n {
+ panic("blas: index of " + string(name) + " out of range")
+ }
+}
+
+func checkZMatrix(name byte, m, n int, a []complex128, lda int) {
+ if m < 0 {
+ panic(mLT0)
+ }
+ if n < 0 {
+ panic(nLT0)
+ }
+ if lda < max(1, n) {
+ panic("blas: illegal stride of " + string(name))
+ }
+ if len(a) < (m-1)*lda+n {
+ panic("blas: insufficient " + string(name) + " matrix slice length")
+ }
+}
+
+func checkZVector(name byte, n int, x []complex128, incX int) {
+ if n < 0 {
+ panic(nLT0)
+ }
+ if incX == 0 {
+ panic(zeroIncX)
+ }
+ if (incX > 0 && (n-1)*incX >= len(x)) || (incX < 0 && (1-n)*incX >= len(x)) {
+ panic("blas: insufficient " + string(name) + " vector slice length")
+ }
+}
+
// blocks returns the number of divisions of the dimension length with the given
// block size.
func blocks(dim, bsize int) int {

MODIFY
blas/gonum/sgemm.go
blas/gonum/sgemm.go
@@ -29,17 +29,17 @@ func (Implementation) Sgemm(tA, tB blas.Transpose, m, n, k int, alpha float32, a
}
aTrans := tA == blas.Trans || tA == blas.ConjTrans
if aTrans {
- checkMatrix32('a', k, m, a, lda)
+ checkSMatrix('a', k, m, a, lda)
} else {
- checkMatrix32('a', m, k, a, lda)
+ checkSMatrix('a', m, k, a, lda)
}
bTrans := tB == blas.Trans || tB == blas.ConjTrans
if bTrans {
- checkMatrix32('b', n, k, b, ldb)
+ checkSMatrix('b', n, k, b, ldb)
} else {
- checkMatrix32('b', k, n, b, ldb)
+ checkSMatrix('b', k, n, b, ldb)
}
- checkMatrix32('c', m, n, c, ldc)
+ checkSMatrix('c', m, n, c, ldc)
// scale c
if beta != 1 {
@@ -263,18 +263,3 @@ func sgemmSerialTransTrans(m, n, k int, a []float32, lda int, b []float32, ldb i
func sliceView32(a []float32, lda, i, j, r, c int) []float32 {
return a[i*lda+j : (i+r-1)*lda+j+c]
}
-
-func checkMatrix32(name byte, m, n int, a []float32, lda int) {
- if m < 0 {
- panic("blas: rows < 0")
- }
- if n < 0 {
- panic("blas: cols < 0")
- }
- if lda < n {
- panic("blas: illegal stride")
- }
- if len(a) < (m-1)*lda+n {
- panic("blas: index of " + string(name) + " out of range")
- }
-}

MODIFY
blas/gonum/single_precision.bash
blas/gonum/single_precision.bash
@@ -136,7 +136,6 @@ cat dgemm.go \
| gofmt -r 'float64 -> float32' \
| gofmt -r 'general64 -> general32' \
| gofmt -r 'sliceView64 -> sliceView32' \
-| gofmt -r 'checkMatrix64 -> checkMatrix32' \
\
| gofmt -r 'dgemmParallel -> sgemmParallel' \
| gofmt -r 'computeNumBlocks64 -> computeNumBlocks32' \

blas/gonum: add checking functions for matrices and vectors