lapack/testlapack: add implementation comments to Dlanv2 test

This commit is contained in:
Vladimir Chalupecky
2018-06-13 15:57:54 +02:00
committed by Vladimír Chalupecký
parent 1c4cf027b8
commit 9868dba4c8

View File

@@ -61,17 +61,24 @@ func dlanv2Test(t *testing.T, impl Dlanv2er, a, b, c, d float64) {
mat := fmt.Sprintf("[%v %v; %v %v]", a, b, c, d) mat := fmt.Sprintf("[%v %v; %v %v]", a, b, c, d)
if cc == 0 { if cc == 0 {
// The eigenvalues are real, so check that the imaginary parts
// are zero.
if rt1i != 0 || rt2i != 0 { if rt1i != 0 || rt2i != 0 {
t.Errorf("Unexpected complex eigenvalues for %v", mat) t.Errorf("Unexpected complex eigenvalues for %v", mat)
} }
} else { } else {
// The eigenvalues are complex, so check that documented
// conditions hold.
if aa != dd { if aa != dd {
t.Errorf("Diagonal elements not equal for %v: got [%v %v]", mat, aa, dd) t.Errorf("Diagonal elements not equal for %v: got [%v %v]", mat, aa, dd)
} }
if bb*cc >= 0 { if bb*cc >= 0 {
t.Errorf("Non-diagonal elements have the same sign for %v: got [%v %v]", mat, bb, cc) t.Errorf("Non-diagonal elements have the same sign for %v: got [%v %v]", mat, bb, cc)
} else { } else {
// Compute the absolute value of the imaginary part.
im := math.Sqrt(-bb * cc) im := math.Sqrt(-bb * cc)
// Check that ±im is close to one of the returned
// imaginary parts.
if math.Abs(rt1i-im) > 1e-14 && math.Abs(rt1i+im) > 1e-14 { if math.Abs(rt1i-im) > 1e-14 && math.Abs(rt1i+im) > 1e-14 {
t.Errorf("Unexpected imaginary part of eigenvalue for %v: got %v, want %v or %v", mat, rt1i, im, -im) t.Errorf("Unexpected imaginary part of eigenvalue for %v: got %v, want %v or %v", mat, rt1i, im, -im)
} }
@@ -80,16 +87,19 @@ func dlanv2Test(t *testing.T, impl Dlanv2er, a, b, c, d float64) {
} }
} }
} }
// Check that the returned real parts are consistent.
if rt1r != aa && rt1r != dd { if rt1r != aa && rt1r != dd {
t.Errorf("Unexpected real part of eigenvalue for %v: got %v, want %v or %v", mat, rt1r, aa, dd) t.Errorf("Unexpected real part of eigenvalue for %v: got %v, want %v or %v", mat, rt1r, aa, dd)
} }
if rt2r != aa && rt2r != dd { if rt2r != aa && rt2r != dd {
t.Errorf("Unexpected real part of eigenvalue for %v: got %v, want %v or %v", mat, rt2r, aa, dd) t.Errorf("Unexpected real part of eigenvalue for %v: got %v, want %v or %v", mat, rt2r, aa, dd)
} }
// Check that the columns of the orthogonal matrix have unit norm.
if math.Abs(math.Hypot(cs, sn)-1) > 1e-14 { if math.Abs(math.Hypot(cs, sn)-1) > 1e-14 {
t.Errorf("Unexpected unitary matrix for %v: got cs %v, sn %v", mat, cs, sn) t.Errorf("Unexpected unitary matrix for %v: got cs %v, sn %v", mat, cs, sn)
} }
// Re-compute the original matrix [a b; c d] from its factorization.
gota := cs*(aa*cs-bb*sn) - sn*(cc*cs-dd*sn) gota := cs*(aa*cs-bb*sn) - sn*(cc*cs-dd*sn)
gotb := cs*(aa*sn+bb*cs) - sn*(cc*sn+dd*cs) gotb := cs*(aa*sn+bb*cs) - sn*(cc*sn+dd*cs)
gotc := sn*(aa*cs-bb*sn) + cs*(cc*cs-dd*sn) gotc := sn*(aa*cs-bb*sn) + cs*(cc*cs-dd*sn)