MyraMath


Source: tests/iterative/ICholeskySolver.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>
18 
19 // Algorithms.
21 #include <myramath/sparse/phasor.h>
23 
24 // Reporting.
25 #include <tests/myratest.h>
26 
27 using namespace myra;
28 
29 namespace {
30 
31 // Tests real-valued ICholeskySolver
32 template<class Precision> void test1(int I, int J, Precision tolerance)
33  {
34  typedef Precision Number;
35  myra::out() << typestring<Number>() << std::endl;
36  // Make a laplacian of an IxJ structured grid.
37  auto A = laplacian2<Number>(I,J);
38  ICholeskySolver<Number> solver(A);
39  int N = I*J;
40  // Solve an identity from the right and the left, make sure they are equal.
41  auto eyeL = Matrix<Number>::identity(N);
42  solver.solve(eyeL,'L');
43  auto eyeR = Matrix<Number>::identity(N);
44  solver.solve(eyeR,'R');
45  Precision error = frobenius(eyeL-eyeR);
46  myra::out() << "|L'\\L\\I - I/L/L'| = " << error << std::endl;
47  REQUIRE(error < tolerance);
48  }
49 
50 // Tests complex-valued ICholeskySolver
51 template<class Precision> void test2(int I, int J, Precision tolerance)
52  {
53  typedef std::complex<Precision> Number;
54  myra::out() << typestring<Number>() << std::endl;
55  // Make a laplacian of an IxJ structured grid.
56  auto A = laplacian2<Number>(I,J);
57  phasor_hermitian(A);
58  ICholeskySolver<Number> solver(A);
59  int N = I*J;
60  // Solve an identity from the right and the left, make sure they are equal.
61  auto eyeL = Matrix<Number>::identity(N);
62  solver.solve(eyeL,'L');
63  auto eyeR = Matrix<Number>::identity(N);
64  solver.solve(eyeR,'R');
65  Precision error = frobenius(eyeL-eyeR);
66  myra::out() << "|L'\\L\\I - I/L/L'| = " << error << std::endl;
67  REQUIRE(error < tolerance);
68  }
69 
70 } // namespace
71 
72 ADD_TEST("ICholeskySolver","[iterative]")
73  {
74  // Real-valued.
75  test1<float> (20,20,1.0e-4f);
76  test1<double>(20,20,1.0e-8);
77  // Complex-valued.
78  test2<float> (20,20,1.0e-4f);
79  test2<double>(20,20,1.0e-8);
80  }
81 
Interface class for representing subranges of dense Matrix&#39;s.
Routines for computing Frobenius norms of various algebraic containers.
General purpose compressed-sparse-column (CSC) container.
Definition: syntax.dox:1
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
General purpose dense matrix container, O(i*j) storage.
Incompletely factors A ~= L*L&#39;, presents approximate solve() method.
Definition: ICholeskySolver.h:28
Helper routines for reordering/filling 2D structured grids. Used by many unit tests.
Applies random phase shifts to a complex square SparseMatrix.
Incomplete Cholesky preconditioner. Presents a solve() function, but it&#39;s only approximate.
Range/Iterator types associated with SparseMatrix.


Results: [PASS]

float
|L'\L\I - I/L/L'| = 1.88734e-07
double
|L'\L\I - I/L/L'| = 4.0476e-16
std::complex<float>
|L'\L\I - I/L/L'| = 1.99883e-07
std::complex<double>
|L'\L\I - I/L/L'| = 4.25093e-16


Go back to Summary of /test programs.