42 #include <tests/myratest.h> 49 template<
class Precision>
void test(
int X,
int Y)
51 myra::out() << typestring<Precision>() << std::endl;
54 auto A = laplacian2<Precision>(X,Y);
57 Precision sigma = std::pow(ten,-3);
58 for (
int n = 0; n < N; ++n)
59 A(n,n) = A(n,n) - one + sigma;
60 A *= one /frobenius(A);
62 auto A_action = make_GemmAction(A);
68 normalize(Q.range().vector(0));
70 auto v_mu = lopcg1(M_action,A_action,Q);
72 Precision lambda = Precision(1)/v_mu.second;
75 Precision r_error = frobenius(r);
76 myra::out() <<
" |A*v - v*lambda| = " << r_error << std::endl;
77 REQUIRE(r_error < 1.0e-3);
80 auto V_Mu = lopcgN(M_action,A_action,Q,size);
83 for (
int ij = 0; ij < size; ++ij)
84 Lambda(ij) = Precision(1) / Lambda(ij);
87 Precision R_error = frobenius(R);
90 Precision I_error = frobenius(gemm(V,
'T',V,
'N')-I);
91 myra::out() <<
" |A*V - V*Lambda| = " << R_error << std::endl;
92 myra::out() <<
" |V'V - I| = " << R_error << std::endl;
93 myra::out() <<
" Mu = " << V_Mu.second.range() << std::endl;
94 REQUIRE(R_error < 1.0e-3);
95 REQUIRE(I_error < 1.0e-3);
100 ADD_TEST(
"lopcg",
"[iterative]")
Routines for computing euclidean norm of a Vector/VectorRange, or normalizing a Vector/VectorRange to...
Interface class for representing subranges of DiagonalMatrix's.
Interface class for representing subranges of dense Matrix's.
Interface class for representing subranges of dense Vector's.
Applies the "Action" of a linear operator, b := A*x, used in iterative solution algorithms.
Finds several small eigenpairs of a real symmetric Action.
Variety of routines for mixed dense*sparse or dense*sparse matrix multiplies. The dense*dense case is...
Routines for computing Frobenius norms of various algebraic containers.
Routines for multiplying by a DiagonalMatrix.
General purpose compressed-sparse-column (CSC) container.
CVectorRange< Number > first(int n) const
Returns a VectorRange over the first n entries, this(0:n)
Definition: Vector.cpp:192
Definition: stlprint.h:32
Action< typename ReflectNumber< Solver >::type > make_SolveAction(const Solver &solver, char op='N')
Free function for making SolveAction's.
Definition: SolveAction.h:67
Routines for printing the contents of various std::container's to a std::ostream using operator <<...
Various utility functions/classes related to scalar Number types.
static Matrix< Number > identity(int IJ)
Generates an identity Matrix of specified size.
Definition: Matrix.cpp:349
Signatures for sparse matrix * dense vector multiplies. All delegate to gemm() under the hood...
General purpose dense matrix container, O(i*j) storage.
Tabulates a vector of length N, allows random access.
Definition: conjugate.h:21
Container for either a column vector or row vector (depends upon the usage context) ...
Finds one small eigenpair of a real symmetric Action.
static Matrix< Number > ones(int I, int J)
Generates a ones Matrix of specified size.
Definition: Matrix.cpp:361
Adapts a class with a .solve() method into an Action.
An Action for multiplying by a dense Matrix or SparseMatrix using gemm().
Returns frobenius norm of a SparseMatrix.
Container for a diagonal matrix, O(n) storage. Used by SVD, row/column scaling, etc.
Incompletely factors A ~= L*L', presents approximate solve() method.
Definition: ICholeskySolver.h:28
Helper routines for reordering/filling 2D structured grids. Used by many unit tests.
Variety of routines all for dense Matrix*Matrix multiplies. Delegates to the BLAS.
Incomplete Cholesky preconditioner. Presents a solve() function, but it's only approximate.
Range/Iterator types associated with SparseMatrix.
double
|A*v - v*lambda| = 2.82036e-08
|A*V - V*Lambda| = 5.71556e-08
|V'V - I| = 5.71556e-08
Mu = size 3 DiagonalMatrix of double: [ 13126.5 13126.5 6887.18 ]
float
|A*v - v*lambda| = 6.89423e-05
|A*V - V*Lambda| = 0.000183611
|V'V - I| = 0.000183611
Mu = size 3 DiagonalMatrix of float: [ 13124.8 9546.3 6899.35 ]
double
|A*v - v*lambda| = 1.68718e-06
|A*V - V*Lambda| = 6.89533e-08
|V'V - I| = 6.89533e-08
Mu = size 3 DiagonalMatrix of double: [ 12914.4 12191 6571.3 ]
double
|A*v - v*lambda| = 4.84616e-08
|A*V - V*Lambda| = 1.53363e-07
|V'V - I| = 1.53363e-07
Mu = size 3 DiagonalMatrix of double: [ 9160.9 2469.86 2469.86 ]
float
|A*v - v*lambda| = 3.80715e-05
|A*V - V*Lambda| = 0.000146797
|V'V - I| = 0.000146797
Mu = size 3 DiagonalMatrix of float: [ 11584.7 10065.8 7610.83 ]
float
|A*v - v*lambda| = 4.17571e-06
|A*V - V*Lambda| = 1.36859e-05
|V'V - I| = 1.36859e-05
Mu = size 3 DiagonalMatrix of float: [ 9160.15 2469.8 2469.76 ]