32 #include <tests/myratest.h> 39 template<
class Precision>
void testL(
int N, Precision tolerance)
41 myra::out() << typestring<Precision>() << std::endl;
48 auto tau = sytrd_inplace(
'L',A);
53 for (
int n = 0; n < N; ++n)
54 T0(n) = T(n,n) = A(n,n);
55 for (
int n = 0; n < N-1; ++n)
56 T1(n) = T(n+1,n) = T(n,n+1) = A(n+1,n);
58 auto lambda_A = syev_inplace(A1);
59 auto lambda_T = stev(T0,T1).second;
60 Precision error1 = frobenius(lambda_A-lambda_T) / frobenius(lambda_A);
61 myra::out() <<
"|eig(A)-eig(T)| = " << error1 << std::endl;
62 REQUIRE(error1 < tolerance);
64 auto Q = A.
bottom(N-1).left(N-1);
65 ormqr_inplace(Q,tau,A2.bottom(N-1),
'L',
'T');
66 ormqr_inplace(Q,tau,A2.right(N-1),
'R',
'N');
67 Precision error2 = frobenius(A2-T) / frobenius(T);
68 myra::out() <<
"|Q'*A*Q - T| = " << error2 << std::endl;
69 REQUIRE(error2 < tolerance);
73 template<
class Precision>
void testU(
int N, Precision tolerance)
75 myra::out() << typestring<Precision>() << std::endl;
82 auto tau = sytrd_inplace(
'U',A);
87 for (
int n = 0; n < N; ++n)
88 T0(n) = T(n,n) = A(n,n);
89 for (
int n = 0; n < N-1; ++n)
90 T1(n) = T(n+1,n) = T(n,n+1) = A(n,n+1);
92 auto lambda_A = syev_inplace(A1);
93 auto lambda_T = stev(T0,T1).second;
94 Precision error1 = frobenius(lambda_A-lambda_T) / frobenius(lambda_A);
95 myra::out() <<
"|eig(A)-eig(T)| = " << error1 << std::endl;
96 REQUIRE(error1 < tolerance);
98 auto Q = A.
right(N-1).top(N-1);
99 ormlq_inplace(Q,tau,A2.bottom(N-1),
'L',
'N');
100 ormlq_inplace(Q,tau,A2.right(N-1),
'R',
'T');
101 Precision error2 = frobenius(A2-T) / frobenius(T);
102 myra::out() <<
"|Q*A*Q' - T| = " << error2 << std::endl;
110 ADD_TEST(
"ssytrdL",
"[dense][lapack]")
111 { testL<float>(157,1.0e-4f); }
113 ADD_TEST(
"dsytrdL",
"[dense][lapack]")
114 { testL<double>(157,1.0e-10); }
116 ADD_TEST(
"ssytrdU",
"[dense][lapack]")
117 { testU<float>(157,1.0e-4f); }
119 ADD_TEST(
"dsytrdU",
"[dense][lapack]")
120 { testU<double>(157,1.0e-10); }
CMatrixRange< Number > right(int j) const
Returns a MatrixRange over the j rightmost columns, this(:,J-j:J)
Definition: Matrix.cpp:281
Interface class for representing subranges of DiagonalMatrix's.
Computes all eigenpairs of real symmetric Matrix.
Interface class for representing subranges of dense Matrix's.
Routines to apply a Householder Q, as previously factored via gelqf_inplace()
static Matrix< Number > zeros(int I, int J)
Generates a zeros Matrix of specified size.
Definition: Matrix.cpp:357
Routines for computing Frobenius norms of various algebraic containers.
static Matrix< Number > random(int I, int J)
Generates a random Matrix of specified size.
Definition: Matrix.cpp:353
CMatrixRange< Number > bottom(int i) const
Returns a MatrixRange over the i bottommost rows, this(I-i:I,:)
Definition: Matrix.cpp:225
Householder tridiagonalization of a real symmetric Matrix.
Replaces small values with explicit zeros.
Returns a transposed copy of a Matrix. The inplace version only works on a square operand...
Various utility functions/classes related to scalar Number types.
static Vector< Number > zeros(int N)
Generates a zeros Vector of specified size.
Definition: Vector.cpp:280
General purpose dense matrix container, O(i*j) storage.
Container for either a column vector or row vector (depends upon the usage context) ...
Returns the diagonal of a dense Matrix or LowerMatrix.
Routines to apply a Householder Q, as previously factored via geqrf_inplace()
Computes all eigenpairs of real symmetric tridiagonal matrix.
Container for a diagonal matrix, O(n) storage. Used by SVD, row/column scaling, etc.
Variety of routines all for dense Matrix*Matrix multiplies. Delegates to the BLAS.