MyraMath
diagcat_Action_cpp11


Source: tests/iterative/diagcat.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>
16 
17 // Algorithms.
19 #include <myramath/dense/diagcat.h>
20 
21 // Iterative solve/action stuff.
25 
26 // Reporting.
27 #include <tests/myratest.h>
28 
29 using namespace myra;
30 
31 namespace {
32 
33 // Tests diagcat(A,B)
34 template<class Number> void test1(typename ReflectPrecision<Number>::type tolerance)
35  {
36  typedef typename ReflectPrecision<Number>::type Precision;
37  auto A0 = Matrix<Number>::random(5,3);
38  auto B0 = Matrix<Number>::random(5,7);
39  auto C0 = diagcat(A0,B0);
40  auto A = make_GemmAction(A0);
41  auto B = make_GemmAction(B0);
42  auto C = diagcat(A,B);
43  Precision error = frobenius(C0-C.make_Matrix());
44  myra::out() << " |C0-C| = " << error << std::endl;
45  REQUIRE(error < tolerance);
46  }
47 
48 #ifdef MYRAMATH_ENABLE_CPP11
49 
50 // Tests diagcat(A,B,C)
51 template<class Number> void test2(typename ReflectPrecision<Number>::type tolerance)
52  {
53  typedef typename ReflectPrecision<Number>::type Precision;
54  auto A0 = Matrix<Number>::random(5,3);
55  auto B0 = Matrix<Number>::random(5,7);
56  auto C0 = Matrix<Number>::random(5,6);
57  auto D0 = diagcat({A0,B0,C0});
58  auto A = make_GemmAction(A0);
59  auto B = make_GemmAction(B0);
60  auto C = make_GemmAction(C0);
61  auto D = diagcat({A,B,C});
62  Precision error = frobenius(D0-D.make_Matrix());
63  myra::out() << " |D0-D| = " << error << std::endl;
64  REQUIRE(error < tolerance);
65  }
66 
67 #endif
68 
69 }
70 
71 ADD_TEST("diagcat_Action","[iterative]")
72  {
73  test1<NumberS>(1.0e-5f);
74  test1<NumberD>(1.0e-10);
75  test1<NumberC>(1.0e-5f);
76  test1<NumberZ>(1.0e-10);
77  }
78 
79 #ifdef MYRAMATH_ENABLE_CPP11
80 
81 ADD_TEST("diagcat_Action_cpp11","[iterative]")
82  {
83  test2<NumberS>(1.0e-5f);
84  test2<NumberD>(1.0e-10);
85  test2<NumberC>(1.0e-5f);
86  test2<NumberZ>(1.0e-10);
87  }
88 
89 #endif
90 
Interface class for representing subranges of dense Matrix&#39;s.
Container of values, allows random (i) access.
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
Various utility functions/classes related to scalar Number types.
General purpose dense matrix container, O(i*j) storage.
Reflects Precision trait for a Number, scalar Number types should specialize it.
Definition: Number.h:33
Routines to concatenate Matrix&#39;s in diagonal fashion.
An Action for multiplying by a dense Matrix or SparseMatrix using gemm().
Routines to concatenate Action&#39;s in diagonal fashion.


Results: [PASS]

|D0-D| = 0
|D0-D| = 0
|D0-D| = 0
|D0-D| = 0


Go back to Summary of /test programs.