From a84dbb2e4f19f947a3a20094acda433ea06ee75a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Chalupeck=C3=BD?= Date: Mon, 27 Jan 2020 10:06:36 +0100 Subject: [PATCH] testlapack: adjust some tolerances (#1224) --- lapack/testlapack/dgeev.go | 5 +++ lapack/testlapack/dlaln2.go | 2 +- lapack/testlapack/dlansb.go | 2 +- lapack/testlapack/dlascl.go | 63 +++++++++++++++++++++++-------------- 4 files changed, 46 insertions(+), 26 deletions(-) diff --git a/lapack/testlapack/dgeev.go b/lapack/testlapack/dgeev.go index 15314e4b..84612d61 100644 --- a/lapack/testlapack/dgeev.go +++ b/lapack/testlapack/dgeev.go @@ -285,6 +285,7 @@ func DgeevTest(t *testing.T, impl Dgeever) { a: Gear(4).Matrix(), evWant: Gear(4).Eigenvalues(), valTol: 1e-7, + vecTol: 1e-11, }, { a: Gear(5).Matrix(), @@ -294,6 +295,7 @@ func DgeevTest(t *testing.T, impl Dgeever) { a: Gear(10).Matrix(), evWant: Gear(10).Eigenvalues(), valTol: 1e-8, + vecTol: 1e-11, }, { a: Gear(15).Matrix(), @@ -303,11 +305,13 @@ func DgeevTest(t *testing.T, impl Dgeever) { a: Gear(30).Matrix(), evWant: Gear(30).Eigenvalues(), valTol: 1e-8, + vecTol: 1e-11, }, { a: Gear(50).Matrix(), evWant: Gear(50).Eigenvalues(), valTol: 1e-8, + vecTol: 1e-11, }, { a: Gear(101).Matrix(), @@ -317,6 +321,7 @@ func DgeevTest(t *testing.T, impl Dgeever) { a: Gear(150).Matrix(), evWant: Gear(150).Eigenvalues(), valTol: 1e-8, + vecTol: 1e-11, }, { diff --git a/lapack/testlapack/dlaln2.go b/lapack/testlapack/dlaln2.go index a89781d0..ea8b9372 100644 --- a/lapack/testlapack/dlaln2.go +++ b/lapack/testlapack/dlaln2.go @@ -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) { - const tol = 1e-12 + const tol = 1e-11 // Generate random input scalars. ca := rnd.NormFloat64() diff --git a/lapack/testlapack/dlansb.go b/lapack/testlapack/dlansb.go index fd7d52f0..fe594ae8 100644 --- a/lapack/testlapack/dlansb.go +++ b/lapack/testlapack/dlansb.go @@ -121,7 +121,7 @@ func dlansbTest(t *testing.T, impl Dlansber, rnd *rand.Rand, uplo blas.Uplo, n, case lapack.Frobenius: 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) } } diff --git a/lapack/testlapack/dlascl.go b/lapack/testlapack/dlascl.go index 1c92e573..cec3e6e1 100644 --- a/lapack/testlapack/dlascl.go +++ b/lapack/testlapack/dlascl.go @@ -19,7 +19,7 @@ type Dlascler interface { } func DlasclTest(t *testing.T, impl Dlascler) { - const tol = 1e-16 + const tol = 1e-15 rnd := rand.New(rand.NewSource(1)) 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) } 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: for i := 0; i < m; i++ { for j := 0; j < n; j++ { want := scale * aCopy.Data[i*aCopy.Stride+j] got := a.Data[i*a.Stride+j] - if math.Abs(want-got) > tol { - t.Errorf("%v: unexpected A[%v,%v]=%v, want %v", prefix, i, j, got, want) - } + resid = math.Max(resid, math.Abs(want-got)) } } case lapack.UpperTri: @@ -71,16 +101,7 @@ func DlasclTest(t *testing.T, impl Dlascler) { for j := i; j < n; j++ { want := scale * aCopy.Data[i*aCopy.Stride+j] got := a.Data[i*a.Stride+j] - if math.Abs(want-got) > tol { - 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) - } + resid = math.Max(resid, math.Abs(want-got)) } } case lapack.LowerTri: @@ -88,19 +109,13 @@ func DlasclTest(t *testing.T, impl Dlascler) { for j := 0; j <= min(i, n-1); j++ { want := scale * aCopy.Data[i*aCopy.Stride+j] got := a.Data[i*a.Stride+j] - if math.Abs(want-got) > tol { - 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) - } + resid = math.Max(resid, math.Abs(want-got)) } } } + if resid > tol*float64(max(m, n)) { + t.Errorf("%v: unexpected result; residual=%v, want<=%v", prefix, resid, tol*float64(max(m, n))) + } } } }