blas/gonum: panic with more informative messages
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(k, m, a, lda)
+ checkMatrix64('a', k, m, a, lda)
} else {
- checkMatrix64(m, k, a, lda)
+ checkMatrix64('a', m, k, a, lda)
}
bTrans := tB == blas.Trans || tB == blas.ConjTrans
if bTrans {
- checkMatrix64(n, k, b, ldb)
+ checkMatrix64('b', n, k, b, ldb)
} else {
- checkMatrix64(k, n, b, ldb)
+ checkMatrix64('b', k, n, b, ldb)
}
- checkMatrix64(m, n, c, ldc)
+ checkMatrix64('c', m, n, c, ldc)
// scale c
if beta != 1 {
@@ -260,7 +260,7 @@ func sliceView64(a []float64, lda, i, j, r, c int) []float64 {
return a[i*lda+j : (i+r-1)*lda+j+c]
}
-func checkMatrix64(m, n int, a []float64, lda int) {
+func checkMatrix64(name byte, m, n int, a []float64, lda int) {
if m < 0 {
panic("blas: rows < 0")
}
@@ -271,6 +271,6 @@ func checkMatrix64(m, n int, a []float64, lda int) {
panic("blas: illegal stride")
}
if len(a) < (m-1)*lda+n {
- panic("blas: insufficient matrix slice length")
+ panic("blas: index of " + string(name) + " out of range")
}
}

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(k, m, a, lda)
+ checkMatrix32('a', k, m, a, lda)
} else {
- checkMatrix32(m, k, a, lda)
+ checkMatrix32('a', m, k, a, lda)
}
bTrans := tB == blas.Trans || tB == blas.ConjTrans
if bTrans {
- checkMatrix32(n, k, b, ldb)
+ checkMatrix32('b', n, k, b, ldb)
} else {
- checkMatrix32(k, n, b, ldb)
+ checkMatrix32('b', k, n, b, ldb)
}
- checkMatrix32(m, n, c, ldc)
+ checkMatrix32('c', m, n, c, ldc)
// scale c
if beta != 1 {
@@ -125,7 +125,7 @@ func sgemmParallel(aTrans, bTrans bool, m, n, k int, a []float32, lda int, b []f
go func() {
defer wg.Done()
// Make local copies of otherwise global variables to reduce shared memory.
- // This has a noticable effect on benchmarks in some cases.
+ // This has a noticeable effect on benchmarks in some cases.
alpha := alpha
aTrans := aTrans
bTrans := bTrans
@@ -264,7 +264,7 @@ func sliceView32(a []float32, lda, i, j, r, c int) []float32 {
return a[i*lda+j : (i+r-1)*lda+j+c]
}
-func checkMatrix32(m, n int, a []float32, lda int) {
+func checkMatrix32(name byte, m, n int, a []float32, lda int) {
if m < 0 {
panic("blas: rows < 0")
}
@@ -275,6 +275,6 @@ func checkMatrix32(m, n int, a []float32, lda int) {
panic("blas: illegal stride")
}
if len(a) < (m-1)*lda+n {
- panic("blas: insufficient matrix slice length")
+ panic("blas: index of " + string(name) + " out of range")
}
}

MODIFY
mat/dense_test.go
mat/dense_test.go
@@ -830,7 +830,7 @@ func TestMul(t *testing.T) {
// These probably warrant a better check and failure. They should never happen in the wild though.
temp.mat.Data = nil
panicked, message := panics(func() { temp.Mul(a, b) })
- if !panicked || message != "blas: insufficient matrix slice length" {
+ if !panicked || message != "blas: index of c out of range" {
if message != "" {
t.Errorf("expected runtime panic for nil data slice: got %q", message)
} else {

blas/gonum: panic with more informative messages