MyraMath
bothcat_Pattern


Source: tests/sparse/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.
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 bothcat(A,B,C,D)
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 = bothcat( A.top(12).left(6), A.top(12).right(14), A.bottom(8).left(6), A.bottom(8).right(14) );
38  Precision error = frobenius(A-B);
39  myra::out() << " |A - bothcat(a,a,a,a)| = " << error << std::endl;
40  REQUIRE(error < tolerance);
41  }
42 
43 #ifdef MYRAMATH_ENABLE_CPP11
44 
45 // Test bothcat({A,B,C,D,E,F})
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 = bothcat( A.add_const().windows({10,5,5},{6,8,6}) );
51  Precision error = frobenius(A-B);
52  myra::out() << " |A - bothcat(...)| = " << error << std::endl;
53  REQUIRE(error < tolerance);
54  }
55 
56 #endif
57 
58 // Pattern/PatternRange
59 
60 // Test bothcat(A,B,C,D)
61 void test3()
62  {
63  auto A = Pattern::random(20,20,50);
64  auto B = bothcat( A.top(12).left(6), A.top(12).right(14), A.bottom(8).left(6), A.bottom(8).right(14) );
65  bool equal = (A==B);
66  myra::out() << " A == bothcat(a,a,a,a) : " << (equal?"true":"false") << std::endl;
67  REQUIRE(equal);
68  }
69 
70 #ifdef MYRAMATH_ENABLE_CPP11
71 
72 // Test bothcat({A,B,C,D,E,F})
73 void test4()
74  {
75  auto A = Pattern::random(20,20,50);
76  auto B = bothcat( A.add_const().windows({10,5,5},{6,8,6}) );
77  bool equal = (A==B);
78  myra::out() << " A == bothcat(...) : " << (equal?"true":"false") << std::endl;
79  REQUIRE(equal);
80  }
81 
82 #endif
83 
84 } // namespace
85 
86 ADD_TEST("bothcat_SparseMatrix","[sparse]")
87  {
88  test1<NumberS>(1.0e-5f);
89  test1<NumberD>(1.0e-10);
90  test1<NumberC>(1.0e-5f);
91  test1<NumberZ>(1.0e-10);
92  }
93 
94 #ifdef MYRAMATH_ENABLE_CPP11
95 
96 ADD_TEST("bothcat_SparseMatrix_cpp11","[sparse]")
97  {
98  test2<NumberS>(1.0e-5f);
99  test2<NumberD>(1.0e-10);
100  test2<NumberC>(1.0e-5f);
101  test2<NumberZ>(1.0e-10);
102  }
103 
104 #endif
105 
106 ADD_TEST("bothcat_Pattern","[sparse]")
107  { test3(); }
108 
109 #ifdef MYRAMATH_ENABLE_CPP11
110 
111 ADD_TEST("bothcat_Pattern_cpp11","[sparse]")
112  { test4(); }
113 
114 #endif
115 
Routines to concatenate SparseMatrix&#39;s in two-by-two fashion.
Container of values, allows random (i,j) 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 == bothcat(a,a,a,a) : true


Go back to Summary of /test programs.