37#include <boost/test/tools/floating_point_comparison.hpp>
38#include <boost/test/unit_test.hpp>
43namespace MatrixUnitTests
48 double buf[] = {1.0, 3.0, 2.0, 4.0};
52 BOOST_CHECK_CLOSE(*m(0, 0), -2.0, .00001);
53 BOOST_CHECK_CLOSE(*m(0, 1), 1.0, .00001);
54 BOOST_CHECK_CLOSE(*m(1, 0), 3.0 / 2.0, .00001);
55 BOOST_CHECK_CLOSE(*m(1, 1), -1.0 / 2.0, .00001);
59 double buf[] = {1.7, 5.6, 9.1, -3.4, -2.0, 4.5, 7.8, 8.2, -2.5,
60 5.0, 9.0, 3.6, 7.3, .98, 1.0, -12.6, 2.9, 6.4,
61 .02, -4.0, -1, 1.7, 5.6, 2.98, 5.0};
65 BOOST_CHECK_CLOSE(*m(0, 0), 0.0005010995978, .000001);
66 BOOST_CHECK_CLOSE(*m(0, 1), -0.4704403712, .000001);
67 BOOST_CHECK_CLOSE(*m(0, 2), 0.2719063614, .000001);
68 BOOST_CHECK_CLOSE(*m(0, 3), -0.3941557805, .000001);
69 BOOST_CHECK_CLOSE(*m(0, 4), 0.09043166650, .000001);
71 BOOST_CHECK_CLOSE(*m(1, 0), -0.01087166322, .000001);
72 BOOST_CHECK_CLOSE(*m(1, 1), 0.3242048735, .000001);
73 BOOST_CHECK_CLOSE(*m(1, 2), -0.1605116333, .000001);
74 BOOST_CHECK_CLOSE(*m(1, 3), 0.09133673974, .000001);
75 BOOST_CHECK_CLOSE(*m(1, 4), 0.01293234281, .000001);
77 BOOST_CHECK_CLOSE(*m(2, 0), 0.06465598241, .000001);
78 BOOST_CHECK_CLOSE(*m(2, 1), 0.2593895742, .000001);
79 BOOST_CHECK_CLOSE(*m(2, 2), -0.09057233795, .000001);
80 BOOST_CHECK_CLOSE(*m(2, 3), 0.3106562459, .000001);
81 BOOST_CHECK_CLOSE(*m(2, 4), -0.1589713628, .000001);
83 BOOST_CHECK_CLOSE(*m(3, 0), -0.03464982687, .000001);
84 BOOST_CHECK_CLOSE(*m(3, 1), 0.2655177914, .000001);
85 BOOST_CHECK_CLOSE(*m(3, 2), -0.1016866584, .000001);
86 BOOST_CHECK_CLOSE(*m(3, 3), 0.2125363445, .000001);
87 BOOST_CHECK_CLOSE(*m(3, 4), -0.1099886183, .000001);
89 BOOST_CHECK_CLOSE(*m(4, 0), -0.02957895492, .000001);
90 BOOST_CHECK_CLOSE(*m(4, 1), -0.3518447037, .000001);
91 BOOST_CHECK_CLOSE(*m(4, 2), 0.2060393188, .000001);
92 BOOST_CHECK_CLOSE(*m(4, 3), -0.1411012255, .000001);
93 BOOST_CHECK_CLOSE(*m(4, 4), 0.1670437017, .000001);
102 double buf[] = {1.0, 2.0, 3.0, 4.0};
106 BOOST_CHECK_EQUAL(m(0, 0), 1.0 / 1.0);
107 BOOST_CHECK_EQUAL(m(1, 1), 1.0 / 2.0);
108 BOOST_CHECK_EQUAL(m(2, 2), 1.0 / 3.0);
109 BOOST_CHECK_EQUAL(m(3, 3), 1.0 / 4.0);
115 std::shared_ptr<Nektar::Matrix<double>> a(
117 std::shared_ptr<Nektar::NekMatrix<double>> b(
120 BOOST_CHECK_EQUAL(a->GetRows(), 3u);
121 BOOST_CHECK_EQUAL(a->GetColumns(), 4u);
122 BOOST_CHECK_EQUAL(a->GetSize()[0], 3u);
123 BOOST_CHECK_EQUAL(a->GetSize()[1], 4u);
125 BOOST_CHECK_EQUAL(b->GetRows(), 5u);
126 BOOST_CHECK_EQUAL(b->GetColumns(), 6u);
127 BOOST_CHECK_EQUAL(b->GetSize()[0], 5u);
128 BOOST_CHECK_EQUAL(b->GetSize()[1], 6u);
130 BOOST_CHECK_EQUAL(a->GetStorageType(),
eFULL);
131 BOOST_CHECK_EQUAL(b->GetStorageType(),
eFULL);
133 BOOST_CHECK_EQUAL(a->GetStorageSize(), 3 * 4);
134 BOOST_CHECK_EQUAL(b->GetStorageSize(), 5 * 6);
138 std::shared_ptr<Nektar::Matrix<double>> a(
140 std::shared_ptr<Nektar::NekMatrix<double>> b(
143 BOOST_CHECK_EQUAL(a->GetRows(), 3);
144 BOOST_CHECK_EQUAL(a->GetColumns(), 3);
145 BOOST_CHECK_EQUAL(a->GetSize()[0], 3);
146 BOOST_CHECK_EQUAL(a->GetSize()[1], 3);
148 BOOST_CHECK_EQUAL(b->GetRows(), 5);
149 BOOST_CHECK_EQUAL(b->GetColumns(), 5);
150 BOOST_CHECK_EQUAL(b->GetSize()[0], 5);
151 BOOST_CHECK_EQUAL(b->GetSize()[1], 5);
153 BOOST_CHECK_EQUAL(a->GetStorageType(),
eDIAGONAL);
154 BOOST_CHECK_EQUAL(b->GetStorageType(),
eDIAGONAL);
156 BOOST_CHECK_EQUAL(a->GetStorageSize(), 3);
157 BOOST_CHECK_EQUAL(b->GetStorageSize(), 5);
164 double data[] = {1.0, 89.0, 0.0, 45.12, 2.0, -12.3,
165 892.2532, 76.12, 3.0, -56.7, 211.22, 45.23};
169 BOOST_CHECK_EQUAL(m(0, 0), 1.0);
170 BOOST_CHECK_EQUAL(m(0, 1), 2.0);
171 BOOST_CHECK_EQUAL(m(0, 2), 3.0);
173 BOOST_CHECK_EQUAL(m(1, 0), 89.0);
174 BOOST_CHECK_EQUAL(m(1, 1), -12.3);
175 BOOST_CHECK_EQUAL(m(1, 2), -56.7);
177 BOOST_CHECK_EQUAL(m(2, 0), 0.0);
178 BOOST_CHECK_EQUAL(m(2, 1), 892.2532);
179 BOOST_CHECK_EQUAL(m(2, 2), 211.22);
181 BOOST_CHECK_EQUAL(m(3, 0), 45.12);
182 BOOST_CHECK_EQUAL(m(3, 1), 76.12);
183 BOOST_CHECK_EQUAL(m(3, 2), 45.23);
185#ifdef NEKTAR_FULLDEBUG
191 std::shared_ptr<Nektar::Matrix<double>> m1(
193 std::shared_ptr<Nektar::NekMatrix<double>> m2(
196 BOOST_CHECK_EQUAL((*m1)(0, 0), 1.0);
197 BOOST_CHECK_EQUAL((*m1)(0, 1), 2.0);
198 BOOST_CHECK_EQUAL((*m1)(0, 2), 3.0);
200 BOOST_CHECK_EQUAL((*m1)(1, 0), 89.0);
201 BOOST_CHECK_EQUAL((*m1)(1, 1), -12.3);
202 BOOST_CHECK_EQUAL((*m1)(1, 2), -56.7);
204 BOOST_CHECK_EQUAL((*m1)(2, 0), 0.0);
205 BOOST_CHECK_EQUAL((*m1)(2, 1), 892.2532);
206 BOOST_CHECK_EQUAL((*m1)(2, 2), 211.22);
208 BOOST_CHECK_EQUAL((*m1)(3, 0), 45.12);
209 BOOST_CHECK_EQUAL((*m1)(3, 1), 76.12);
210 BOOST_CHECK_EQUAL((*m1)(3, 2), 45.23);
212#ifdef NEKTAR_FULLDEBUG
218 BOOST_CHECK_EQUAL((*m2)(0, 0), 1.0);
219 BOOST_CHECK_EQUAL((*m2)(0, 1), 2.0);
220 BOOST_CHECK_EQUAL((*m2)(0, 2), 3.0);
222 BOOST_CHECK_EQUAL((*m2)(1, 0), 89.0);
223 BOOST_CHECK_EQUAL((*m2)(1, 1), -12.3);
224 BOOST_CHECK_EQUAL((*m2)(1, 2), -56.7);
226 BOOST_CHECK_EQUAL((*m2)(2, 0), 0.0);
227 BOOST_CHECK_EQUAL((*m2)(2, 1), 892.2532);
228 BOOST_CHECK_EQUAL((*m2)(2, 2), 211.22);
230 BOOST_CHECK_EQUAL((*m2)(3, 0), 45.12);
231 BOOST_CHECK_EQUAL((*m2)(3, 1), 76.12);
232 BOOST_CHECK_EQUAL((*m2)(3, 2), 45.23);
234#ifdef NEKTAR_FULLDEBUG
244 double data[] = {8.9, 3.4, 5.7};
246 std::shared_ptr<Nektar::Matrix<double>> m2(
248 std::shared_ptr<Nektar::NekMatrix<double>> m3(
251 BOOST_CHECK_EQUAL(m1(0, 0), 8.9);
252 BOOST_CHECK_EQUAL((*m2)(0, 0), 8.9);
253 BOOST_CHECK_EQUAL((*m3)(0, 0), 8.9);
255 BOOST_CHECK_EQUAL(m1(0, 1), 0.0);
256 BOOST_CHECK_EQUAL((*m2)(0, 1), 0.0);
257 BOOST_CHECK_EQUAL((*m3)(0, 1), 0.0);
259 BOOST_CHECK_EQUAL(m1(0, 2), 0.0);
260 BOOST_CHECK_EQUAL((*m2)(0, 2), 0.0);
261 BOOST_CHECK_EQUAL((*m3)(0, 2), 0.0);
263 BOOST_CHECK_EQUAL(m1(1, 0), 0.0);
264 BOOST_CHECK_EQUAL((*m2)(1, 0), 0.0);
265 BOOST_CHECK_EQUAL((*m3)(1, 0), 0.0);
267 BOOST_CHECK_EQUAL(m1(1, 1), 3.4);
268 BOOST_CHECK_EQUAL((*m2)(1, 1), 3.4);
269 BOOST_CHECK_EQUAL((*m3)(1, 1), 3.4);
271 BOOST_CHECK_EQUAL(m1(1, 2), 0.0);
272 BOOST_CHECK_EQUAL((*m2)(1, 2), 0.0);
273 BOOST_CHECK_EQUAL((*m3)(1, 2), 0.0);
275 BOOST_CHECK_EQUAL(m1(2, 0), 0.0);
276 BOOST_CHECK_EQUAL((*m2)(2, 0), 0.0);
277 BOOST_CHECK_EQUAL((*m3)(2, 0), 0.0);
279 BOOST_CHECK_EQUAL(m1(2, 1), 0.0);
280 BOOST_CHECK_EQUAL((*m2)(2, 1), 0.0);
281 BOOST_CHECK_EQUAL((*m3)(2, 1), 0.0);
283 BOOST_CHECK_EQUAL(m1(2, 2), 5.7);
284 BOOST_CHECK_EQUAL((*m2)(2, 2), 5.7);
285 BOOST_CHECK_EQUAL((*m3)(2, 2), 5.7);
287#ifdef NEKTAR_FULLDEBUG
304 double data[] = {1.0, 3.0, 5.0, 2.0, 4.0, 6.0};
306 std::shared_ptr<Nektar::Matrix<double>> m2(
308 std::shared_ptr<Nektar::NekMatrix<double>> m3(
311 m1.SetValue(0, 0, -1.0);
312 m2->SetValue(1, 1, -2.0);
313 m3->SetValue(2, 1, -3.0);
315 BOOST_CHECK_EQUAL(m1(0, 0), -1.0);
316 BOOST_CHECK_EQUAL(m1(0, 1), 2.0);
317 BOOST_CHECK_EQUAL(m1(1, 0), 3.0);
318 BOOST_CHECK_EQUAL(m1(1, 1), 4.0);
319 BOOST_CHECK_EQUAL(m1(2, 0), 5.0);
320 BOOST_CHECK_EQUAL(m1(2, 1), 6.0);
322 BOOST_CHECK_EQUAL((*m2)(0, 0), 1.0);
323 BOOST_CHECK_EQUAL((*m2)(0, 1), 2.0);
324 BOOST_CHECK_EQUAL((*m2)(1, 0), 3.0);
325 BOOST_CHECK_EQUAL((*m2)(1, 1), -2.0);
326 BOOST_CHECK_EQUAL((*m2)(2, 0), 5.0);
327 BOOST_CHECK_EQUAL((*m2)(2, 1), 6.0);
329 BOOST_CHECK_EQUAL((*m3)(0, 0), 1.0);
330 BOOST_CHECK_EQUAL((*m3)(0, 1), 2.0);
331 BOOST_CHECK_EQUAL((*m3)(1, 0), 3.0);
332 BOOST_CHECK_EQUAL((*m3)(1, 1), 4.0);
333 BOOST_CHECK_EQUAL((*m3)(2, 0), 5.0);
334 BOOST_CHECK_EQUAL((*m3)(2, 1), -3.0);
340 double data[] = {8.9, 3.4, 5.7};
342 std::shared_ptr<Nektar::Matrix<double>> m2(
344 std::shared_ptr<Nektar::NekMatrix<double>> m3(
347 m1.SetValue(0, 0, 1.0);
348 m2->SetValue(1, 1, 2.0);
349 m3->SetValue(2, 2, 3.0);
351 BOOST_CHECK_EQUAL(m1.GetStorageType(),
eDIAGONAL);
352 BOOST_CHECK_EQUAL(m2->GetStorageType(),
eDIAGONAL);
353 BOOST_CHECK_EQUAL(m3->GetStorageType(),
eDIAGONAL);
355 BOOST_CHECK_EQUAL(m1(0, 0), 1.0);
356 BOOST_CHECK_EQUAL(m1(1, 1), 3.4);
357 BOOST_CHECK_EQUAL(m1(2, 2), 5.7);
359 BOOST_CHECK_EQUAL((*m2)(0, 0), 8.9);
360 BOOST_CHECK_EQUAL((*m2)(1, 1), 2.0);
361 BOOST_CHECK_EQUAL((*m2)(2, 2), 5.7);
363 BOOST_CHECK_EQUAL((*m3)(0, 0), 8.9);
364 BOOST_CHECK_EQUAL((*m3)(1, 1), 3.4);
365 BOOST_CHECK_EQUAL((*m3)(2, 2), 3.0);
367#ifdef NEKTAR_FULLDEBUG
384 double lhs_data[] = {1.0, 4.0, 2.0, 5.0, 3.0, 6.0};
385 double rhs_data[] = {10.0, 13.0, 11.0, 14.0, 12.0, 15.0};
391 BOOST_CHECK_EQUAL(result.GetRows(), 2);
392 BOOST_CHECK_EQUAL(result.GetColumns(), 3);
393 BOOST_CHECK_EQUAL(result.GetStorageType(),
eFULL);
394 BOOST_CHECK_EQUAL(result(0, 0), 11.0);
395 BOOST_CHECK_EQUAL(result(0, 1), 13.0);
396 BOOST_CHECK_EQUAL(result(0, 2), 15.0);
397 BOOST_CHECK_EQUAL(result(1, 0), 17.0);
398 BOOST_CHECK_EQUAL(result(1, 1), 19.0);
399 BOOST_CHECK_EQUAL(result(1, 2), 21.0);
412 double buf[] = {1.0, 4.0, 7.0, 10.0, 2.0, 5.0,
413 8.0, 11.0, 3.0, 6.0, 9.0, 12.0};
416 BOOST_CHECK(dynamic_matrix.GetRows() == 4);
417 BOOST_CHECK(dynamic_matrix.GetColumns() == 3);
419 for (
unsigned int i = 0; i < 4; ++i)
421 for (
unsigned int j = 0; j < 3; ++j)
423 BOOST_CHECK(dynamic_matrix(i, j) == buf[4 * j + i]);
433 double buf[] = {1.0, 4.0, 7.0, 2.0, 5.0, 8.0, 3.0, 6.0, 9.0};
438 for (
unsigned int i = 0; i < 3; ++i)
440 for (
unsigned int j = 0; j < 3; ++j)
442 BOOST_CHECK(m3(i, j) == buf[3 * j + i] + buf[3 * j + i]);
450 for (
unsigned int i = 0; i < 3; ++i)
452 for (
unsigned int j = 0; j < 3; ++j)
454 BOOST_CHECK(m6(i, j) == buf[3 * j + i] + buf[3 * j + i]);
461 double buf1[] = {1, 4, 7, 2, 5, 8, 3, 6, 9};
462 double buf2[] = {10, 15, 19, 11, 16, 20, 12, 17, 21};
468 BOOST_CHECK(result.GetRows() == 3);
469 BOOST_CHECK(result.GetColumns() == 3);
471 double epsilon = 1e-12;
472 BOOST_CHECK_CLOSE(*result(0, 0), 97.0, epsilon);
473 BOOST_CHECK_CLOSE(*result(0, 1), 103.0, epsilon);
474 BOOST_CHECK_CLOSE(*result(0, 2), 109.0, epsilon);
476 BOOST_CHECK_CLOSE(*result(1, 0), 229.0, epsilon);
477 BOOST_CHECK_CLOSE(*result(1, 1), 244.0, epsilon);
478 BOOST_CHECK_CLOSE(*result(1, 2), 259.0, epsilon);
480 BOOST_CHECK_CLOSE(*result(2, 0), 361.0, epsilon);
481 BOOST_CHECK_CLOSE(*result(2, 1), 385.0, epsilon);
482 BOOST_CHECK_CLOSE(*result(2, 2), 409.0, epsilon);
486 double buf1[] = {1, 4, 7, 2, 5, 8, 3, 6, 9};
487 double buf2[] = {10, 15, 19, 11, 16, 20, 12, 17, 21, 14, 18, 22};
493 BOOST_CHECK(result.GetRows() == 3);
494 BOOST_CHECK(result.GetColumns() == 4);
496 double epsilon = 1e-12;
497 BOOST_CHECK_CLOSE(*result(0, 0), 97.0, epsilon);
498 BOOST_CHECK_CLOSE(*result(0, 1), 103.0, epsilon);
499 BOOST_CHECK_CLOSE(*result(0, 2), 109.0, epsilon);
500 BOOST_CHECK_CLOSE(*result(0, 3), 116.0, epsilon);
502 BOOST_CHECK_CLOSE(*result(1, 0), 229.0, epsilon);
503 BOOST_CHECK_CLOSE(*result(1, 1), 244.0, epsilon);
504 BOOST_CHECK_CLOSE(*result(1, 2), 259.0, epsilon);
505 BOOST_CHECK_CLOSE(*result(1, 3), 278.0, epsilon);
507 BOOST_CHECK_CLOSE(*result(2, 0), 361.0, epsilon);
508 BOOST_CHECK_CLOSE(*result(2, 1), 385.0, epsilon);
509 BOOST_CHECK_CLOSE(*result(2, 2), 409.0, epsilon);
510 BOOST_CHECK_CLOSE(*result(2, 3), 440.0, epsilon);
BOOST_AUTO_TEST_CASE(TestFullMatrixInversion)
void RedirectCerrIfNeeded()
BOOST_AUTO_TEST_CASE(TestGaussInt)