35#define BOOST_TEST_MODULE LinearAlgebraUnitTests test
36#include <boost/test/unit_test.hpp>
39#include <boost/test/tools/floating_point_comparison.hpp>
40#include <boost/test/unit_test.hpp>
47namespace StandardMatrixUnitTests
51 double buf1[] = {1, 4, 2, 5, 3, 6};
59 BOOST_CHECK_EQUAL(1, *m1_iter);
60 BOOST_CHECK_EQUAL(1, *m2_iter);
61 BOOST_CHECK_EQUAL(1, *m1_iter++);
62 BOOST_CHECK_EQUAL(1, *m2_iter++);
63 BOOST_CHECK_EQUAL(4, *m1_iter++);
64 BOOST_CHECK_EQUAL(4, *m2_iter++);
65 BOOST_CHECK_EQUAL(2, *m1_iter++);
66 BOOST_CHECK_EQUAL(2, *m2_iter++);
67 BOOST_CHECK_EQUAL(5, *m1_iter++);
68 BOOST_CHECK_EQUAL(5, *m2_iter++);
69 BOOST_CHECK_EQUAL(3, *m1_iter++);
70 BOOST_CHECK_EQUAL(3, *m2_iter++);
71 BOOST_CHECK_EQUAL(6, *m1_iter++);
72 BOOST_CHECK_EQUAL(6, *m2_iter++);
73 BOOST_CHECK(m1_iter == m1.end());
74 BOOST_CHECK(m2_iter == m2.end());
80 BOOST_CHECK_EQUAL(1, *m1_iter);
81 BOOST_CHECK_EQUAL(1, *m2_iter);
82 BOOST_CHECK_EQUAL(2, *(++m1_iter));
83 BOOST_CHECK_EQUAL(2, *(++m2_iter));
84 BOOST_CHECK_EQUAL(3, *(++m1_iter));
85 BOOST_CHECK_EQUAL(3, *(++m2_iter));
86 BOOST_CHECK_EQUAL(4, *(++m1_iter));
87 BOOST_CHECK_EQUAL(4, *(++m2_iter));
88 BOOST_CHECK_EQUAL(5, *(++m1_iter));
89 BOOST_CHECK_EQUAL(5, *(++m2_iter));
90 BOOST_CHECK_EQUAL(6, *(++m1_iter));
91 BOOST_CHECK_EQUAL(6, *(++m2_iter));
92 BOOST_CHECK(m1_iter != m1.end());
93 BOOST_CHECK(m2_iter != m2.end());
96 BOOST_CHECK(m1_iter == m1.end());
97 BOOST_CHECK(m2_iter == m2.end());
102 double buf1[] = {1, 4, 2, 5, 3, 6};
107 BOOST_CHECK_EQUAL(1.0, m1(0, 0));
108 BOOST_CHECK_EQUAL(1.0, m2(0, 0));
112 BOOST_CHECK_EQUAL(-4.5, m1(0, 0));
113 BOOST_CHECK_EQUAL(-4.5, m2(0, 0));
115 BOOST_CHECK_EQUAL(4.0, m1(1, 0));
116 BOOST_CHECK_EQUAL(4.0, m2(1, 0));
120 BOOST_CHECK_EQUAL(6.7, m1(1, 0));
121 BOOST_CHECK_EQUAL(6.7, m2(1, 0));
125namespace StandardMatrixOperationsUnitTests
129 double lhs_buf[] = {2.0, 4.0, 6.0, 8.0, 10.0, 12.0, 14.0, 16.0,
130 18.0, 20.0, 22.0, 24.0, 26.0, 28.0, 30.0, 32.0};
131 double rhs_buf[] = {3.0, 6.0, 9.0, 12.0, 15.0, 18.0, 21.0, 24.0,
132 27.0, 30.0, 33.0, 36.0, 39.0, 42.0, 45.0, 48.0};
135 std::shared_ptr<NekMatrix<NekMatrix<double>, ScaledMatrixTag>> lhs2;
136 std::shared_ptr<NekMatrix<NekMatrix<double>, BlockMatrixTag>> lhs3;
139 std::shared_ptr<NekMatrix<NekMatrix<double>, ScaledMatrixTag>> rhs2;
140 std::shared_ptr<NekMatrix<NekMatrix<double>, BlockMatrixTag>> rhs3;
145 double result_buf[] = {5, 10, 15, 20, 25, 30, 35, 40,
146 45, 50, 55, 60, 65, 70, 75, 80};
153 lhs1 + rhs_transposed;
155 double expected_result_with_one_operand_transposed[] = {
156 5, 19, 33, 47, 16, 30, 44, 58, 27, 41, 55, 69, 38, 52, 66, 80};
159 result_with_one_operand_transposed);
164 double lhs_buf[] = {2.0, 4.0, 6.0, 8.0, 10.0, 12.0, 14.0, 16.0,
165 18.0, 20.0, 22.0, 24.0, 26.0, 28.0, 30.0, 32.0};
166 double rhs_buf[] = {3.0, 6.0, 9.0, 12.0, 15.0, 18.0, 21.0, 24.0,
167 27.0, 30.0, 33.0, 36.0, 39.0, 42.0, 45.0, 48.0};
170 std::shared_ptr<NekMatrix<NekMatrix<double>, ScaledMatrixTag>> lhs2;
171 std::shared_ptr<NekMatrix<NekMatrix<double>, BlockMatrixTag>> lhs3;
174 std::shared_ptr<NekMatrix<NekMatrix<double>, ScaledMatrixTag>> rhs2;
175 std::shared_ptr<NekMatrix<NekMatrix<double>, BlockMatrixTag>> rhs3;
180 double result_buf[] = {-1, -2, -3, -4, -5, -6, -7, -8,
181 -9, -10, -11, -12, -13, -14, -15, -16};
189 double lhs_buf[] = {2.0, 4.0, 6.0, 8.0, 10.0, 12.0, 14.0, 16.0,
190 18.0, 20.0, 22.0, 24.0, 26.0, 28.0, 30.0, 32.0};
191 double middle_buf[] = {2.0, 4.0, 6.0, 8.0, 10.0, 12.0, 14.0, 16.0,
192 18.0, 20.0, 22.0, 24.0, 26.0, 28.0, 30.0, 32.0};
193 double rhs_buf[] = {3.0, 6.0, 9.0, 12.0, 15.0, 18.0, 21.0, 24.0,
194 27.0, 30.0, 33.0, 36.0, 39.0, 42.0, 45.0, 48.0};
206 double buf1[] = {1, 4, 2, 5, 3, 6};
207 double buf2[] = {10, 11, 12, 13, 14, 15};
209 double transposed_buf1[] = {1, 2, 3, 4, 5, 6};
211 double transposed_buf2[] = {10, 13, 11, 14, 12, 15};
213 double result_buf[] = {68, 167, 86, 212};
215 double transposed_result_buf[] = {62, 85, 108, 67, 92,
225 transposed_result_buf);
227 BOOST_CHECK_EQUAL(expected_result, m1 * m2);
228 BOOST_CHECK_EQUAL(expected_transposed_result,
229 transposed_m1 * transposed_m2);
232 BOOST_CHECK_EQUAL(expected_transposed_result, m1 * m2);
235 BOOST_CHECK_EQUAL(expected_result, m1 * m2);
239 BOOST_CHECK_EQUAL(expected_result, m1 * m2);
240 BOOST_CHECK_EQUAL(expected_transposed_result, tm1 * tm2);
246 double buf1[] = {1, 4, 2, 5, 3, 6};
247 double buf2[] = {10, 11, 12, 13, 14, 15};
249 double transposed_buf1[] = {1, 2, 3, 4, 5, 6};
251 double transposed_buf2[] = {10, 13, 11, 14, 12, 15};
262 BOOST_CHECK_EQUAL(tm1, expected_tm1);
263 BOOST_CHECK_EQUAL(tm2, expected_tm2);
265 BOOST_CHECK_EQUAL(m1(0, 1), 2);
266 BOOST_CHECK_EQUAL(tm1(1, 0), 2);
269 BOOST_CHECK_EQUAL(m1(0, 1), 89);
270 BOOST_CHECK_EQUAL(tm1(1, 0), 89);
272 BOOST_CHECK_EQUAL(m1.GetTransposeFlag(),
'N');
273 BOOST_CHECK_EQUAL(tm1.GetTransposeFlag(),
'T');
278 double buf1[] = {1, 4, 2, 5, 3, 6};
284 double m2_expected_result_buf[] = {2.0, 8.0, 4.0, 10.0, 6.0, 12.0};
286 double m3_expected_result_buf[] = {3.0, 12.0, 6.0, 15.0, 9.0, 18.0};
291 BOOST_CHECK_EQUAL(m2_expected_result, m2);
292 BOOST_CHECK_EQUAL(m3_expected_result, m3);
BOOST_AUTO_TEST_CASE(TestAddition)
BOOST_AUTO_TEST_CASE(TestIterators)
void GenerateMatrices(const NekMatrix< NumberType, StandardMatrixTag > &m1, NumberType scale, unsigned int blockRows, unsigned int blockColumns, std::shared_ptr< NekMatrix< NekMatrix< NumberType, StandardMatrixTag >, ScaledMatrixTag > > &m2, std::shared_ptr< NekMatrix< NekMatrix< NumberType >, BlockMatrixTag > > &m3)
void RunAllAddCombinations(const NekMatrix< NekDouble, StandardMatrixTag > &l1, const NekMatrix< NekMatrix< NekDouble, LhsScaledInnerMatrixType >, ScaledMatrixTag > &l2, const NekMatrix< NekMatrix< NekDouble, LhsBlockInnerMatrixType >, BlockMatrixTag > &l3, const NekMatrix< NekDouble, StandardMatrixTag > &r1, const NekMatrix< NekMatrix< NekDouble, RhsScaledInnerMatrixType >, ScaledMatrixTag > &r2, const NekMatrix< NekMatrix< NekDouble, RhsBlockInnerMatrixType >, BlockMatrixTag > &r3, const NekMatrix< NekDouble, StandardMatrixTag > &result)
NekMatrix< InnerMatrixType, BlockMatrixTag > Transpose(NekMatrix< InnerMatrixType, BlockMatrixTag > &rhs)
void RunAllSubCombinations(const NekMatrix< NekDouble, StandardMatrixTag > &l1, const NekMatrix< NekMatrix< NekDouble, LhsScaledInnerMatrixType >, ScaledMatrixTag > &l2, const NekMatrix< NekMatrix< NekDouble, LhsBlockInnerMatrixType >, BlockMatrixTag > &l3, const NekMatrix< NekDouble, StandardMatrixTag > &r1, const NekMatrix< NekMatrix< NekDouble, RhsScaledInnerMatrixType >, ScaledMatrixTag > &r2, const NekMatrix< NekMatrix< NekDouble, RhsBlockInnerMatrixType >, BlockMatrixTag > &r3, const NekMatrix< NekDouble, StandardMatrixTag > &result)