13 #ifndef FASTMATRIXMATHHELPER_H 14 #define FASTMATRIXMATHHELPER_H 1 33 template <
typename T,
unsigned int DIM>
37 static constexpr
unsigned int Dim = DIM;
86 template <
typename T,
unsigned int DIM>
104 {
return InvertMatrix(mat, Determinant(mat)); }
108 {
return InvertSymmetricMatrix(mat, Determinant(mat)); }
126 template <
unsigned int NCols>
128 {
return row * NCols + col; }
130 template <
unsigned int N>
132 static constexpr
size_t index(
unsigned int row,
unsigned int col)
133 {
return MatrixIndex<N>(
row, col); }
136 template <
typename T,
unsigned int N,
142 static T compute(
T const*
data);
147 template <
typename T,
unsigned int N,
148 unsigned int R,
unsigned int C 152 static_assert(R < N,
"invalid row index specified");
153 static_assert(
C < N,
"invalid column index specified");
160 template <
typename T,
unsigned int N,
161 unsigned int R1,
unsigned int R2,
162 unsigned int C1,
unsigned int C2 168 static_assert(R1 < N,
"invalid row index specified");
169 static_assert(R2 < N,
"invalid row index specified");
170 static_assert(C1 < N,
"invalid column index specified");
171 static_assert(
C2 < N,
"invalid column index specified");
173 static constexpr
T sqr(
T v) {
return v*v; }
188 template <
typename T,
unsigned int N,
189 unsigned int R1,
unsigned int R2,
unsigned int R3,
190 unsigned int C1,
unsigned int C2,
unsigned int C3 196 static_assert(R1 < N,
"invalid row index specified");
197 static_assert(R2 < N,
"invalid row index specified");
198 static_assert(R3 < N,
"invalid row index specified");
199 static_assert(C1 < N,
"invalid column index specified");
200 static_assert(C2 < N,
"invalid column index specified");
201 static_assert(
C3 < N,
"invalid column index specified");
203 unsigned int sR1,
unsigned int sR2,
204 unsigned int sC1,
unsigned int sC2
219 template <
typename T,
unsigned int N,
220 unsigned int R1,
unsigned int R2,
unsigned int R3,
unsigned int R4,
221 unsigned int C1,
unsigned int C2,
unsigned int C3,
unsigned int C4 227 static_assert(R1 < N,
"invalid row index specified");
228 static_assert(R2 < N,
"invalid row index specified");
229 static_assert(R3 < N,
"invalid row index specified");
230 static_assert(R4 < N,
"invalid row index specified");
231 static_assert(C1 < N,
"invalid column index specified");
232 static_assert(C2 < N,
"invalid column index specified");
233 static_assert(C3 < N,
"invalid column index specified");
234 static_assert(
C4 < N,
"invalid column index specified");
236 unsigned int sR1,
unsigned int sR2,
unsigned int sR3,
237 unsigned int sC1,
unsigned int sC2,
unsigned int sC3
253 template <
typename T>
258 static constexpr
unsigned int Dim = Base_t::Dim;
275 {
return InvertMatrix(mat, Determinant(mat)); }
279 {
return InvertSymmetricMatrix(mat, Determinant(mat)); }
285 template <
typename T>
290 static constexpr
unsigned int Dim = Base_t::Dim;
310 {
return InvertMatrix(mat, Determinant(mat)); }
314 {
return InvertSymmetricMatrix(mat, Determinant(mat)); }
320 template <
typename T>
325 static constexpr
unsigned int Dim = Base_t::Dim;
345 {
return InvertMatrix(mat, Determinant(mat)); }
349 {
return InvertSymmetricMatrix(mat, Determinant(mat)); }
360 template <
typename T,
unsigned int DIM>
366 Data_t const* mat_row = mat.data();
367 for (
size_t r = 0;
r <
Dim; ++
r) {
369 for (
size_t c = 0;
c <
Dim; ++
c)
370 elem += *(mat_row++) * vec[
c];
377 template <
typename T>
382 Inverse[0 *
Dim + 0] = mat[1 *
Dim + 1] / det;
383 Inverse[0 *
Dim + 1] = - mat[0 *
Dim + 1] / det;
384 Inverse[1 *
Dim + 0] = - mat[1 *
Dim + 0] / det;
385 Inverse[1 *
Dim + 1] = mat[0 *
Dim + 0] / det;
390 template <
typename T>
395 Inverse[0 *
Dim + 0] = mat[1 *
Dim + 1] / det;
396 Inverse[0 *
Dim + 1] =
397 Inverse[1 *
Dim + 0] = - mat[1 *
Dim + 0] / det;
398 Inverse[1 *
Dim + 1] = mat[0 *
Dim + 0] / det;
403 template <
typename T>
430 template <
typename T>
441 Inverse[0 *
Dim + 1] =
443 Inverse[0 *
Dim + 2] =
446 Inverse[1 *
Dim + 2] =
453 template <
typename T>
487 template <
typename T>
498 Inverse[0 *
Dim + 1] =
500 Inverse[0 *
Dim + 2] =
502 Inverse[0 *
Dim + 3] =
505 Inverse[1 *
Dim + 2] =
507 Inverse[1 *
Dim + 3] =
510 Inverse[2 *
Dim + 3] =
517 #endif // FASTMATRIXMATHHELPER_H typename Base_t::Matrix_t Matrix_t
static Data_t Determinant(Matrix_t const &mat)
Computes the determinant of a matrix.
Namespace for general, non-LArSoft-specific utilities.
static Matrix_t InvertSymmetricMatrix(Matrix_t const &mat)
Computes the determinant of a matrix.
typename Base_t::Data_t Data_t
static constexpr T sqr(T v)
static Matrix_t InvertMatrix(Matrix_t const &mat)
Computes the determinant of a matrix.
static T compute(T const *data)
typename Base_t::Data_t Data_t
static T compute(T const *data)
static constexpr size_t index(unsigned int row, unsigned int col)
static constexpr Data_t sqr(Data_t v)
static Matrix_t InvertMatrix(Matrix_t const &mat)
Computes the determinant of a matrix.
static T compute(T const *data)
Classes gathering simple statistics.
static Matrix_t InvertMatrix(Matrix_t const &mat, Data_t det)
Computes the determinant of a matrix, using the provided determinant.
typename Base_t::Matrix_t Matrix_t
static Matrix_t InvertSymmetricMatrix(Matrix_t const &mat, Data_t det)
Base class with common definitions for "fast" matrix operations.
static T compute(T const *data)
Provides "fast" matrix operations.
static T compute(T const *data)
typename Base_t::Data_t Data_t
typename Base_t::Matrix_t Matrix_t
static Matrix_t InvertSymmetricMatrix(Matrix_t const &mat)
Computes the determinant of a matrix.
static Matrix_t InvertMatrix(Matrix_t const &mat)
Computes the determinant of a matrix.
static Matrix_t InvertSymmetricMatrix(Matrix_t const &mat)
Computes the determinant of a matrix.
static constexpr unsigned int Dim
matrix dimensions
static Data_t Determinant(Matrix_t const &mat)
Computes the determinant of a matrix.
static Vector_t MatrixVectorProduct(Matrix_t const &mat, Vector_t const &vec)
Returns the product of a square matrix times a column vector.
static Matrix_t InvertMatrix(Matrix_t const &mat)
Computes the determinant of a matrix.
constexpr size_t MatrixIndex(unsigned int row, unsigned int col)
static Matrix_t InvertSymmetricMatrix(Matrix_t const &mat)
Computes the determinant of a matrix.
std::array< Data_t, Dim > Vector_t
LArSoft-specific namespace.
std::array< Data_t, Dim *Dim > Matrix_t
static Data_t Determinant(Matrix_t const &mat)
Computes the determinant of a matrix.