MyraMath
zldlh2_inverse


Source: tests/multifrontal/zldlh/zldlh2_inverse.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.
14 #include <myramath/dense/Matrix.h>
23 
24 // Algorithms.
26 #include <myramath/dense/gemm.h>
27 #include <myramath/dense/inverse.h>
30 #include <myramath/sparse/phasor.h>
31 
32 // Solver under test.
34 
35 // Reporting.
36 #include <myramath/utility/Timer.h>
37 #include <tests/myratest.h>
38 
39 #include <algorithm>
40 
41 using namespace myra;
42 
43 ADD_TEST("zldlh2_inverse","[multifrontal][parallel]")
44  {
45  // Generate A. Need to break these tests apart, there's a wide dynamic
46  // range in times so using the same input size doesn't make the most sense.
47  int I = 10;
48  int J = 10;
49  int N = I*J;
50  SparseMatrix<NumberZ> A = laplacian2<NumberZ>(I,J);
51  double shift = 5.5;
52  for (int n = 0; n < N; ++n)
53  A(n,n) -= shift;
54  phasor_hermitian(A);
55  Pattern P = stencil2(I,J);
56  // Options related to reordering. Test input is small, so need to use small
57  // blocks/no globbing to make sure the symbolic factorization is nontrivial
58  typedef multifrontal::Options Options;
59  Options options = Options::create().set_blocksize(4).set_globsize(4).set_nthreads(1);
60  // Reorder A using bisection and factor it.
61  Permutation perm = bisect2(I,J);
62  SparseZLDLHSolver<double> solver(A,perm,options);
63  // Compute inverse of A explicitly, for reference.
64  Matrix<NumberZ> invA = inverse(A.make_Matrix());
65  // Compare to solver.inverse(i,j) for each nonzero original pattern.
66  {
67  Timer timer;
68  double error1 = 0;
69  for (int j = 0; j < N; ++j)
70  {
71  std::vector<int> Pj = P.pattern(j);
72  for (auto i = Pj.begin(); i != Pj.end(); ++i)
73  error1 = std::max(error1, scalar_norm1(invA(*i,j)-solver.inverse(*i,j)) );
74  }
75  double t = timer.elapsed_time();
76  myra::out() << "|solver.inverse(i,j)| = " << error1 << ", " << t << " sec" << std::endl;
77  REQUIRE(error1 < 1.0e-12);
78  }
79  // Check the inverse over some arbitrary 20x20 tensor block.
80  {
81  Timer timer;
82  Matrix<NumberZ> invA_block = solver.inverse(ilinspace(5,25), ilinspace(27,47));
83  double t = timer.elapsed_time();
84  double error3 = frobenius(invA_block - invA.window(5,25,27,47));
85  myra::out() << "|solver.inverse(i_indices,j_indices)| = " << error3 << ", " << t << " sec" << std::endl;
86  REQUIRE(error3 < 1.0e-12);
87  }
88  // Check the inverse over a diagonal 20x20 tensor block.
89  {
90  Timer timer;
91  LowerMatrix<NumberZ> invA_block = solver.inverse(ilinspace(5,25));
92  double t = timer.elapsed_time();
93  double error4 = frobenius(invA_block.make_Matrix('H') - invA.window(5,25,5,25));
94  myra::out() << "|solver.inverse(ij_indices)| = " << error4 << ", " << t << " sec" << std::endl;
95  REQUIRE(error4 < 1.0e-12);
96  }
97  }
Interface class for representing subranges of dense Matrix&#39;s.
Options pack for routines in /multifrontal.
Definition: Options.h:24
Sparse direct solver suitable for complex hermitian indefinite systems.
Represents a Permutation matrix, used to reorder rows/columns/etc of various numeric containers...
Definition: Permutation.h:34
Tabulates an IxJ matrix. Allows random access, has column major layout to be compatible with BLAS/LAP...
Definition: bdsqr.h:20
Matrix< Number > make_Matrix(char op='N') const
Accumulates *this onto the lower triangle of a Matrix<Number>
Definition: LowerMatrix.cpp:152
Routines for computing Frobenius norms of various algebraic containers.
Simplistic timing class, might dispatch to platform specific timers depending upon environment...
std::vector< int > pattern(int j) const
Returns the (sorted) nonzero pattern of A(:,j)
Definition: Pattern.cpp:157
Sparse direct solver suitable for complex hermitian indefinite systems.
Definition: SparseZLDLHSolver.h:60
General purpose compressed-sparse-column (CSC) container.
Range construct for a lower triangular matrix stored in rectangular packed format.
Definition: syntax.dox:1
CMatrixRange< Number > window(int i0, int i1, int j0, int j1) const
Returns a MatrixRange over this(i0:i1,j0:j1)
Definition: Matrix.cpp:142
Measures elapsed time.
Definition: Timer.h:19
Specialized container for a lower triangular matrix, O(N^2/2) storage. Used by symmetry exploiting ma...
Various utility functions/classes related to scalar Number types.
Returns a vector of int&#39;s, over [min,max)
General purpose dense matrix container, O(i*j) storage.
Range/Iterator types associated with Pattern.
Holds the nonzero pattern of a sparse matrix.
Definition: Pattern.h:55
Container class for a sparse nonzero pattern, used in reordering/symbolic analysis.
Overwrites a LowerMatrix, DiagonalMatrix, or square Matrix with its own inverse. Or, returns it as a copy.
Aggregates a (perm, iperm, swaps) triple into a vocabulary type.
Stores a lower triangular matrix in rectangular packed format.
Definition: conjugate.h:22
Stores an IxJ matrix A in compressed sparse column format.
Definition: bothcat.h:23
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.
Applies random phase shifts to a complex square SparseMatrix.
double elapsed_time() const
Returns elapsed time in seconds since last call to reset()
Definition: Timer.cpp:18
Range/Iterator types associated with SparseMatrix.
Matrix< Number > make_Matrix() const
Accumulates *this onto a Matrix<Number>.
Definition: SparseMatrix.cpp:581
Interface class for representing subranges of contiguous int&#39;s.


Results: [PASS]

|solver.inverse(i,j)| = 9.63218e-15, 0.103006 sec
|solver.inverse(i_indices,j_indices)| = 3.37255e-14, 0.047002 sec
|solver.inverse(ij_indices)| = 3.2302e-14, 0.030002 sec


Go back to Summary of /test programs.