38 #define BOOST_TEST_MODULE ( FastMatrixMath_test )
39 #include "boost/test/unit_test.hpp"
57 std::numeric_limits<unsigned int>::max()))));
61 template <
typename Array>
63 (std::ostream& out, Array
const&
m, std::string
name =
"Matrix")
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
80 template <
typename Array>
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)
86 BOOST_TEST(m[
r * Dim + c] == m[
r * Dim + c], 0.001%
tolerance());
91 template <
typename Array>
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());
113 template <
typename Array>
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);
131 template <
typename Array>
132 void MatrixTest(Array
const& mat,
typename Array::value_type det) {
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);
153 template <
typename Array>
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);
173 template <
typename Array>
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);
197 template <
typename T>
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);
215 template <
typename T>
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);
234 template <
typename T>
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);
255 template <
typename T>
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);
277 template <
typename T>
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);
298 template <
typename T>
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);
320 template <
typename T>
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);
342 template <
typename T,
unsigned int Dim>
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); }
364 template <
typename T,
unsigned int Dim>
369 std::array<Data_t, Dim*Dim> matrix;
370 matrix.fill(Data_t(0));
381 template <
typename T>
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);
416 TestMatrix2x2<double>();
417 TestSymmetricMatrix2x2<double>();
419 TestMatrix_N<double, 2>();
420 TestNullMatrix<double, 2>();
424 TestMatrix3x3_1<double>();
425 TestMatrix3x3_2<double>();
426 TestSymmetricMatrix3x3<double>();
428 TestMatrix_N<double, 3>();
429 TestNullMatrix<double, 3>();
433 TestMatrix4x4_1<double>();
434 TestMatrix4x4_2<double>();
435 TestSymmetricMatrix4x4<double>();
437 TestMatrix_N<double, 4>();
438 TestNullMatrix<double, 4>();
void TestSymmetricMatrix4x4()
constexpr unsigned int static_sqrt(unsigned int n)
void TestSymmetricMatrix3x3()
void CheckSymmetric(Array const &m)
void SymmetricMatrixTest(Array const &mat)
tuple m
now if test mode generate materials, CRT shell, world, gdml header else just generate CRT shell for u...
Classes with hard-coded (hence "fast") matrix math.
Provides "fast" matrix operations.
void TestSymmetricMatrix2x2()
void PrintMatrix(std::ostream &out, Array const &m, std::string name="Matrix")
void MatrixTest(Array const &mat)
process_name largeant stream1 can override from command line with o or output physics producers generator N
void TestMatrix_N(unsigned int N=100)
void CheckInverse(Array const &a, Array const &a_inv)
BEGIN_PROLOG could also be cout