MyraMath
bothcat_Action


Source: tests/iterative/bothcat.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/bothcat.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 bothcat(A,B,C,D)
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,5);
38  auto B0 = Matrix<Number>::random(5,3);
39  auto C0 = Matrix<Number>::random(3,5);
40  auto D0 = Matrix<Number>::random(3,3);
41  auto E0 = bothcat(A0,B0,C0,D0);
42  auto A = make_GemmAction(A0);
43  auto B = make_GemmAction(B0);
44  auto C = make_GemmAction(C0);
45  auto D = make_GemmAction(D0);
46  auto E = bothcat(A,B,C,D);
47  Precision error = frobenius(E0-E.make_Matrix());
48  myra::out() << " |E0-E| = " << error << std::endl;
49  REQUIRE(error < tolerance);
50  }
51 
52 #ifdef MYRAMATH_ENABLE_CPP11
53 
54 // Tests bothcat(A,B,C,D,E,F)
55 template<class Number> void test2(typename ReflectPrecision<Number>::type tolerance)
56  {
57  typedef typename ReflectPrecision<Number>::type Precision;
58  auto A0 = Matrix<Number>::random(5,5);
59  auto B0 = Matrix<Number>::random(5,3);
60  auto C0 = Matrix<Number>::random(5,7);
61  auto D0 = Matrix<Number>::random(4,5);
62  auto E0 = Matrix<Number>::random(4,3);
63  auto F0 = Matrix<Number>::random(4,7);
64  auto G0 = bothcat({2,3,{A0,B0,C0,D0,E0,F0}});
65  auto A = make_GemmAction(A0);
66  auto B = make_GemmAction(B0);
67  auto C = make_GemmAction(C0);
68  auto D = make_GemmAction(D0);
69  auto E = make_GemmAction(E0);
70  auto F = make_GemmAction(F0);
71  auto G = bothcat({2,3,{A,B,C,D,E,F}});
72  Precision error = frobenius(G0-G.make_Matrix());
73  myra::out() << " |G0-G| = " << error << std::endl;
74  REQUIRE(error < tolerance);
75  }
76 
77 #endif
78 
79 }
80 
81 ADD_TEST("bothcat_Action","[iterative]")
82  {
83  test1<NumberS>(1.0e-5f);
84  test1<NumberD>(1.0e-10);
85  test1<NumberC>(1.0e-5f);
86  test1<NumberZ>(1.0e-10);
87  }
88 
89 #ifdef MYRAMATH_ENABLE_CPP11
90 
91 ADD_TEST("bothcat_Action_cpp11","[iterative]")
92  {
93  test2<NumberS>(1.0e-5f);
94  test2<NumberD>(1.0e-10);
95  test2<NumberC>(1.0e-5f);
96  test2<NumberZ>(1.0e-10);
97  }
98 
99 #endif
100 
Interface class for representing subranges of dense Matrix&#39;s.
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
Container of values, allows random (i,j) access.
Routines to concatenate Action&#39;s in two-by-two fashion.
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
An Action for multiplying by a dense Matrix or SparseMatrix using gemm().
Routines to concatenate Matrix&#39;s in two-by-two fashion.


Results: [PASS]

|E0-E| = 0
|E0-E| = 0
|E0-E| = 0
|E0-E| = 0


Go back to Summary of /test programs.