MyraMath
vertcat_Pattern


Source: tests/sparse/vertcat.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.
18 
19 // Algorithms.
22 
23 // Reporting.
24 #include <tests/myratest.h>
25 
26 using namespace myra;
27 
28 namespace {
29 
30 // SparseMatrix/SparseMatrixRange
31 
32 // Test vertcat(A,B)
33 template<class Number> void test1(typename ReflectPrecision<Number>::type tolerance)
34  {
35  typedef typename ReflectPrecision<Number>::type Precision;
36  auto A = SparseMatrix<Number>::random(20,20,50);
37  auto B = vertcat( A.top(10), A.bottom(10) );
38  Precision error = frobenius(A-B);
39  myra::out() << " |A - vertcat(a,a)| = " << error << std::endl;
40  REQUIRE(error < tolerance);
41  }
42 
43 #ifdef MYRAMATH_ENABLE_CPP11
44 
45 // Test vertcat({A,B,C})
46 template<class Number> void test2(typename ReflectPrecision<Number>::type tolerance)
47  {
48  typedef typename ReflectPrecision<Number>::type Precision;
49  auto A = SparseMatrix<Number>::random(20,20,50);
50  auto B = vertcat( A.add_const().rows({10,5,5}) );
51  Precision error = frobenius(A-B);
52  myra::out() << " |A - vertcat(...)| = " << error << std::endl;
53  REQUIRE(error < tolerance);
54  }
55 
56 #endif
57 
58 // Pattern/PatternRange
59 
60 // Test vertcat(A,B)
61 void test3()
62  {
63  auto A = Pattern::random(20,20,50);
64  auto B = vertcat( A.top(10), A.bottom(10) );
65  bool equal = (A==B);
66  myra::out() << " A == vertcat(a,a) : " << (equal?"true":"false") << std::endl;
67  REQUIRE(equal);
68  }
69 
70 
71 #ifdef MYRAMATH_ENABLE_CPP11
72 
73 // Test vertcat({A,B,C})
74 void test4()
75  {
76  auto A = Pattern::random(20,20,50);
77  auto B = vertcat( A.rows({10,5,5}) );
78  bool equal = (A==B);
79  myra::out() << " A == vertcat(...) : " << (equal?"true":"false") << std::endl;
80  REQUIRE(equal);
81  }
82 
83 #endif
84 
85 } // namespace
86 
87 ADD_TEST("vertcat_SparseMatrix","[sparse]")
88  {
89  test1<NumberS>(1.0e-5f);
90  test1<NumberD>(1.0e-10);
91  test1<NumberC>(1.0e-5f);
92  test1<NumberZ>(1.0e-10);
93  }
94 
95 #ifdef MYRAMATH_ENABLE_CPP11
96 
97 ADD_TEST("vertcat_SparseMatrix_cpp11","[sparse]")
98  {
99  test2<NumberS>(1.0e-5f);
100  test2<NumberD>(1.0e-10);
101  test2<NumberC>(1.0e-5f);
102  test2<NumberZ>(1.0e-10);
103  }
104 
105 #endif
106 
107 ADD_TEST("vertcat_Pattern","[sparse]")
108  { test3(); }
109 
110 #ifdef MYRAMATH_ENABLE_CPP11
111 
112 ADD_TEST("vertcat_Pattern_cpp11","[sparse]")
113  { test4(); }
114 
115 #endif
Routines to concatenate SparseMatrix&#39;s in top/bottom fashion.
Container of values, allows random (i) access.
static SparseMatrix< Number > random(int I, int J, int N)
Generates a random SparseMatrix with size IxJ and (approximately) N nonzeros.
Definition: SparseMatrix.cpp:493
General purpose compressed-sparse-column (CSC) container.
Definition: syntax.dox:1
static Pattern random(int I, int J, int N)
Generates a random Pattern with size IxJ and (approximately) N nonzeros.
Definition: Pattern.cpp:300
Range/Iterator types associated with Pattern.
Reflects Precision trait for a Number, scalar Number types should specialize it.
Definition: Number.h:33
Container class for a sparse nonzero pattern, used in reordering/symbolic analysis.
Returns frobenius norm of a SparseMatrix.
Range/Iterator types associated with SparseMatrix.
Interface class for representing subranges of contiguous int&#39;s.


Results: [PASS]

A == vertcat(a,a) : true


Go back to Summary of /test programs.