MyraMath
diagcat_Matrix


Source: tests/dense/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.
12 #include <myramath/dense/Matrix.h>
16 
17 // Algorithms.
18 #include <myramath/dense/diagcat.h>
20 
21 // Reporting.
22 #include <tests/myratest.h>
23 
24 using namespace myra;
25 
26 namespace {
27 
28 // Test diagcat(A,B)
29 template<class Number> void test1(typename ReflectPrecision<Number>::type tolerance)
30  {
31  typedef typename ReflectPrecision<Number>::type Precision;
32  auto A = Matrix<Number>::random(6,6);
33  A.bottom(4).left(2).zero();
34  A.top(2).right(4).zero();
35  auto B = diagcat( A.top(2).left(2), A.bottom(4).right(4) );
36  Precision error = frobenius(A-B);
37  myra::out() << " |A - diagcat(a,a)| = " << error << std::endl;
38  REQUIRE(error < tolerance);
39  }
40 
41 // Test diagcat(a,b)
42 template<class Number> void test2(typename ReflectPrecision<Number>::type tolerance)
43  {
44  typedef typename ReflectPrecision<Number>::type Precision;
46  auto B = diagcat( A.first(2), A.last(4) );
47  Precision error = frobenius(A-B);
48  myra::out() << " |A - diagcat(...)| = " << error << std::endl;
49  REQUIRE(error < tolerance);
50  }
51 
52 } // namespace
53 
54 ADD_TEST("diagcat_Matrix","[dense]")
55  {
56  test1<NumberS>(1.0e-5f);
57  test1<NumberD>(1.0e-10);
58  test1<NumberC>(1.0e-5f);
59  test1<NumberZ>(1.0e-10);
60  }
61 
62 ADD_TEST("diagcat_DiagonalMatrix","[dense]")
63  {
64  test2<NumberS>(1.0e-5f);
65  test2<NumberD>(1.0e-10);
66  test2<NumberC>(1.0e-5f);
67  test2<NumberZ>(1.0e-10);
68  }
Interface class for representing subranges of DiagonalMatrix&#39;s.
Interface class for representing subranges of dense Matrix&#39;s.
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
static DiagonalMatrix< Number > random(int N)
Generates a random DiagonalMatrix of specified size.
Definition: DiagonalMatrix.cpp:217
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.
Container for a diagonal matrix, O(n) storage. Used by SVD, row/column scaling, etc.


Results: [PASS]

|A - diagcat(a,a)| = 0
|A - diagcat(a,a)| = 0
|A - diagcat(a,a)| = 0
|A - diagcat(a,a)| = 0


Go back to Summary of /test programs.