MyraMath
mixed_refine


Source: tests/iterative/mixed_refine.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>
16 
17 // Algorithms.
18 #include <myramath/dense/gemm.h>
21 
22 // Iterative solve/action stuff.
27 
28 // Reporting.
30 #include <tests/myratest.h>
31 
32 using namespace myra;
33 using namespace myra_stlprint;
34 
35 namespace {
36 
37 template<class Double> void test(int I, int J)
38  {
39  // Deduce low precision Number type.
40  typedef typename LowerPrecision<Double>::type Float;
41  // Form random double precision A..
42  auto A_double = Matrix<Double>::random(I,I);
43  auto A_action = make_GemmAction(A_double);
44  // .. generate float precision LUSolver for it
45  auto A_float = lower_precision(A_double);
46  typedef LUSolver<Float> Solver;
47  Solver solver(A_float);
48  auto M_action = make_SolveAction(solver);
49  // .. generate random X, form A*X=B
50  auto X = Matrix<Double>::random(I,J);
51  auto B = A_double*X;
52  // .. solve A*X=B using refine(), by raising the precision of M_action
53  auto history = mixed_refine(A_action, M_action, B, 1.0e-14, 10);
54  double error = frobenius(B-X)/ frobenius(X);
55  myra::out() << " |inv(A)*B-X| = " << error << std::endl;
56  myra::out() << " history = " << history << std::endl;
57  REQUIRE(error < 1.0e-10);
58  }
59 
60 } // namespace
61 
62 ADD_TEST("mixed_refine","[iterative]")
63  {
64  int I = 50;
65  int J = 10;
66  test<NumberD> (I,J);
67  test<NumberZ> (I,J);
68  }
Interface class for representing subranges of dense Matrix&#39;s.
Routines for copying and lowering the precision of a container.
Applies the "Action" of a linear operator, b := A*x, used in iterative solution algorithms.
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
Definition: syntax.dox:1
Definition: stlprint.h:32
Action< typename ReflectNumber< Solver >::type > make_SolveAction(const Solver &solver, char op='N')
Free function for making SolveAction&#39;s.
Definition: SolveAction.h:67
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.
Like refine(), but uses a low-precision M to solve/refine a high-precision A.
General purpose dense matrix container, O(i*j) storage.
Reflectors that lower the Precision of a Number type.
Definition: Number.h:73
General purpose linear solver, no symmetry/definiteness assumptions upon A (just square) ...
Adapts a class with a .solve() method into an Action.
An Action for multiplying by a dense Matrix or SparseMatrix using gemm().
Factors a square matrix A into L*U, presents solve methods.
Definition: LUSolver.h:30
Variety of routines all for dense Matrix*Matrix multiplies. Delegates to the BLAS.


Results: [PASS]

|inv(A)*B-X| = 6.5319e-15
history = [ 4.90407e-07 2.45875e-12 3.10828e-16 ] (3)
|inv(A)*B-X| = 2.04088e-15
history = [ 7.43922e-07 1.51802e-12 3.48167e-16 ] (3)


Go back to Summary of /test programs.