MyraMath
equilibrate


Source: tests/sparse/equilibrate.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 // Expressions.
16 
17 // Containers.
20 
21 // Algorithms.
26 #include <myramath/sparse/dimm.h>
27 
28 // Reporting.
29 #include <tests/myratest.h>
30 using namespace myra;
31 
32 ADD_TEST("equilibrate","[sparse]")
33  {
34  // Form a laplacian, rescale it randomly into D*A*D
35  auto A = laplacian2<NumberD>(5,5);
36  auto D = DiagonalMatrix<NumberD>::evaluate( pow(10.0,6.0*make_RandomExpression<NumberD>(A.size().first)) );
37  dimm_inplace('L','N',D,A);
38  dimm_inplace('R','N',D,A);
39  // Make a deep copy and equilibrate it.
40  auto B = A;
41  auto E = equilibrate(B);
42  // Verify E*B*E = A, with low relative error.
43  double error = frobenius(A-E*B*E)/frobenius(A);
44  myra::out() << "|A-E*B*E| = " << error << std::endl;
45  REQUIRE(error < 1.0e-12);
46  }
47 
Expression< 1, NumberS > pow(const Expression< 1, NumberS > &A, const Expression< 1, NumberS > &B)
Returns A^B, an Expression base raised to an Expression power.
Definition: functions_power.cpp:53
Generators for basic Expression&#39;s (constant, random, linspace, etc).
An interface used to fill containers from Expression&#39;s (see Matrix::evaluate(), for example)...
General purpose compressed-sparse-column (CSC) container.
Definition: syntax.dox:1
Arithmetic operators (+,-,*,/) for Expression&#39;s.
Routines for multiplying by a DiagonalMatrix.
Rescales rows and columns of a symmetric SparseMatrix A, prior to direct factorization.
Function overloads (sin, exp, etc) for Expression&#39;s.
Returns frobenius norm of a SparseMatrix.
std::pair< int, int > size() const
Size inspector.
Definition: Matrix.cpp:116
Simplistic random number functions.
Container for a diagonal matrix, O(n) storage. Used by SVD, row/column scaling, etc.
static DiagonalMatrix< Number > evaluate(const Expression< 1, Number > &e)
Generates a DiagonalMatrix by evaluating an arity-1 Expression of Number.
Definition: DiagonalMatrix.cpp:258
Helper routines for reordering/filling 2D structured grids. Used by many unit tests.


Results: [PASS]

|A-E*B*E| = 1.30301e-17


Go back to Summary of /test programs.