mat: use single panic string for bad capacity
MODIFY
mat/cdense.go
mat/cdense.go
@@ -93,7 +93,7 @@ func (m *CDense) ReuseAs(r, c int) {
func (m *CDense) reuseAsNonZeroed(r, c int) {
if m.mat.Rows > m.capRows || m.mat.Cols > m.capCols {
// Panic as a string, not a mat.Error.
- panic("mat: caps not correctly set")
+ panic(badCap)
}
if r == 0 || c == 0 {
panic(ErrZeroLength)
@@ -118,7 +118,7 @@ func (m *CDense) reuseAsZeroed(r, c int) {
// This must be kept in-sync with reuseAs.
if m.mat.Rows > m.capRows || m.mat.Cols > m.capCols {
// Panic as a string, not a mat.Error.
- panic("mat: caps not correctly set")
+ panic(badCap)
}
if r == 0 || c == 0 {
panic(ErrZeroLength)

MODIFY
mat/dense.go
mat/dense.go
@@ -97,7 +97,7 @@ func (m *Dense) reuseAsNonZeroed(r, c int) {
// reuseAs must be kept in sync with reuseAsZeroed.
if m.mat.Rows > m.capRows || m.mat.Cols > m.capCols {
// Panic as a string, not a mat.Error.
- panic("mat: caps not correctly set")
+ panic(badCap)
}
if r == 0 || c == 0 {
panic(ErrZeroLength)
@@ -125,7 +125,7 @@ func (m *Dense) reuseAsZeroed(r, c int) {
// reuseAsZeroed must be kept in sync with reuseAsNonZeroed.
if m.mat.Rows > m.capRows || m.mat.Cols > m.capCols {
// Panic as a string, not a mat.Error.
- panic("mat: caps not correctly set")
+ panic(badCap)
}
if r == 0 || c == 0 {
panic(ErrZeroLength)

MODIFY
mat/errors.go
mat/errors.go
@@ -131,6 +131,7 @@ var (
ErrPivot = Error{"mat: malformed pivot list"}
ErrTriangle = Error{"mat: triangular storage mismatch"}
ErrTriangleSet = Error{"mat: triangular set out of bounds"}
+ ErrBandwidth = Error{"mat: bandwidth out of range"}
ErrBandSet = Error{"mat: band set out of bounds"}
ErrDiagSet = Error{"mat: diagonal set out of bounds"}
ErrSliceLengthMismatch = Error{"mat: input slice length mismatch"}
@@ -149,3 +150,5 @@ type ErrorStack struct {
}
func (err ErrorStack) Error() string { return err.Err.Error() }
+
+const badCap = "mat: bad capacity"

MODIFY
mat/symmetric.go
mat/symmetric.go
@@ -22,10 +22,7 @@ var (
_ MutableSymmetric = symDense
)
-const (
- badSymTriangle = "mat: blas64.Symmetric not upper"
- badSymCap = "mat: bad capacity for SymDense"
-)
+const badSymTriangle = "mat: blas64.Symmetric not upper"
// SymDense is a symmetric matrix that uses dense storage. SymDense
// matrices are stored in the upper triangle.
@@ -182,7 +179,8 @@ func (s *SymDense) reuseAsNonZeroed(n int) {
panic(ErrZeroLength)
}
if s.mat.N > s.cap {
- panic(badSymCap)
+ // Panic as a string, not a mat.Error.
+ panic(badCap)
}
if s.IsEmpty() {
s.mat = blas64.Symmetric{
@@ -211,7 +209,8 @@ func (s *SymDense) reuseAsZeroed(n int) {
panic(ErrZeroLength)
}
if s.mat.N > s.cap {
- panic(badSymCap)
+ // Panic as a string, not a mat.Error.
+ panic(badCap)
}
if s.IsEmpty() {
s.mat = blas64.Symmetric{

MODIFY
mat/triband.go
mat/triband.go
@@ -201,10 +201,10 @@ func NewTriBandDense(n, k int, kind TriKind, data []float64) *TriBandDense {
if n == 0 {
panic(ErrZeroLength)
}
- panic("mat: negative dimension")
+ panic(ErrNegativeDimension)
}
if k+1 > n {
- panic("mat: band out of range")
+ panic(ErrBandwidth)
}
bc := k + 1
if data != nil && len(data) != n*bc {

mat: use single panic string for bad capacity