MyraMath
djacobi


Source: tests/dense/jacobi.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>
17 
18 // Algorithms.
19 #include <myramath/dense/dimm.h>
20 #include <myramath/dense/gemm.h>
21 #include <myramath/dense/jacobi.h>
24 
25 // Reporting.
26 #include <tests/myratest.h>
27 
28 using namespace myra;
29 
30 namespace {
31 
32 template<class Precision> void test(int N, Precision tolerance)
33  {
34  myra::out() << typestring<Precision>() << std::endl;
35  // Fill symmetric A.
36  auto A = Matrix<Precision>::random(N,N);
37  A = A+transpose(A);
38  // Compute (X,D) using jacobi()
39  const auto XD = jacobi(A);
40  const auto& X = XD.first;
41  const auto& D = XD.second;
42  // Check errors (orthogonality, residual, convergence to diagonal form).
43  Precision I_error = frobenius(gemm(X,'T',X)-Matrix<Precision>::identity(N));
44  myra::out() << " |X'X-I| = " << I_error << std::endl;
45  Precision R_error = frobenius(A*X-X*D);
46  myra::out() << " |A*X-X*D| = " << R_error << std::endl;
47  REQUIRE(I_error < tolerance);
48  REQUIRE(R_error < tolerance);
49  }
50 
51 } // namespace
52 
53 ADD_TEST("sjacobi","[dense]")
54  { test<float> (10, 1.0e-3f); }
55 
56 ADD_TEST("djacobi","[dense]")
57  { test<double> (20, 1.0e-8); }
58 
Interface class for representing subranges of DiagonalMatrix&#39;s.
Jacobi methods for real symmetric eigendecomposition.
Interface class for representing subranges of dense Matrix&#39;s.
Tabulates an IxJ matrix. Allows random access, has column major layout to be compatible with BLAS/LAP...
Definition: bdsqr.h:20
Routines for computing Frobenius norms of various algebraic containers.
static Matrix< Number > random(int I, int J)
Generates a random Matrix of specified size.
Definition: Matrix.cpp:353
Routines for multiplying by a DiagonalMatrix.
Definition: syntax.dox:1
Returns a transposed copy of a Matrix. The inplace version only works on a square operand...
Various utility functions/classes related to scalar Number types.
General purpose dense matrix container, O(i*j) storage.
Container for a diagonal matrix, O(n) storage. Used by SVD, row/column scaling, etc.
Variety of routines all for dense Matrix*Matrix multiplies. Delegates to the BLAS.


Results: [PASS]

double
|X'X-I| = 1.0386e-14
|A*X-X*D| = 4.10424e-14


Go back to Summary of /test programs.