blas/gonum: slice arguments to exact length
Also, avoid unnecessary use of ...To routines.
MODIFY
blas/gonum/dgemm.go
blas/gonum/dgemm.go
@@ -259,7 +259,7 @@ func dgemmSerialNotNot(m, n, k int, a []float64, lda int, b []float64, ldb int,
for l, v := range a[i*lda : i*lda+k] {
tmp := alpha * v
if tmp != 0 {
- f64.AxpyUnitaryTo(ctmp, tmp, b[l*ldb:l*ldb+n], ctmp)
+ f64.AxpyUnitary(tmp, b[l*ldb:l*ldb+n], ctmp)
}
}
}
@@ -275,7 +275,7 @@ func dgemmSerialTransNot(m, n, k int, a []float64, lda int, b []float64, ldb int
tmp := alpha * v
if tmp != 0 {
ctmp := c[i*ldc : i*ldc+n]
- f64.AxpyUnitaryTo(ctmp, tmp, btmp, ctmp)
+ f64.AxpyUnitary(tmp, btmp, ctmp)
}
}
}

MODIFY
blas/gonum/gemv.go
blas/gonum/gemv.go
@@ -29,7 +29,6 @@ func (Implementation) Dgemv(tA blas.Transpose, m, n int, alpha float64, a []floa
if lda < max(1, n) {
panic(badLdA)
}
-
if incX == 0 {
panic(zeroIncX)
}
@@ -43,18 +42,24 @@ func (Implementation) Dgemv(tA blas.Transpose, m, n int, alpha float64, a []floa
lenX = n
lenY = m
}
+
+ // Quick return if possible
+ if m == 0 || n == 0 {
+ return
+ }
+
if (incX > 0 && (lenX-1)*incX >= len(x)) || (incX < 0 && (1-lenX)*incX >= len(x)) {
panic(shortX)
}
if (incY > 0 && (lenY-1)*incY >= len(y)) || (incY < 0 && (1-lenY)*incY >= len(y)) {
panic(shortY)
}
- if lda*(m-1)+n > len(a) || lda < max(1, n) {
- panic(badLdA)
+ if len(a) < lda*(m-1)+n {
+ panic(shortA)
}
// Quick return if possible
- if m == 0 || n == 0 || (alpha == 0 && beta == 1) {
+ if alpha == 0 && beta == 1 {
return
}
@@ -96,13 +101,18 @@ func (Implementation) Sgemv(tA blas.Transpose, m, n int, alpha float32, a []floa
if lda < max(1, n) {
panic(badLdA)
}
-
if incX == 0 {
panic(zeroIncX)
}
if incY == 0 {
panic(zeroIncY)
}
+
+ // Quick return if possible.
+ if m == 0 || n == 0 {
+ return
+ }
+
// Set up indexes
lenX := m
lenY := n
@@ -116,23 +126,15 @@ func (Implementation) Sgemv(tA blas.Transpose, m, n int, alpha float32, a []floa
if (incY > 0 && (lenY-1)*incY >= len(y)) || (incY < 0 && (1-lenY)*incY >= len(y)) {
panic(shortY)
}
- if lda*(m-1)+n > len(a) || lda < max(1, n) {
- panic(badLdA)
+ if len(a) < lda*(m-1)+n {
+ panic(shortA)
}
- // Quick return if possible
- if m == 0 || n == 0 || (alpha == 0 && beta == 1) {
+ // Quick return if possible.
+ if alpha == 0 && beta == 1 {
return
}
- var kx, ky int
- if incX < 0 {
- kx = -(lenX - 1) * incX
- }
- if incY < 0 {
- ky = -(lenY - 1) * incY
- }
-
// First form y = beta * y
if incY > 0 {
Implementation{}.Sscal(lenY, beta, y, incY)
@@ -144,11 +146,19 @@ func (Implementation) Sgemv(tA blas.Transpose, m, n int, alpha float32, a []floa
return
}
+ var kx, ky int
+ if incX < 0 {
+ kx = -(lenX - 1) * incX
+ }
+ if incY < 0 {
+ ky = -(lenY - 1) * incY
+ }
+
// Form y = alpha * A * x + y
if tA == blas.NoTrans {
if incX == 1 && incY == 1 {
for i := 0; i < m; i++ {
- y[i] += alpha * f32.DotUnitary(a[lda*i:lda*i+n], x)
+ y[i] += alpha * f32.DotUnitary(a[lda*i:lda*i+n], x[:n])
}
return
}
@@ -164,7 +174,7 @@ func (Implementation) Sgemv(tA blas.Transpose, m, n int, alpha float32, a []floa
for i := 0; i < m; i++ {
tmp := alpha * x[i]
if tmp != 0 {
- f32.AxpyUnitaryTo(y, tmp, a[lda*i:lda*i+n], y)
+ f32.AxpyUnitaryTo(y, tmp, a[lda*i:lda*i+n], y[:n])
}
}
return

MODIFY
blas/gonum/level1double_ddot.go
blas/gonum/level1double_ddot.go
@@ -30,7 +30,7 @@ func (Implementation) Ddot(n int, x []float64, incX int, y []float64, incY int)
if len(y) < n {
panic(shortY)
}
- return f64.DotUnitary(x[:n], y)
+ return f64.DotUnitary(x[:n], y[:n])
}
var ix, iy int
if incX < 0 {

MODIFY
blas/gonum/level1single_dsdot.go
blas/gonum/level1single_dsdot.go
@@ -34,7 +34,7 @@ func (Implementation) Dsdot(n int, x []float32, incX int, y []float32, incY int)
if len(y) < n {
panic(shortY)
}
- return f32.DdotUnitary(x[:n], y)
+ return f32.DdotUnitary(x[:n], y[:n])
}
var ix, iy int
if incX < 0 {

MODIFY
blas/gonum/level1single_sdot.go
blas/gonum/level1single_sdot.go
@@ -34,7 +34,7 @@ func (Implementation) Sdot(n int, x []float32, incX int, y []float32, incY int)
if len(y) < n {
panic(shortY)
}
- return f32.DotUnitary(x[:n], y)
+ return f32.DotUnitary(x[:n], y[:n])
}
var ix, iy int
if incX < 0 {

MODIFY
blas/gonum/level1single_sdsdot.go
blas/gonum/level1single_sdsdot.go
@@ -34,7 +34,7 @@ func (Implementation) Sdsdot(n int, alpha float32, x []float32, incX int, y []fl
if len(y) < n {
panic(shortY)
}
- return alpha + float32(f32.DdotUnitary(x[:n], y))
+ return alpha + float32(f32.DdotUnitary(x[:n], y[:n]))
}
var ix, iy int
if incX < 0 {

MODIFY
blas/gonum/level2cmplx128.go
blas/gonum/level2cmplx128.go
@@ -2334,7 +2334,7 @@ func (Implementation) Ztpsv(uplo blas.Uplo, trans blas.Transpose, diag blas.Diag
if incX == 1 {
for i := 0; i < n; i++ {
if i > 0 {
- x[i] -= c128.DotuUnitary(x[:i], ap[kk:kk+i+1])
+ x[i] -= c128.DotuUnitary(x[:i], ap[kk:kk+i])
}
if diag == blas.NonUnit {
x[i] /= ap[kk+i]
@@ -2345,7 +2345,7 @@ func (Implementation) Ztpsv(uplo blas.Uplo, trans blas.Transpose, diag blas.Diag
ix := kx
for i := 0; i < n; i++ {
if i > 0 {
- x[ix] -= c128.DotuInc(x, ap[kk:kk+i+1], uintptr(i), uintptr(incX), 1, uintptr(kx), 0)
+ x[ix] -= c128.DotuInc(x, ap[kk:kk+i], uintptr(i), uintptr(incX), 1, uintptr(kx), 0)
}
if diag == blas.NonUnit {
x[ix] /= ap[kk+i]

MODIFY
blas/gonum/level2double.go
blas/gonum/level2double.go
@@ -262,8 +262,7 @@ func (Implementation) Dtrmv(ul blas.Uplo, tA blas.Transpose, d blas.Diag, n int,
} else {
tmp = x[i]
}
- xtmp := x[i+1:]
- x[i] = tmp + f64.DotUnitary(a[ilda+i+1:ilda+n], xtmp)
+ x[i] = tmp + f64.DotUnitary(a[ilda+i+1:ilda+n], x[i+1:n])
}
return
}
@@ -290,7 +289,7 @@ func (Implementation) Dtrmv(ul blas.Uplo, tA blas.Transpose, d blas.Diag, n int,
} else {
tmp = x[i]
}
- x[i] = tmp + f64.DotUnitary(a[ilda:ilda+i], x)
+ x[i] = tmp + f64.DotUnitary(a[ilda:ilda+i], x[:i])
}
return
}
@@ -337,7 +336,7 @@ func (Implementation) Dtrmv(ul blas.Uplo, tA blas.Transpose, d blas.Diag, n int,
for i := 0; i < n; i++ {
ilda := i * lda
xi := x[i]
- f64.AxpyUnitary(xi, a[ilda:ilda+i], x)
+ f64.AxpyUnitary(xi, a[ilda:ilda+i], x[:i])
if nonUnit {
x[i] *= a[i*lda+i]
}

MODIFY
blas/gonum/level2single.go
blas/gonum/level2single.go
@@ -270,8 +270,7 @@ func (Implementation) Strmv(ul blas.Uplo, tA blas.Transpose, d blas.Diag, n int,
} else {
tmp = x[i]
}
- xtmp := x[i+1:]
- x[i] = tmp + f32.DotUnitary(a[ilda+i+1:ilda+n], xtmp)
+ x[i] = tmp + f32.DotUnitary(a[ilda+i+1:ilda+n], x[i+1:n])
}
return
}
@@ -298,7 +297,7 @@ func (Implementation) Strmv(ul blas.Uplo, tA blas.Transpose, d blas.Diag, n int,
} else {
tmp = x[i]
}
- x[i] = tmp + f32.DotUnitary(a[ilda:ilda+i], x)
+ x[i] = tmp + f32.DotUnitary(a[ilda:ilda+i], x[:i])
}
return
}
@@ -345,7 +344,7 @@ func (Implementation) Strmv(ul blas.Uplo, tA blas.Transpose, d blas.Diag, n int,
for i := 0; i < n; i++ {
ilda := i * lda
xi := x[i]
- f32.AxpyUnitary(xi, a[ilda:ilda+i], x)
+ f32.AxpyUnitary(xi, a[ilda:ilda+i], x[:i])
if nonUnit {
x[i] *= a[i*lda+i]
}

MODIFY
blas/gonum/level3cmplx128.go
blas/gonum/level3cmplx128.go
@@ -341,20 +341,20 @@ func (Implementation) Zhemm(side blas.Side, uplo blas.Uplo, m, n int, alpha comp
if uplo == blas.Upper {
for k := 0; k < i; k++ {
atmp = alpha * cmplx.Conj(a[k*lda+i])
- c128.AxpyUnitaryTo(ci, atmp, b[k*ldb:k*ldb+n], ci)
+ c128.AxpyUnitary(atmp, b[k*ldb:k*ldb+n], ci)
}
for k := i + 1; k < m; k++ {
atmp = alpha * a[i*lda+k]
- c128.AxpyUnitaryTo(ci, atmp, b[k*ldb:k*ldb+n], ci)
+ c128.AxpyUnitary(atmp, b[k*ldb:k*ldb+n], ci)
}
} else {
for k := 0; k < i; k++ {
atmp = alpha * a[i*lda+k]
- c128.AxpyUnitaryTo(ci, atmp, b[k*ldb:k*ldb+n], ci)
+ c128.AxpyUnitary(atmp, b[k*ldb:k*ldb+n], ci)
}
for k := i + 1; k < m; k++ {
atmp = alpha * cmplx.Conj(a[k*lda+i])
- c128.AxpyUnitaryTo(ci, atmp, b[k*ldb:k*ldb+n], ci)
+ c128.AxpyUnitary(atmp, b[k*ldb:k*ldb+n], ci)
}
}
}
@@ -881,20 +881,20 @@ func (Implementation) Zsymm(side blas.Side, uplo blas.Uplo, m, n int, alpha comp
if uplo == blas.Upper {
for k := 0; k < i; k++ {
atmp = alpha * a[k*lda+i]
- c128.AxpyUnitaryTo(ci, atmp, b[k*ldb:k*ldb+n], ci)
+ c128.AxpyUnitary(atmp, b[k*ldb:k*ldb+n], ci)
}
for k := i + 1; k < m; k++ {
atmp = alpha * a[i*lda+k]
- c128.AxpyUnitaryTo(ci, atmp, b[k*ldb:k*ldb+n], ci)
+ c128.AxpyUnitary(atmp, b[k*ldb:k*ldb+n], ci)
}
} else {
for k := 0; k < i; k++ {
atmp = alpha * a[i*lda+k]
- c128.AxpyUnitaryTo(ci, atmp, b[k*ldb:k*ldb+n], ci)
+ c128.AxpyUnitary(atmp, b[k*ldb:k*ldb+n], ci)
}
for k := i + 1; k < m; k++ {
atmp = alpha * a[k*lda+i]
- c128.AxpyUnitaryTo(ci, atmp, b[k*ldb:k*ldb+n], ci)
+ c128.AxpyUnitary(atmp, b[k*ldb:k*ldb+n], ci)
}
}
}
@@ -1440,7 +1440,7 @@ func (Implementation) Ztrmm(side blas.Side, uplo blas.Uplo, trans blas.Transpose
if noUnit {
bi[k] *= a[k*lda+k]
}
- c128.AxpyUnitary(abik, a[k*lda:k*lda+k], bi)
+ c128.AxpyUnitary(abik, a[k*lda:k*lda+k], bi[:k])
}
}
}
@@ -1696,12 +1696,12 @@ func (Implementation) Ztrsm(side blas.Side, uplo blas.Uplo, transA blas.Transpos
for j, bij := range bi {
bij *= alpha
if noConj {
- bij -= c128.DotuUnitary(a[j*lda:j*lda+j], bi)
+ bij -= c128.DotuUnitary(a[j*lda:j*lda+j], bi[:j])
if noUnit {
bij /= a[j*lda+j]
}
} else {
- bij -= c128.DotcUnitary(a[j*lda:j*lda+j], bi)
+ bij -= c128.DotcUnitary(a[j*lda:j*lda+j], bi[:j])
if noUnit {
bij /= cmplx.Conj(a[j*lda+j])
}

MODIFY
blas/gonum/level3double.go
blas/gonum/level3double.go
@@ -104,7 +104,7 @@ func (Implementation) Dtrsm(s blas.Side, ul blas.Uplo, tA blas.Transpose, d blas
}
for k, va := range a[i*lda : i*lda+i] {
if va != 0 {
- f64.AxpyUnitaryTo(btmp, -va, b[k*ldb:k*ldb+n], btmp)
+ f64.AxpyUnitary(-va, b[k*ldb:k*ldb+n], btmp)
}
}
if nonUnit {
@@ -183,7 +183,7 @@ func (Implementation) Dtrsm(s blas.Side, ul blas.Uplo, tA blas.Transpose, d blas
if nonUnit {
btmp[k] /= a[k*lda+k]
}
- f64.AxpyUnitary(-btmp[k], a[k*lda:k*lda+k], btmp)
+ f64.AxpyUnitary(-btmp[k], a[k*lda:k*lda+k], btmp[:k])
}
}
return
@@ -205,7 +205,7 @@ func (Implementation) Dtrsm(s blas.Side, ul blas.Uplo, tA blas.Transpose, d blas
for i := 0; i < m; i++ {
btmp := b[i*ldb : i*ldb+n]
for j := 0; j < n; j++ {
- tmp := alpha*btmp[j] - f64.DotUnitary(a[j*lda:j*lda+j], btmp)
+ tmp := alpha*btmp[j] - f64.DotUnitary(a[j*lda:j*lda+j], btmp[:j])
if nonUnit {
tmp /= a[j*lda+j]
}
@@ -305,7 +305,7 @@ func (Implementation) Dsymm(s blas.Side, ul blas.Uplo, m, n int, alpha float64,
atmp = a[i*lda+k]
}
atmp *= alpha
- f64.AxpyUnitaryTo(ctmp, atmp, b[k*ldb:k*ldb+n], ctmp)
+ f64.AxpyUnitary(atmp, b[k*ldb:k*ldb+n], ctmp)
}
for k := i + 1; k < m; k++ {
var atmp float64
@@ -315,7 +315,7 @@ func (Implementation) Dsymm(s blas.Side, ul blas.Uplo, m, n int, alpha float64,
atmp = a[k*lda+i]
}
atmp *= alpha
- f64.AxpyUnitaryTo(ctmp, atmp, b[k*ldb:k*ldb+n], ctmp)
+ f64.AxpyUnitary(atmp, b[k*ldb:k*ldb+n], ctmp)
}
}
return
@@ -483,7 +483,7 @@ func (Implementation) Dsyrk(ul blas.Uplo, tA blas.Transpose, n, k int, alpha flo
for l := 0; l < k; l++ {
tmp := alpha * a[l*lda+i]
if tmp != 0 {
- f64.AxpyUnitaryTo(ctmp, tmp, a[l*lda+i:l*lda+n], ctmp)
+ f64.AxpyUnitary(tmp, a[l*lda+i:l*lda+n], ctmp)
}
}
}
@@ -499,7 +499,7 @@ func (Implementation) Dsyrk(ul blas.Uplo, tA blas.Transpose, n, k int, alpha flo
for l := 0; l < k; l++ {
tmp := alpha * a[l*lda+i]
if tmp != 0 {
- f64.AxpyUnitaryTo(ctmp, tmp, a[l*lda:l*lda+i+1], ctmp)
+ f64.AxpyUnitary(tmp, a[l*lda:l*lda+i+1], ctmp)
}
}
}

MODIFY
blas/gonum/level3single.go
blas/gonum/level3single.go
@@ -108,7 +108,7 @@ func (Implementation) Strsm(s blas.Side, ul blas.Uplo, tA blas.Transpose, d blas
}
for k, va := range a[i*lda : i*lda+i] {
if va != 0 {
- f32.AxpyUnitaryTo(btmp, -va, b[k*ldb:k*ldb+n], btmp)
+ f32.AxpyUnitary(-va, b[k*ldb:k*ldb+n], btmp)
}
}
if nonUnit {
@@ -187,7 +187,7 @@ func (Implementation) Strsm(s blas.Side, ul blas.Uplo, tA blas.Transpose, d blas
if nonUnit {
btmp[k] /= a[k*lda+k]
}
- f32.AxpyUnitary(-btmp[k], a[k*lda:k*lda+k], btmp)
+ f32.AxpyUnitary(-btmp[k], a[k*lda:k*lda+k], btmp[:k])
}
}
return
@@ -209,7 +209,7 @@ func (Implementation) Strsm(s blas.Side, ul blas.Uplo, tA blas.Transpose, d blas
for i := 0; i < m; i++ {
btmp := b[i*ldb : i*ldb+n]
for j := 0; j < n; j++ {
- tmp := alpha*btmp[j] - f32.DotUnitary(a[j*lda:j*lda+j], btmp)
+ tmp := alpha*btmp[j] - f32.DotUnitary(a[j*lda:j*lda+j], btmp[:j])
if nonUnit {
tmp /= a[j*lda+j]
}
@@ -311,7 +311,7 @@ func (Implementation) Ssymm(s blas.Side, ul blas.Uplo, m, n int, alpha float32,
atmp = a[i*lda+k]
}
atmp *= alpha
- f32.AxpyUnitaryTo(ctmp, atmp, b[k*ldb:k*ldb+n], ctmp)
+ f32.AxpyUnitary(atmp, b[k*ldb:k*ldb+n], ctmp)
}
for k := i + 1; k < m; k++ {
var atmp float32
@@ -321,7 +321,7 @@ func (Implementation) Ssymm(s blas.Side, ul blas.Uplo, m, n int, alpha float32,
atmp = a[k*lda+i]
}
atmp *= alpha
- f32.AxpyUnitaryTo(ctmp, atmp, b[k*ldb:k*ldb+n], ctmp)
+ f32.AxpyUnitary(atmp, b[k*ldb:k*ldb+n], ctmp)
}
}
return
@@ -491,7 +491,7 @@ func (Implementation) Ssyrk(ul blas.Uplo, tA blas.Transpose, n, k int, alpha flo
for l := 0; l < k; l++ {
tmp := alpha * a[l*lda+i]
if tmp != 0 {
- f32.AxpyUnitaryTo(ctmp, tmp, a[l*lda+i:l*lda+n], ctmp)
+ f32.AxpyUnitary(tmp, a[l*lda+i:l*lda+n], ctmp)
}
}
}
@@ -507,7 +507,7 @@ func (Implementation) Ssyrk(ul blas.Uplo, tA blas.Transpose, n, k int, alpha flo
for l := 0; l < k; l++ {
tmp := alpha * a[l*lda+i]
if tmp != 0 {
- f32.AxpyUnitaryTo(ctmp, tmp, a[l*lda:l*lda+i+1], ctmp)
+ f32.AxpyUnitary(tmp, a[l*lda:l*lda+i+1], ctmp)
}
}
}

MODIFY
blas/gonum/sgemm.go
blas/gonum/sgemm.go
@@ -263,7 +263,7 @@ func sgemmSerialNotNot(m, n, k int, a []float32, lda int, b []float32, ldb int,
for l, v := range a[i*lda : i*lda+k] {
tmp := alpha * v
if tmp != 0 {
- f32.AxpyUnitaryTo(ctmp, tmp, b[l*ldb:l*ldb+n], ctmp)
+ f32.AxpyUnitary(tmp, b[l*ldb:l*ldb+n], ctmp)
}
}
}
@@ -279,7 +279,7 @@ func sgemmSerialTransNot(m, n, k int, a []float32, lda int, b []float32, ldb int
tmp := alpha * v
if tmp != 0 {
ctmp := c[i*ldc : i*ldc+n]
- f32.AxpyUnitaryTo(ctmp, tmp, btmp, ctmp)
+ f32.AxpyUnitary(tmp, btmp, ctmp)
}
}
}

MODIFY
blas/gonum/single_precision.bash
blas/gonum/single_precision.bash
@@ -19,9 +19,7 @@ cat level1double.go \
| gofmt -r 'blas.DrotmParams -> blas.SrotmParams' \
\
| gofmt -r 'f64.AxpyInc -> f32.AxpyInc' \
-| gofmt -r 'f64.AxpyIncTo -> f32.AxpyIncTo' \
| gofmt -r 'f64.AxpyUnitary -> f32.AxpyUnitary' \
-| gofmt -r 'f64.AxpyUnitaryTo -> f32.AxpyUnitaryTo' \
| gofmt -r 'f64.DotUnitary -> f32.DotUnitary' \
| gofmt -r 'f64.ScalInc -> f32.ScalInc' \
| gofmt -r 'f64.ScalUnitary -> f32.ScalUnitary' \
@@ -135,8 +133,7 @@ cat dgemm.go \
| gofmt -r 'dgemmSerialTransTrans -> sgemmSerialTransTrans' \
\
| gofmt -r 'f64.AxpyInc -> f32.AxpyInc' \
-| gofmt -r 'f64.AxpyIncTo -> f32.AxpyIncTo' \
-| gofmt -r 'f64.AxpyUnitaryTo -> f32.AxpyUnitaryTo' \
+| gofmt -r 'f64.AxpyUnitary -> f32.AxpyUnitary' \
| gofmt -r 'f64.DotUnitary -> f32.DotUnitary' \
\
| sed -e "s_^\(func (Implementation) \)D\(.*\)\$_$WARNING\1S\2_" \

blas/gonum: slice arguments to exact length

Also, avoid unnecessary use of ...To routines.