Skip to content

Commit

Permalink
blas/gonum: rename, add and use panic strings
Browse files Browse the repository at this point in the history
  • Loading branch information
vladimir-ch committed Nov 11, 2018
1 parent 48288cc commit 3063fbf
Show file tree
Hide file tree
Showing 14 changed files with 130 additions and 125 deletions.
9 changes: 7 additions & 2 deletions blas/gonum/errors.go
Expand Up @@ -20,11 +20,16 @@ const (
badTranspose = "blas: illegal transpose"
badDiag = "blas: illegal diagonal"
badSide = "blas: illegal side"
badFlag = "blas: illegal rotm flag"

badLdA = "blas: bad leading dimension of A"
badLdB = "blas: bad leading dimension of B"
badLdC = "blas: bad leading dimension of C"

badX = "blas: bad length of x"
badY = "blas: bad length of y"
shortX = "blas: insufficient length of x"
shortY = "blas: insufficient length of y"
shortAP = "blas: insufficient length of ap"
shortA = "blas: insufficient length of a"
shortB = "blas: insufficient length of b"
shortC = "blas: insufficient length of c"
)
8 changes: 4 additions & 4 deletions blas/gonum/gemv.go
Expand Up @@ -44,10 +44,10 @@ func (Implementation) Dgemv(tA blas.Transpose, m, n int, alpha float64, a []floa
lenY = m
}
if (incX > 0 && (lenX-1)*incX >= len(x)) || (incX < 0 && (1-lenX)*incX >= len(x)) {
panic(badX)
panic(shortX)
}
if (incY > 0 && (lenY-1)*incY >= len(y)) || (incY < 0 && (1-lenY)*incY >= len(y)) {
panic(badY)
panic(shortY)
}
if lda*(m-1)+n > len(a) || lda < max(1, n) {
panic(badLdA)
Expand Down Expand Up @@ -111,10 +111,10 @@ func (Implementation) Sgemv(tA blas.Transpose, m, n int, alpha float32, a []floa
lenY = m
}
if (incX > 0 && (lenX-1)*incX >= len(x)) || (incX < 0 && (1-lenX)*incX >= len(x)) {
panic(badX)
panic(shortX)
}
if (incY > 0 && (lenY-1)*incY >= len(y)) || (incY < 0 && (1-lenY)*incY >= len(y)) {
panic(badY)
panic(shortY)
}
if lda*(m-1)+n > len(a) || lda < max(1, n) {
panic(badLdA)
Expand Down
40 changes: 20 additions & 20 deletions blas/gonum/level1cmplx128.go
Expand Up @@ -26,15 +26,15 @@ func (Implementation) Dzasum(n int, x []complex128, incX int) float64 {
var sum float64
if incX == 1 {
if len(x) < n {
panic(badX)
panic(shortX)
}
for _, v := range x[:n] {
sum += dcabs1(v)
}
return sum
}
if (n-1)*incX >= len(x) {
panic(badX)
panic(shortX)
}
for i := 0; i < n; i++ {
v := x[i*incX]
Expand All @@ -60,7 +60,7 @@ func (Implementation) Dznrm2(n int, x []complex128, incX int) float64 {
panic(nLT0)
}
if (n-1)*incX >= len(x) {
panic(badX)
panic(shortX)
}
var (
scale float64
Expand Down Expand Up @@ -134,7 +134,7 @@ func (Implementation) Izamax(n int, x []complex128, incX int) int {
panic(nLT0)
}
if len(x) <= (n-1)*incX {
panic(badX)
panic(shortX)
}
idx := 0
max := dcabs1(x[0])
Expand Down Expand Up @@ -176,10 +176,10 @@ func (Implementation) Zaxpy(n int, alpha complex128, x []complex128, incX int, y
panic(nLT0)
}
if (incX > 0 && (n-1)*incX >= len(x)) || (incX < 0 && (1-n)*incX >= len(x)) {
panic(badX)
panic(shortX)
}
if (incY > 0 && (n-1)*incY >= len(y)) || (incY < 0 && (1-n)*incY >= len(y)) {
panic(badY)
panic(shortY)
}
if alpha == 0 {
return
Expand Down Expand Up @@ -213,10 +213,10 @@ func (Implementation) Zcopy(n int, x []complex128, incX int, y []complex128, inc
panic(nLT0)
}
if (incX > 0 && (n-1)*incX >= len(x)) || (incX < 0 && (1-n)*incX >= len(x)) {
panic(badX)
panic(shortX)
}
if (incY > 0 && (n-1)*incY >= len(y)) || (incY < 0 && (1-n)*incY >= len(y)) {
panic(badY)
panic(shortY)
}
if incX == 1 && incY == 1 {
copy(y[:n], x[:n])
Expand Down Expand Up @@ -254,10 +254,10 @@ func (Implementation) Zdotc(n int, x []complex128, incX int, y []complex128, inc
}
if incX == 1 && incY == 1 {
if len(x) < n {
panic(badX)
panic(shortX)
}
if len(y) < n {
panic(badY)
panic(shortY)
}
return c128.DotcUnitary(x[:n], y[:n])
}
Expand All @@ -269,10 +269,10 @@ func (Implementation) Zdotc(n int, x []complex128, incX int, y []complex128, inc
iy = (-n + 1) * incY
}
if ix >= len(x) || (n-1)*incX >= len(x) {
panic(badX)
panic(shortX)
}
if iy >= len(y) || (n-1)*incY >= len(y) {
panic(badY)
panic(shortY)
}
return c128.DotcInc(x, y, uintptr(n), uintptr(incX), uintptr(incY), uintptr(ix), uintptr(iy))
}
Expand All @@ -295,10 +295,10 @@ func (Implementation) Zdotu(n int, x []complex128, incX int, y []complex128, inc
}
if incX == 1 && incY == 1 {
if len(x) < n {
panic(badX)
panic(shortX)
}
if len(y) < n {
panic(badY)
panic(shortY)
}
return c128.DotuUnitary(x[:n], y[:n])
}
Expand All @@ -310,10 +310,10 @@ func (Implementation) Zdotu(n int, x []complex128, incX int, y []complex128, inc
iy = (-n + 1) * incY
}
if ix >= len(x) || (n-1)*incX >= len(x) {
panic(badX)
panic(shortX)
}
if iy >= len(y) || (n-1)*incY >= len(y) {
panic(badY)
panic(shortY)
}
return c128.DotuInc(x, y, uintptr(n), uintptr(incX), uintptr(incY), uintptr(ix), uintptr(iy))
}
Expand All @@ -328,7 +328,7 @@ func (Implementation) Zdscal(n int, alpha float64, x []complex128, incX int) {
return
}
if (n-1)*incX >= len(x) {
panic(badX)
panic(shortX)
}
if n < 1 {
if n == 0 {
Expand Down Expand Up @@ -372,7 +372,7 @@ func (Implementation) Zscal(n int, alpha complex128, x []complex128, incX int) {
return
}
if (n-1)*incX >= len(x) {
panic(badX)
panic(shortX)
}
if n < 1 {
if n == 0 {
Expand Down Expand Up @@ -415,10 +415,10 @@ func (Implementation) Zswap(n int, x []complex128, incX int, y []complex128, inc
panic(nLT0)
}
if (incX > 0 && (n-1)*incX >= len(x)) || (incX < 0 && (1-n)*incX >= len(x)) {
panic(badX)
panic(shortX)
}
if (incY > 0 && (n-1)*incY >= len(y)) || (incY < 0 && (1-n)*incY >= len(y)) {
panic(badY)
panic(shortY)
}
if incX == 1 && incY == 1 {
x = x[:n]
Expand Down
30 changes: 15 additions & 15 deletions blas/gonum/level1double.go
Expand Up @@ -24,7 +24,7 @@ func (Implementation) Dnrm2(n int, x []float64, incX int) float64 {
return 0
}
if incX > 0 && (n-1)*incX >= len(x) {
panic(badX)
panic(shortX)
}
if n < 2 {
if n == 1 {
Expand Down Expand Up @@ -98,7 +98,7 @@ func (Implementation) Dasum(n int, x []float64, incX int) float64 {
return 0
}
if incX > 0 && (n-1)*incX >= len(x) {
panic(badX)
panic(shortX)
}
if incX == 1 {
x = x[:n]
Expand All @@ -124,7 +124,7 @@ func (Implementation) Idamax(n int, x []float64, incX int) int {
return -1
}
if incX > 0 && (n-1)*incX >= len(x) {
panic(badX)
panic(shortX)
}
if n < 2 {
if n == 1 {
Expand Down Expand Up @@ -176,10 +176,10 @@ func (Implementation) Dswap(n int, x []float64, incX int, y []float64, incY int)
panic(nLT0)
}
if (incX > 0 && (n-1)*incX >= len(x)) || (incX < 0 && (1-n)*incX >= len(x)) {
panic(badX)
panic(shortX)
}
if (incY > 0 && (n-1)*incY >= len(y)) || (incY < 0 && (1-n)*incY >= len(y)) {
panic(badY)
panic(shortY)
}
if incX == 1 && incY == 1 {
x = x[:n]
Expand Down Expand Up @@ -218,10 +218,10 @@ func (Implementation) Dcopy(n int, x []float64, incX int, y []float64, incY int)
panic(nLT0)
}
if (incX > 0 && (n-1)*incX >= len(x)) || (incX < 0 && (1-n)*incX >= len(x)) {
panic(badX)
panic(shortX)
}
if (incY > 0 && (n-1)*incY >= len(y)) || (incY < 0 && (1-n)*incY >= len(y)) {
panic(badY)
panic(shortY)
}
if incX == 1 && incY == 1 {
copy(y[:n], x[:n])
Expand Down Expand Up @@ -257,10 +257,10 @@ func (Implementation) Daxpy(n int, alpha float64, x []float64, incX int, y []flo
panic(nLT0)
}
if (incX > 0 && (n-1)*incX >= len(x)) || (incX < 0 && (1-n)*incX >= len(x)) {
panic(badX)
panic(shortX)
}
if (incY > 0 && (n-1)*incY >= len(y)) || (incY < 0 && (1-n)*incY >= len(y)) {
panic(badY)
panic(shortY)
}
if alpha == 0 {
return
Expand Down Expand Up @@ -422,7 +422,7 @@ func (Implementation) Drotmg(d1, d2, x1, y1 float64) (p blas.DrotmParams, rd1, r
case blas.Rescaling:
p.H = [4]float64{h11, h21, h12, h22}
default:
panic("blas: unexpected blas.Flag")
panic(badFlag)
}

return p, d1, d2, x1
Expand All @@ -445,10 +445,10 @@ func (Implementation) Drot(n int, x []float64, incX int, y []float64, incY int,
panic(nLT0)
}
if (incX > 0 && (n-1)*incX >= len(x)) || (incX < 0 && (1-n)*incX >= len(x)) {
panic(badX)
panic(shortX)
}
if (incY > 0 && (n-1)*incY >= len(y)) || (incY < 0 && (1-n)*incY >= len(y)) {
panic(badY)
panic(shortY)
}
if incX == 1 && incY == 1 {
x = x[:n]
Expand Down Expand Up @@ -489,10 +489,10 @@ func (Implementation) Drotm(n int, x []float64, incX int, y []float64, incY int,
panic(nLT0)
}
if (incX > 0 && (n-1)*incX >= len(x)) || (incX < 0 && (1-n)*incX >= len(x)) {
panic(badX)
panic(shortX)
}
if (incY > 0 && (n-1)*incY >= len(y)) || (incY < 0 && (1-n)*incY >= len(y)) {
panic(badY)
panic(shortY)
}

if p.Flag == blas.Identity {
Expand Down Expand Up @@ -591,7 +591,7 @@ func (Implementation) Dscal(n int, alpha float64, x []float64, incX int) {
return
}
if (n-1)*incX >= len(x) {
panic(badX)
panic(shortX)
}
if n < 1 {
if n == 0 {
Expand Down
8 changes: 4 additions & 4 deletions blas/gonum/level1double_ddot.go
Expand Up @@ -25,10 +25,10 @@ func (Implementation) Ddot(n int, x []float64, incX int, y []float64, incY int)
}
if incX == 1 && incY == 1 {
if len(x) < n {
panic(badX)
panic(shortX)
}
if len(y) < n {
panic(badY)
panic(shortY)
}
return f64.DotUnitary(x[:n], y)
}
Expand All @@ -40,10 +40,10 @@ func (Implementation) Ddot(n int, x []float64, incX int, y []float64, incY int)
iy = (-n + 1) * incY
}
if ix >= len(x) || ix+(n-1)*incX >= len(x) {
panic(badX)
panic(shortX)
}
if iy >= len(y) || iy+(n-1)*incY >= len(y) {
panic(badY)
panic(shortY)
}
return f64.DotInc(x, y, uintptr(n), uintptr(incX), uintptr(incY), uintptr(ix), uintptr(iy))
}

0 comments on commit 3063fbf

Please sign in to comment.