mirror of
				https://github.com/gonum/gonum.git
				synced 2025-10-31 10:36:30 +08:00 
			
		
		
		
	lapack/testlapack: add implementation comments to Dlanv2 test
This commit is contained in:
		 Vladimir Chalupecky
					Vladimir Chalupecky
				
			
				
					committed by
					
						 Vladimír Chalupecký
						Vladimír Chalupecký
					
				
			
			
				
	
			
			
			 Vladimír Chalupecký
						Vladimír Chalupecký
					
				
			
						parent
						
							1c4cf027b8
						
					
				
				
					commit
					9868dba4c8
				
			| @@ -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) | ||||
| 	if cc == 0 { | ||||
| 		// The eigenvalues are real, so check that the imaginary parts | ||||
| 		// are zero. | ||||
| 		if rt1i != 0 || rt2i != 0 { | ||||
| 			t.Errorf("Unexpected complex eigenvalues for %v", mat) | ||||
| 		} | ||||
| 	} else { | ||||
| 		// The eigenvalues are complex, so check that documented | ||||
| 		// conditions hold. | ||||
| 		if aa != dd { | ||||
| 			t.Errorf("Diagonal elements not equal for %v: got [%v %v]", mat, aa, dd) | ||||
| 		} | ||||
| 		if bb*cc >= 0 { | ||||
| 			t.Errorf("Non-diagonal elements have the same sign for %v: got [%v %v]", mat, bb, cc) | ||||
| 		} else { | ||||
| 			// Compute the absolute value of the imaginary part. | ||||
| 			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 { | ||||
| 				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 { | ||||
| 		t.Errorf("Unexpected real part of eigenvalue for %v: got %v, want %v or %v", mat, rt1r, aa, 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) | ||||
| 	} | ||||
| 	// Check that the columns of the orthogonal matrix have unit norm. | ||||
| 	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) | ||||
| 	} | ||||
|  | ||||
| 	// Re-compute the original matrix [a b; c d] from its factorization. | ||||
| 	gota := cs*(aa*cs-bb*sn) - sn*(cc*cs-dd*sn) | ||||
| 	gotb := cs*(aa*sn+bb*cs) - sn*(cc*sn+dd*cs) | ||||
| 	gotc := sn*(aa*cs-bb*sn) + cs*(cc*cs-dd*sn) | ||||
|   | ||||
		Reference in New Issue
	
	Block a user