testlapack: adjust some tolerances (#1224)

This commit is contained in:
Vladimír Chalupecký
2020-01-27 10:06:36 +01:00
committed by GitHub
parent 86e8186781
commit a84dbb2e4f
4 changed files with 46 additions and 26 deletions

View File

@@ -285,6 +285,7 @@ func DgeevTest(t *testing.T, impl Dgeever) {
a: Gear(4).Matrix(), a: Gear(4).Matrix(),
evWant: Gear(4).Eigenvalues(), evWant: Gear(4).Eigenvalues(),
valTol: 1e-7, valTol: 1e-7,
vecTol: 1e-11,
}, },
{ {
a: Gear(5).Matrix(), a: Gear(5).Matrix(),
@@ -294,6 +295,7 @@ func DgeevTest(t *testing.T, impl Dgeever) {
a: Gear(10).Matrix(), a: Gear(10).Matrix(),
evWant: Gear(10).Eigenvalues(), evWant: Gear(10).Eigenvalues(),
valTol: 1e-8, valTol: 1e-8,
vecTol: 1e-11,
}, },
{ {
a: Gear(15).Matrix(), a: Gear(15).Matrix(),
@@ -303,11 +305,13 @@ func DgeevTest(t *testing.T, impl Dgeever) {
a: Gear(30).Matrix(), a: Gear(30).Matrix(),
evWant: Gear(30).Eigenvalues(), evWant: Gear(30).Eigenvalues(),
valTol: 1e-8, valTol: 1e-8,
vecTol: 1e-11,
}, },
{ {
a: Gear(50).Matrix(), a: Gear(50).Matrix(),
evWant: Gear(50).Eigenvalues(), evWant: Gear(50).Eigenvalues(),
valTol: 1e-8, valTol: 1e-8,
vecTol: 1e-11,
}, },
{ {
a: Gear(101).Matrix(), a: Gear(101).Matrix(),
@@ -317,6 +321,7 @@ func DgeevTest(t *testing.T, impl Dgeever) {
a: Gear(150).Matrix(), a: Gear(150).Matrix(),
evWant: Gear(150).Eigenvalues(), evWant: Gear(150).Eigenvalues(),
valTol: 1e-8, valTol: 1e-8,
vecTol: 1e-11,
}, },
{ {

View File

@@ -33,7 +33,7 @@ func Dlaln2Test(t *testing.T, impl Dlaln2er) {
} }
func testDlaln2(t *testing.T, impl Dlaln2er, trans bool, na, nw, extra int, rnd *rand.Rand) { func testDlaln2(t *testing.T, impl Dlaln2er, trans bool, na, nw, extra int, rnd *rand.Rand) {
const tol = 1e-12 const tol = 1e-11
// Generate random input scalars. // Generate random input scalars.
ca := rnd.NormFloat64() ca := rnd.NormFloat64()

View File

@@ -121,7 +121,7 @@ func dlansbTest(t *testing.T, impl Dlansber, rnd *rand.Rand, uplo blas.Uplo, n,
case lapack.Frobenius: case lapack.Frobenius:
normWant = frobWant normWant = frobWant
} }
if math.Abs(normGot-normWant) >= tol { if math.Abs(normGot-normWant) > tol*float64(n) {
t.Errorf("%v: unexpected result; got %v, want %v", name, normGot, normWant) t.Errorf("%v: unexpected result; got %v, want %v", name, normGot, normWant)
} }
} }

View File

@@ -19,7 +19,7 @@ type Dlascler interface {
} }
func DlasclTest(t *testing.T, impl Dlascler) { func DlasclTest(t *testing.T, impl Dlascler) {
const tol = 1e-16 const tol = 1e-15
rnd := rand.New(rand.NewSource(1)) rnd := rand.New(rand.NewSource(1))
for ti, test := range []struct { for ti, test := range []struct {
@@ -56,14 +56,44 @@ func DlasclTest(t *testing.T, impl Dlascler) {
t.Errorf("%v: out-of-range write to A", prefix) t.Errorf("%v: out-of-range write to A", prefix)
} }
switch kind { switch kind {
case lapack.UpperTri:
var mod bool
loopLower:
for i := 0; i < m; i++ {
for j := 0; j < min(i, n); j++ {
if a.Data[i*a.Stride+j] != aCopy.Data[i*aCopy.Stride+j] {
mod = true
break loopLower
}
}
}
if mod {
t.Errorf("%v: unexpected modification in lower triangle of A", prefix)
}
case lapack.LowerTri:
var mod bool
loopUpper:
for i := 0; i < m; i++ {
for j := i + 1; j < n; j++ {
if a.Data[i*a.Stride+j] != aCopy.Data[i*aCopy.Stride+j] {
mod = true
break loopUpper
}
}
}
if mod {
t.Errorf("%v: unexpected modification in upper triangle of A", prefix)
}
}
var resid float64
switch kind {
case lapack.General: case lapack.General:
for i := 0; i < m; i++ { for i := 0; i < m; i++ {
for j := 0; j < n; j++ { for j := 0; j < n; j++ {
want := scale * aCopy.Data[i*aCopy.Stride+j] want := scale * aCopy.Data[i*aCopy.Stride+j]
got := a.Data[i*a.Stride+j] got := a.Data[i*a.Stride+j]
if math.Abs(want-got) > tol { resid = math.Max(resid, math.Abs(want-got))
t.Errorf("%v: unexpected A[%v,%v]=%v, want %v", prefix, i, j, got, want)
}
} }
} }
case lapack.UpperTri: case lapack.UpperTri:
@@ -71,16 +101,7 @@ func DlasclTest(t *testing.T, impl Dlascler) {
for j := i; j < n; j++ { for j := i; j < n; j++ {
want := scale * aCopy.Data[i*aCopy.Stride+j] want := scale * aCopy.Data[i*aCopy.Stride+j]
got := a.Data[i*a.Stride+j] got := a.Data[i*a.Stride+j]
if math.Abs(want-got) > tol { resid = math.Max(resid, math.Abs(want-got))
t.Errorf("%v: unexpected A[%v,%v]=%v, want %v", prefix, i, j, got, want)
}
}
}
for i := 0; i < m; i++ {
for j := 0; j < min(i, n); j++ {
if a.Data[i*a.Stride+j] != aCopy.Data[i*aCopy.Stride+j] {
t.Errorf("%v: unexpected modification in lower triangle of A", prefix)
}
} }
} }
case lapack.LowerTri: case lapack.LowerTri:
@@ -88,19 +109,13 @@ func DlasclTest(t *testing.T, impl Dlascler) {
for j := 0; j <= min(i, n-1); j++ { for j := 0; j <= min(i, n-1); j++ {
want := scale * aCopy.Data[i*aCopy.Stride+j] want := scale * aCopy.Data[i*aCopy.Stride+j]
got := a.Data[i*a.Stride+j] got := a.Data[i*a.Stride+j]
if math.Abs(want-got) > tol { resid = math.Max(resid, math.Abs(want-got))
t.Errorf("%v: unexpected A[%v,%v]=%v, want %v", prefix, i, j, got, want)
}
}
}
for i := 0; i < m; i++ {
for j := i + 1; j < n; j++ {
if a.Data[i*a.Stride+j] != aCopy.Data[i*aCopy.Stride+j] {
t.Errorf("%v: unexpected modification in upper triangle of A", prefix)
}
} }
} }
} }
if resid > tol*float64(max(m, n)) {
t.Errorf("%v: unexpected result; residual=%v, want<=%v", prefix, resid, tol*float64(max(m, n)))
}
} }
} }
} }