Tests the classes in SimpleFits.h.
More...
#include <cmath>
#include <limits>
#include <array>
#include <algorithm>
#include <random>
#include <string>
#include <iostream>
#include "boost/test/unit_test.hpp"
#include "lardata/Utilities/FastMatrixMathHelper.h"
Go to the source code of this file.
Tests the classes in SimpleFits.h.
- Author
- Gianluca Petrillo (petri.nosp@m.llo@.nosp@m.fnal..nosp@m.gov)
- Date
- 20141229
- Version
- 1.0
- See also
- SimpleFits.h
See http://www.boost.org/libs/test for the Boost test library home page.
Timing: not given yet
Definition in file FastMatrixMath_test.cc.
#define BOOST_TEST_MODULE ( FastMatrixMath_test ) |
BOOST_AUTO_TEST_CASE |
( |
Matrix2x2RealTest |
| ) |
|
Definition at line 415 of file FastMatrixMath_test.cc.
416 TestMatrix2x2<double>();
417 TestSymmetricMatrix2x2<double>();
419 TestMatrix_N<double, 2>();
420 TestNullMatrix<double, 2>();
BOOST_AUTO_TEST_CASE |
( |
Matrix3x3RealTest |
| ) |
|
Definition at line 423 of file FastMatrixMath_test.cc.
424 TestMatrix3x3_1<double>();
425 TestMatrix3x3_2<double>();
426 TestSymmetricMatrix3x3<double>();
428 TestMatrix_N<double, 3>();
429 TestNullMatrix<double, 3>();
BOOST_AUTO_TEST_CASE |
( |
Matrix4x4RealTest |
| ) |
|
Definition at line 432 of file FastMatrixMath_test.cc.
433 TestMatrix4x4_1<double>();
434 TestMatrix4x4_2<double>();
435 TestSymmetricMatrix4x4<double>();
437 TestMatrix_N<double, 4>();
438 TestNullMatrix<double, 4>();
template<typename Array >
void CheckInverse |
( |
Array const & |
a, |
|
|
Array const & |
a_inv |
|
) |
| |
Definition at line 92 of file FastMatrixMath_test.cc.
94 const size_t Dim = size_t(std::sqrt(
a.size()));
95 using Data_t =
typename Array::value_type;
97 BOOST_TEST(
a.size() == a_inv.size());
99 for (
size_t r = 0;
r < Dim; ++
r) {
100 for (
size_t c = 0;
c < Dim; ++
c) {
102 for (
size_t k = 0;
k < Dim; ++
k) {
103 v +=
a[
r * Dim +
k] * a_inv[
k * Dim +
c];
105 if (
r ==
c) BOOST_TEST(v == Data_t(1), 0.01%
tolerance());
template<typename Array >
void CheckSymmetric |
( |
Array const & |
m | ) |
|
Definition at line 81 of file FastMatrixMath_test.cc.
82 const size_t Dim = size_t(std::sqrt(
m.size()));
84 for (
size_t r = 1;
r < Dim; ++
r)
85 for (
size_t c =
r + 1;
c < Dim; ++
c)
template<typename Array >
void MatrixTest |
( |
Array const & |
mat | ) |
|
Definition at line 114 of file FastMatrixMath_test.cc.
116 using Data_t =
typename Array::value_type;
119 static_assert((Dim >= 1) && (Dim <= 4),
"Dimension not supported");
121 using FastMatrixOperations
124 Array mat_inv = FastMatrixOperations::InvertMatrix(mat);
125 PrintMatrix(std::cout, mat_inv,
"Alleged inverse matrix");
constexpr unsigned int static_sqrt(unsigned int n)
Provides "fast" matrix operations.
void PrintMatrix(std::ostream &out, Array const &m, std::string name="Matrix")
void CheckInverse(Array const &a, Array const &a_inv)
template<typename Array >
void MatrixTest |
( |
Array const & |
mat, |
|
|
typename Array::value_type |
det |
|
) |
| |
Definition at line 132 of file FastMatrixMath_test.cc.
134 using Data_t =
typename Array::value_type;
137 static_assert((Dim >= 1) && (Dim <= 4),
"Dimension not supported");
139 using FastMatrixOperations
142 const Data_t my_det = FastMatrixOperations::Determinant(mat);
145 if (std::isnormal(det)) {
146 Array mat_inv = FastMatrixOperations::InvertMatrix(mat, det);
147 PrintMatrix(std::cout, mat_inv,
"Alleged inverse matrix");
constexpr unsigned int static_sqrt(unsigned int n)
Provides "fast" matrix operations.
void PrintMatrix(std::ostream &out, Array const &m, std::string name="Matrix")
void CheckInverse(Array const &a, Array const &a_inv)
template<typename Array >
void PrintMatrix |
( |
std::ostream & |
out, |
|
|
Array const & |
m, |
|
|
std::string |
name = "Matrix" |
|
) |
| |
Definition at line 63 of file FastMatrixMath_test.cc.
65 #ifdef FASTMATRIXMATH_TEST_DEBUG 66 const size_t Dim = size_t(std::sqrt(
m.size()));
68 out <<
name <<
" " << Dim <<
"x" << Dim <<
":";
69 for (
size_t r = 0;
r < Dim; ++
r) {
71 for (
size_t c = 0;
c < Dim; ++
c)
72 out <<
" " <<
m[
r * Dim +
c];
76 #endif // FASTMATRIXMATH_TEST_DEBUG
QTextStream & endl(QTextStream &s)
constexpr unsigned int static_sqrt |
( |
unsigned int |
n | ) |
|
template<typename Array >
void SymmetricMatrixTest |
( |
Array const & |
mat | ) |
|
Definition at line 154 of file FastMatrixMath_test.cc.
156 using Data_t =
typename Array::value_type;
159 static_assert((Dim >= 1) && (Dim <= 4),
"Dimension not supported");
161 using FastMatrixOperations
166 Array mat_inv = FastMatrixOperations::InvertSymmetricMatrix(mat);
167 PrintMatrix(std::cout, mat_inv,
"Alleged inverse matrix");
constexpr unsigned int static_sqrt(unsigned int n)
void CheckSymmetric(Array const &m)
Provides "fast" matrix operations.
void PrintMatrix(std::ostream &out, Array const &m, std::string name="Matrix")
void CheckInverse(Array const &a, Array const &a_inv)
template<typename Array >
void SymmetricMatrixTest |
( |
Array const & |
mat, |
|
|
typename Array::value_type |
det |
|
) |
| |
Definition at line 174 of file FastMatrixMath_test.cc.
176 using Data_t =
typename Array::value_type;
179 static_assert((Dim >= 1) && (Dim <= 4),
"Dimension not supported");
181 using FastMatrixOperations
184 const Data_t my_det = FastMatrixOperations::Determinant(mat);
187 if (std::isnormal(det)) {
188 Array mat_inv = FastMatrixOperations::InvertSymmetricMatrix(mat, det);
189 PrintMatrix(std::cout, mat_inv,
"Alleged inverse matrix");
constexpr unsigned int static_sqrt(unsigned int n)
void CheckSymmetric(Array const &m)
Provides "fast" matrix operations.
void PrintMatrix(std::ostream &out, Array const &m, std::string name="Matrix")
void CheckInverse(Array const &a, Array const &a_inv)
Definition at line 198 of file FastMatrixMath_test.cc.
200 constexpr
unsigned int Dim = 2;
204 std::array<Data_t, Dim*Dim> matrix = {{
205 Data_t(2), Data_t(3),
208 const Data_t true_det = Data_t(-10);
void PrintMatrix(std::ostream &out, Array const &m, std::string name="Matrix")
void MatrixTest(Array const &mat)
Definition at line 235 of file FastMatrixMath_test.cc.
238 constexpr
unsigned int Dim = 3;
242 std::array<Data_t, Dim*Dim> matrix = {{
243 Data_t(2), Data_t(0), Data_t(3),
244 Data_t(0), Data_t(3), Data_t(0),
245 Data_t(4), Data_t(0), Data_t(1),
247 const Data_t true_det = Data_t(-30);
void PrintMatrix(std::ostream &out, Array const &m, std::string name="Matrix")
void MatrixTest(Array const &mat)
Definition at line 256 of file FastMatrixMath_test.cc.
259 constexpr
unsigned int Dim = 3;
263 std::array<Data_t, Dim*Dim> matrix = {{
264 Data_t(2), Data_t(4), Data_t(3),
265 Data_t(0), Data_t(3), Data_t(0),
266 Data_t(4), Data_t(0), Data_t(1),
268 const Data_t true_det = Data_t(-30);
void PrintMatrix(std::ostream &out, Array const &m, std::string name="Matrix")
void MatrixTest(Array const &mat)
Definition at line 299 of file FastMatrixMath_test.cc.
302 constexpr
unsigned int Dim = 4;
306 std::array<Data_t, Dim*Dim> matrix = {{
307 Data_t(2), Data_t(0), Data_t(3), Data_t(0),
308 Data_t(0), Data_t(3), Data_t(0), Data_t(6),
309 Data_t(4), Data_t(0), Data_t(1), Data_t(0),
310 Data_t(0), Data_t(2), Data_t(0), Data_t(7)
312 const Data_t true_det = Data_t(-90);
void PrintMatrix(std::ostream &out, Array const &m, std::string name="Matrix")
void MatrixTest(Array const &mat)
Definition at line 321 of file FastMatrixMath_test.cc.
324 constexpr
unsigned int Dim = 4;
328 std::array<Data_t, Dim*Dim> matrix = {{
329 Data_t(2), Data_t(0), Data_t(3), Data_t(0),
330 Data_t(5), Data_t(3), Data_t(0), Data_t(6),
331 Data_t(4), Data_t(0), Data_t(1), Data_t(0),
332 Data_t(3), Data_t(2), Data_t(0), Data_t(7)
334 const Data_t true_det = Data_t(-90);
void PrintMatrix(std::ostream &out, Array const &m, std::string name="Matrix")
void MatrixTest(Array const &mat)
template<typename T , unsigned int Dim>
void TestMatrix_N |
( |
unsigned int |
N = 100 | ) |
|
Definition at line 343 of file FastMatrixMath_test.cc.
347 std::default_random_engine engine;
348 std::uniform_real_distribution<Data_t> uniform(Data_t(-10.), Data_t(10.));
350 std::array<Data_t, Dim*Dim> matrix;
351 for (
unsigned int i = 0; i <
N; ++i) {
353 std::generate(matrix.begin(), matrix.end(),
354 [&engine, &uniform] {
return uniform(engine); }
void PrintMatrix(std::ostream &out, Array const &m, std::string name="Matrix")
void MatrixTest(Array const &mat)
template<typename T , unsigned int Dim>
Definition at line 365 of file FastMatrixMath_test.cc.
369 std::array<Data_t, Dim*Dim> matrix;
370 matrix.fill(Data_t(0));
374 PrintMatrix(std::cout, matrix,
"Empty symmetric matrix");
void SymmetricMatrixTest(Array const &mat)
void PrintMatrix(std::ostream &out, Array const &m, std::string name="Matrix")
void MatrixTest(Array const &mat)
template<typename T >
void TestSymmetricMatrix2x2 |
( |
| ) |
|
Definition at line 216 of file FastMatrixMath_test.cc.
218 constexpr
unsigned int Dim = 2;
222 std::array<Data_t, Dim*Dim> matrix = {{
223 Data_t(2), Data_t(3),
226 const Data_t true_det = Data_t(-7);
228 PrintMatrix(std::cout, matrix,
"Symmetric matrix");
void SymmetricMatrixTest(Array const &mat)
void PrintMatrix(std::ostream &out, Array const &m, std::string name="Matrix")
template<typename T >
void TestSymmetricMatrix3x3 |
( |
| ) |
|
Definition at line 278 of file FastMatrixMath_test.cc.
281 constexpr
unsigned int Dim = 3;
285 std::array<Data_t, Dim*Dim> matrix = {{
286 Data_t(2), Data_t(0), Data_t(3),
287 Data_t(0), Data_t(3), Data_t(0),
288 Data_t(3), Data_t(0), Data_t(1),
290 const Data_t true_det = Data_t(-21);
292 PrintMatrix(std::cout, matrix,
"Symmetric matrix");
void SymmetricMatrixTest(Array const &mat)
void PrintMatrix(std::ostream &out, Array const &m, std::string name="Matrix")
template<typename T >
void TestSymmetricMatrix4x4 |
( |
| ) |
|
Definition at line 382 of file FastMatrixMath_test.cc.
385 constexpr
unsigned int Dim = 4;
389 std::array<Data_t, Dim*Dim> matrix = {{
390 Data_t(2), Data_t(0), Data_t(3), Data_t(0),
391 Data_t(0), Data_t(3), Data_t(0), Data_t(2),
392 Data_t(3), Data_t(0), Data_t(1), Data_t(0),
393 Data_t(0), Data_t(2), Data_t(0), Data_t(7)
395 const Data_t true_det = Data_t(-119);
397 PrintMatrix(std::cout, matrix,
"Symmetric matrix");
void SymmetricMatrixTest(Array const &mat)
void PrintMatrix(std::ostream &out, Array const &m, std::string name="Matrix")