blas/gonum:  Fix NaN popagation in Dger.
Fixes
Fix NaN popagation in Dger.  Remove unneeded temp variables in Dger.
Generate level2single with Dger changes.
MODIFY
blas/gonum/level2double.go
blas/gonum/level2double.go
@@ -167,21 +167,14 @@ func (Implementation) Dger(m, n int, alpha float64, x []float64, incX int, y []f
x = x[:m]
y = y[:n]
for i, xv := range x {
- tmp := alpha * xv
- if tmp != 0 {
- atmp := a[i*lda : i*lda+n]
- f64.AxpyUnitaryTo(atmp, tmp, y, atmp)
- }
+ f64.AxpyUnitary(alpha*xv, y, a[i*lda:i*lda+n])
}
return
}
ix := kx
for i := 0; i < m; i++ {
- tmp := alpha * x[ix]
- if tmp != 0 {
- f64.AxpyInc(tmp, y, a[i*lda:i*lda+n], uintptr(n), uintptr(incY), 1, uintptr(ky), 0)
- }
+ f64.AxpyInc(alpha*x[ix], y, a[i*lda:i*lda+n], uintptr(n), uintptr(incY), 1, uintptr(ky), 0)
ix += incX
}
}

MODIFY
blas/gonum/level2single.go
blas/gonum/level2single.go
@@ -173,21 +173,14 @@ func (Implementation) Sger(m, n int, alpha float32, x []float32, incX int, y []f
x = x[:m]
y = y[:n]
for i, xv := range x {
- tmp := alpha * xv
- if tmp != 0 {
- atmp := a[i*lda : i*lda+n]
- f32.AxpyUnitaryTo(atmp, tmp, y, atmp)
- }
+ f32.AxpyUnitary(alpha*xv, y, a[i*lda:i*lda+n])
}
return
}
ix := kx
for i := 0; i < m; i++ {
- tmp := alpha * x[ix]
- if tmp != 0 {
- f32.AxpyInc(tmp, y, a[i*lda:i*lda+n], uintptr(n), uintptr(incY), 1, uintptr(ky), 0)
- }
+ f32.AxpyInc(alpha*x[ix], y, a[i*lda:i*lda+n], uintptr(n), uintptr(incY), 1, uintptr(ky), 0)
ix += incX
}
}

MODIFY
blas/testblas/common.go
blas/testblas/common.go
@@ -69,7 +69,7 @@ func dSliceEqual(a, b []float64) bool {
return false
}
for i := range a {
- if !(a[i] == b[i]) {
+ if !dTolEqual(a[i], b[i]) {
return false
}
}

MODIFY
blas/testblas/dger.go
blas/testblas/dger.go
package testblas
-import "testing"
+import (
+ "math"
+ "testing"
+)
type Dgerer interface {
Dger(m, n int, alpha float64, x []float64, incX int, y []float64, incY int, a []float64, lda int)
@@ -114,6 +117,17 @@ func DgerTest(t *testing.T, blasser Dgerer) {
incY: 2,
trueAns: [][]float64{{3.5, 2.4, -34.5, -17.2, 19.55, -23}, {2.6, 2.8, 3.3, -3.4, 6.2, -8.7}, {-11.2, -4.3, 161.3, 95.9, -74.08, 71.9}},
},
+ {
+ name: "Y NaN element",
+ m: 1,
+ n: 1,
+ a: [][]float64{{1.3}},
+ x: []float64{1.3},
+ y: []float64{math.NaN()},
+ incX: 1,
+ incY: 1,
+ trueAns: [][]float64{{math.NaN()}},
+ },
} {
// TODO: Add tests where a is longer
// TODO: Add panic tests
@@ -148,15 +162,15 @@ func DgerTest(t *testing.T, blasser Dgerer) {
func dgercomp(t *testing.T, x, xCopy, y, yCopy []float64, ans [][]float64, trueAns [][]float64, name string) {
if !dSliceEqual(x, xCopy) {
- t.Errorf("case %v: x modified during call to dger", name)
+ t.Errorf("case %v: x modified during call to dger\n%v\n%v", name, x, xCopy)
}
if !dSliceEqual(y, yCopy) {
- t.Errorf("case %v: x modified during call to dger", name)
+ t.Errorf("case %v: y modified during call to dger\n%v\n%v", name, y, yCopy)
}
for i := range ans {
if !dSliceTolEqual(ans[i], trueAns[i]) {
- t.Errorf("case %v: answer mismatch. Expected %v, Found %v", name, trueAns, ans)
+ t.Errorf("case %v: answer mismatch at %v. Expected %v, Found %v", name, i, trueAns, ans)
break
}
}

blas/gonum:  Fix NaN popagation in Dger.  (#225)

Fixes  #224

Fix NaN popagation in Dger.  Remove unneeded temp variables in Dger.

Generate level2single with Dger changes.