MyraMath
lanczos2


Source: tests/iterative/lanczosn.cpp

1 // ========================================================================= //
2 // This file is part of MyraMath, copyright (c) 2014-2019 by Ryan A Chilton //
3 // and distributed by MyraCore, LLC. See LICENSE.txt for license terms. //
4 // ========================================================================= //
5 
11 // Containers.
13 #include <myramath/dense/Matrix.h>
19 
20 // Algorithms.
21 #include <myramath/dense/gemm.h>
22 #include <myramath/dense/dimm.h>
24 #include <myramath/sparse/gemm.h>
25 #include <myramath/sparse/gemv.h>
27 
28 // Iterative solve/action stuff.
32 
33 // Reporting.
35 #include <tests/myratest.h>
36 
37 using namespace myra;
38 using namespace myra_stlprint;
39 
40 namespace {
41 
42 template<class Precision> void test(int X, int Y, Precision tolerance)
43  {
44  myra::out() << typestring<Precision>() << std::endl;
45  // Construct 2D laplacian.
46  int N = X*Y;
47  auto A = laplacian2<Precision>(X,Y);
48  // Compute a few dominant eigenpairs.
49  int size = 8;
50  Matrix<Precision> Q(N,0);
51  auto VD = lanczosN(make_GemmAction(A),Q,size,tolerance,100);
52  const Matrix<Precision>& V = VD.first;
53  const DiagonalMatrix<Precision>& D = VD.second;
54  // Evaluate residual A*V-V*D
55  Matrix<Precision> R = A*V - V*D;
56  Precision R_error = frobenius(R);
57  myra::out() << " |A*V-V*D| = " << R_error << std::endl;
58  // Evaluate orthogonality V'V-I
59  auto I = Matrix<Precision>::identity(size);
60  Precision I_error = frobenius(gemm(V,'T',V)-I);
61  myra::out() << " |V'V-I| = " << I_error << std::endl;
62  REQUIRE(R_error < tolerance*10.0);
63  REQUIRE(I_error < tolerance*10.0);
64  }
65 
66 } // namespace
67 
68 ADD_TEST("lanczos2","[iterative]")
69  {
70  test<float> (20,15,1.0e-4f);
71  test<double>(20,15,1.0e-8);
72  }
Interface class for representing subranges of DiagonalMatrix&#39;s.
Interface class for representing subranges of dense Matrix&#39;s.
Applies the "Action" of a linear operator, b := A*x, used in iterative solution algorithms.
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.
Definition: syntax.dox:1
Definition: stlprint.h:32
Routines for printing the contents of various std::container&#39;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...
Finds several dominant eigenpairs of a real symmetric Action.
General purpose dense matrix container, O(i*j) storage.
An Action for multiplying by a dense Matrix or SparseMatrix using gemm().
Container for a diagonal matrix, O(n) storage. Used by SVD, row/column scaling, etc.
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.
Range/Iterator types associated with SparseMatrix.


Results: [PASS]

float
|A*V-V*D| = 0.000119167
|V'V-I| = 3.94578e-06
double
|A*V-V*D| = 9.96744e-09
|V'V-I| = 1.3893e-14


Go back to Summary of /test programs.