LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
lar::util::details::FastMatrixOperations< T, DIM > Struct Template Reference

Provides "fast" matrix operations. More...

#include "FastMatrixMathHelper.h"

Inheritance diagram for lar::util::details::FastMatrixOperations< T, DIM >:
lar::util::details::FastMatrixOperationsBase< T, DIM >

Public Types

using Base_t = FastMatrixOperationsBase< T, DIM >
 
using Data_t = typename Base_t::Data_t
 
using Matrix_t = typename Base_t::Matrix_t
 
using Vector_t = std::array< Data_t, Dim >
 

Static Public Member Functions

static Data_t Determinant (Matrix_t const &mat)
 Computes the determinant of a matrix. More...
 
static Matrix_t InvertMatrix (Matrix_t const &mat, Data_t det)
 Computes the determinant of a matrix, using the provided determinant. More...
 
static Matrix_t InvertSymmetricMatrix (Matrix_t const &mat, Data_t det)
 
static Matrix_t InvertMatrix (Matrix_t const &mat)
 Computes the determinant of a matrix. More...
 
static Matrix_t InvertSymmetricMatrix (Matrix_t const &mat)
 Computes the determinant of a matrix. More...
 
static Vector_t MatrixVectorProduct (Matrix_t const &mat, Vector_t const &vec)
 Returns the product of a square matrix times a column vector. More...
 
static constexpr Data_t sqr (Data_t v)
 

Static Public Attributes

static constexpr unsigned int Dim = DIM
 matrix dimensions More...
 

Detailed Description

template<typename T, unsigned int DIM>
struct lar::util::details::FastMatrixOperations< T, DIM >

Provides "fast" matrix operations.

Template Parameters
Tdata type for the elements of the matrix
DIMthe dimension of the (square) matrix

Actually this class does nothing: specialize it!

Once the specialization is in place, this class offers:

constexpr unsigned int Dim = 2;
std::array<float, Dim*Dim> matrix;

float det = FastMatrixOperations<float, Dim>::Determinant();

std::array<float, Dim*Dim> inverse;

// generic inversion
inverse = FastMatrixOperations<float, Dim>::InvertMatrix(matrix);

// faster inversion if we already have the determinant
inverse = FastMatrixOperations<float, Dim>::InvertMatrix
  (matrix, det);

// faster inversion if we know the matrix is symmetric
inverse = FastMatrixOperations<float, Dim>::InvertSymmetricMatrix
  (matrix);

// even faster inversion if we also know the determinant already
inverse = FastMatrixOperations<float, Dim>::InvertSymmetricMatrix
  (matrix, det);

Note that the inversion functions do not have a defined policy for non-invertible matrices. If you need to check (and you usually do), compute the determinant first, and invert only if std::isnormal(det).

Definition at line 83 of file FastMatrixMathHelper.h.

Member Typedef Documentation

template<typename T , unsigned int DIM>
using lar::util::details::FastMatrixOperations< T, DIM >::Base_t = FastMatrixOperationsBase<T, DIM>

Definition at line 84 of file FastMatrixMathHelper.h.

template<typename T , unsigned int DIM>
using lar::util::details::FastMatrixOperations< T, DIM >::Data_t = typename Base_t::Data_t

Definition at line 85 of file FastMatrixMathHelper.h.

template<typename T , unsigned int DIM>
using lar::util::details::FastMatrixOperations< T, DIM >::Matrix_t = typename Base_t::Matrix_t

Definition at line 86 of file FastMatrixMathHelper.h.

template<typename T, unsigned int DIM>
using lar::util::details::FastMatrixOperationsBase< T, DIM >::Vector_t = std::array<Data_t, Dim>
inherited

Definition at line 39 of file FastMatrixMathHelper.h.

Member Function Documentation

template<typename T , unsigned int DIM>
static Data_t lar::util::details::FastMatrixOperations< T, DIM >::Determinant ( Matrix_t const &  mat)
static

Computes the determinant of a matrix.

template<typename T , unsigned int DIM>
static Matrix_t lar::util::details::FastMatrixOperations< T, DIM >::InvertMatrix ( Matrix_t const &  mat,
Data_t  det 
)
static

Computes the determinant of a matrix, using the provided determinant.

template<typename T , unsigned int DIM>
static Matrix_t lar::util::details::FastMatrixOperations< T, DIM >::InvertMatrix ( Matrix_t const &  mat)
inlinestatic

Computes the determinant of a matrix.

Definition at line 99 of file FastMatrixMathHelper.h.

100  {
101  return InvertMatrix(mat, Determinant(mat));
102  }
static Data_t Determinant(Matrix_t const &mat)
Computes the determinant of a matrix.
static Matrix_t InvertMatrix(Matrix_t const &mat, Data_t det)
Computes the determinant of a matrix, using the provided determinant.
Float_t mat
Definition: plot.C:38
template<typename T , unsigned int DIM>
static Matrix_t lar::util::details::FastMatrixOperations< T, DIM >::InvertSymmetricMatrix ( Matrix_t const &  mat,
Data_t  det 
)
static

Computes the determinant of a symmatric matrix, using the provided determinant

template<typename T , unsigned int DIM>
static Matrix_t lar::util::details::FastMatrixOperations< T, DIM >::InvertSymmetricMatrix ( Matrix_t const &  mat)
inlinestatic

Computes the determinant of a matrix.

Definition at line 105 of file FastMatrixMathHelper.h.

106  {
108  }
static Data_t Determinant(Matrix_t const &mat)
Computes the determinant of a matrix.
static Matrix_t InvertSymmetricMatrix(Matrix_t const &mat, Data_t det)
Float_t mat
Definition: plot.C:38
template<typename T , unsigned int DIM>
auto lar::util::details::FastMatrixOperationsBase< T, DIM >::MatrixVectorProduct ( Matrix_t const &  mat,
Vector_t const &  vec 
)
staticinherited

Returns the product of a square matrix times a column vector.

Definition at line 360 of file FastMatrixMathHelper.h.

References lar::util::details::FastMatrixOperationsBase< T, DIM >::Dim, mat, and r.

363 {
364  // not really fast, but there is probably not much to fasten...
365  Vector_t res;
366  Data_t const* mat_row = mat.data();
367  for (size_t r = 0; r < Dim; ++r) {
368  Data_t elem = Data_t(0);
369  for (size_t c = 0; c < Dim; ++c)
370  elem += *(mat_row++) * vec[c];
371  res[r] = elem;
372  } // for
373  return res;
374 } // FastMatrixOperationsBase<>::MatrixVectorProduct()
TRandom r
Definition: spectrum.C:23
static constexpr unsigned int Dim
matrix dimensions
Float_t mat
Definition: plot.C:38
recob::tracking::Vector_t Vector_t
template<typename T, unsigned int DIM>
static constexpr Data_t lar::util::details::FastMatrixOperationsBase< T, DIM >::sqr ( Data_t  v)
inlinestaticinherited

Definition at line 44 of file FastMatrixMathHelper.h.

44 { return v * v; }

Member Data Documentation


The documentation for this struct was generated from the following file: