4 #ifndef ROOT_Math_MatrixFunctions 5 #define ROOT_Math_MatrixFunctions 43 #ifndef ROOT_Math_BinaryOpPolicy 46 #ifndef ROOT_Math_Expression 49 #ifndef ROOT_Math_HelperOps 52 #ifndef ROOT_Math_CholeskyDecomp 60 template <
class T,
unsigned int D>
67 template <
class T,
unsigned int D1,
unsigned int D2,
class R>
68 SVector<T,D1>
operator*(
const SMatrix<T,D1,D2,R>& rhs,
const SVector<T,D2>& lhs)
71 for(
unsigned int i=0; i<D1; ++i) {
72 const unsigned int rpos = i*D2;
73 for(
unsigned int j=0; j<D2; ++j) {
74 tmp[i] += rhs.apply(rpos+j) * lhs.apply(j);
89 template <
unsigned int I>
91 template <
class A,
class B>
92 static inline typename A::value_type
f(
const A& lhs,
const B& rhs,
93 const unsigned int offset) {
104 template <
class A,
class B>
105 static inline typename A::value_type
f(
const A& lhs,
const B& rhs,
106 const unsigned int offset) {
107 return lhs.apply(offset) * rhs.apply(0);
114 template <
class Matrix,
class Vector,
unsigned int D2>
118 typedef typename Vector::value_type
T;
122 lhs_(lhs), rhs_(rhs) {}
128 inline typename Matrix::value_type
apply(
unsigned int i)
const {
135 return rhs_.IsInUse(p);
148 template <
unsigned int I>
150 template <
class Matrix,
class Vector>
151 static inline typename Matrix::value_type
f(
const Matrix& lhs,
const Vector& rhs,
152 const unsigned int offset) {
153 return lhs.apply(Matrix::kCols*
I+offset) * rhs.apply(
I) +
164 template <
class Matrix,
class Vector>
165 static inline typename Matrix::value_type
f(
const Matrix& lhs,
const Vector& rhs,
166 const unsigned int offset) {
167 return lhs.apply(offset) * rhs.apply(0);
179 template <
class Vector,
class Matrix,
unsigned int D1>
183 typedef typename Vector::value_type
T;
186 lhs_(lhs), rhs_(rhs) {}
192 inline typename Matrix::value_type
apply(
unsigned int i)
const {
199 return lhs_.IsInUse(p);
217 template <
class T,
unsigned int D1,
unsigned int D2,
class R>
227 template <
class A,
class T,
unsigned int D1,
unsigned int D2,
class R>
228 inline VecExpr<VectorMatrixRowOp<SMatrix<T,D1,D2,R>,
VecExpr<A,T,D2>, D2>,
T, D1>
237 template <
class A,
class T,
unsigned int D1,
unsigned int D2,
class R>
247 template <
class A,
class B,
class T,
unsigned int D1,
unsigned int D2,
class R>
248 inline VecExpr<VectorMatrixRowOp<Expr<A,T,D1,D2,R>,
VecExpr<B,T,D2>, D2>,
T, D1>
257 template <
class T,
unsigned int D1,
unsigned int D2,
class R>
267 template <
class A,
class T,
unsigned int D1,
unsigned int D2,
class R>
277 template <
class A,
class T,
unsigned int D1,
unsigned int D2,
class R>
287 template <
class A,
class B,
class T,
unsigned int D1,
unsigned int D2,
class R>
288 inline VecExpr<VectorMatrixColOp<VecExpr<A,T,D1>,
Expr<B,T,D1,D2,R>, D1>,
T, D2>
297 template <
unsigned int I>
300 template <
class MatrixA,
class MatrixB>
301 static inline typename MatrixA::value_type
f(
const MatrixA& lhs,
303 const unsigned int offset) {
304 return lhs.apply(offset/MatrixB::kCols*MatrixA::kCols +
I) *
305 rhs.apply(MatrixB::kCols*
I + offset%MatrixB::kCols) +
310 template <
class MatrixA,
class MatrixB>
311 static inline typename MatrixA::value_type
g(
const MatrixA& lhs,
315 return lhs(i,
I) * rhs(
I , j) +
327 template <
class MatrixA,
class MatrixB>
328 static inline typename MatrixA::value_type
f(
const MatrixA& lhs,
330 const unsigned int offset) {
331 return lhs.apply(offset/MatrixB::kCols*MatrixA::kCols) *
332 rhs.apply(offset%MatrixB::kCols);
336 template <
class MatrixA,
class MatrixB>
337 static inline typename MatrixA::value_type
g(
const MatrixA& lhs,
339 unsigned int i,
unsigned int j) {
340 return lhs(i,0) * rhs(0,j);
353 template <
class MatrixA,
class MatrixB,
class T,
unsigned int D>
358 lhs_(lhs), rhs_(rhs) {}
364 inline T
apply(
unsigned int i)
const {
368 inline T operator() (
unsigned int i,
unsigned j)
const {
373 return lhs_.IsInUse(p) || rhs_.IsInUse(p);
392 template <
class T,
unsigned int D1,
unsigned int D,
unsigned int D2,
class R1,
class R2>
393 inline Expr<MatrixMulOp<SMatrix<T,D1,D,R1>,
SMatrix<T,D,D2,R2>,
T,D>,
T, D1, D2,
typename MultPolicy<T,R1,R2>::RepType>
396 return Expr<MatMulOp,
T,D1,D2,
403 template <
class A,
class T,
unsigned int D1,
unsigned int D,
unsigned int D2,
class R1,
class R2>
404 inline Expr<MatrixMulOp<SMatrix<T,D1,D,R1>,
Expr<A,T,D,D2,R2>,
T,D>,
T, D1, D2,
typename MultPolicy<T,R1,R2>::RepType>
406 typedef MatrixMulOp<SMatrix<T,D1,D,R1>, Expr<A,T,D,D2,R2>,
T,D> MatMulOp;
407 return Expr<MatMulOp,
T,D1,D2,
414 template <
class A,
class T,
unsigned int D1,
unsigned int D,
unsigned int D2,
class R1,
class R2>
415 inline Expr<MatrixMulOp<Expr<A,T,D1,D,R1>, SMatrix<T,D,D2,R2>,
T,D>,
T, D1, D2,
typename MultPolicy<T,R1,R2>::RepType>
417 typedef MatrixMulOp<Expr<A,T,D1,D,R1>, SMatrix<T,D,D2,R2>,
T,D> MatMulOp;
418 return Expr<MatMulOp,
T,D1,D2,
425 template <
class A,
class B,
class T,
unsigned int D1,
unsigned int D,
unsigned int D2,
class R1,
class R2>
426 inline Expr<MatrixMulOp<Expr<A,T,D1,D,R1>,
Expr<B,T,D,D2,R2>,
T,D>,
T, D1, D2,
typename MultPolicy<T,R1,R2>::RepType>
428 typedef MatrixMulOp<Expr<A,T,D1,D,R1>, Expr<B,T,D,D2,R2>,
T,D> MatMulOp;
438 template <
class MatrixA,
class MatrixB,
unsigned int D>
442 MatrixMulOp(
const MatrixA& lhs,
const MatrixB& rhs) :
443 lhs_(lhs), rhs_(rhs) {}
449 inline typename MatrixA::value_type
apply(
unsigned int i)
const {
462 template <
class T,
unsigned int D1,
unsigned int D,
unsigned int D2,
class R1,
class R2>
463 inline Expr<MatrixMulOp<SMatrix<T,D1,D,R1>, SMatrix<T,D,D2,R2>, D>,
T, D1, D2,
typename MultPolicy<T,R1,R2>::RepType>
472 template <
class A,
class T,
unsigned int D1,
unsigned int D,
unsigned int D2,
class R1,
class R2>
473 inline Expr<MatrixMulOp<SMatrix<T,D1,D,R1>, Expr<A,T,D,D2,R2>, D>,
T, D1, D2,
typename MultPolicy<T,R1,R2>::RepType>
482 template <
class A,
class T,
unsigned int D1,
unsigned int D,
unsigned int D2,
class R1,
class R2>
483 inline Expr<MatrixMulOp<Expr<A,T,D1,D,R1>, SMatrix<T,D,D2,R2>, D>,
T, D1, D2,
typename MultPolicy<T,R1,R2>::RepType>
492 template <
class A,
class B,
class T,
unsigned int D1,
unsigned int D,
unsigned int D2,
class R1,
class R2>
493 inline Expr<MatrixMulOp<Expr<A,T,D1,D,R1>, Expr<B,T,D,D2,R2>, D>,
T, D1, D2,
typename MultPolicy<T,R1,R2>::RepType>
495 typedef MatrixMulOp<Expr<A,T,D1,D,R1>, Expr<B,T,D,D2,R2>, D> MatMulOp;
508 template <
class Matrix,
class T,
unsigned int D1,
unsigned int D2=D1>
519 inline T
apply(
unsigned int i)
const {
520 return rhs_.apply( (i%D1)*D2 + i/D1);
522 inline T operator() (
unsigned int i,
unsigned j)
const {
527 return rhs_.IsInUse(p);
544 template <
class T,
unsigned int D1,
unsigned int D2,
class R>
545 inline Expr<TransposeOp<SMatrix<T,D1,D2,R>,
T,D1,D2>,
T, D2, D1,
typename TranspPolicy<T,D1,D2,R>::RepType>
555 template <
class A,
class T,
unsigned int D1,
unsigned int D2,
class R>
556 inline Expr<TransposeOp<Expr<A,T,D1,D2,R>,
T,D1,D2>,
T, D2, D1,
typename TranspPolicy<T,D1,D2,R>::RepType>
564 #ifdef ENABLE_TEMPORARIES_TRANSPOSE 570 template <
class T,
unsigned int D1,
unsigned int D2,
class R>
582 template <
class A,
class T,
unsigned int D1,
unsigned int D2,
class R>
584 Transpose(
const Expr<A,T,D1,D2,R>& rhs) {
598 template <
class T,
unsigned int D,
class R>
600 return Dot(rhs, lhs * rhs);
606 template <
class T,
unsigned int D,
class R>
608 return Dot(lhs, rhs * lhs);
614 template <
class A,
class T,
unsigned int D,
class R>
616 return Dot(rhs, lhs * rhs);
622 template <
class A,
class T,
unsigned int D,
class R>
624 return Dot(lhs, rhs * lhs);
630 template <
class A,
class T,
unsigned int D,
class R>
632 return Dot(lhs, rhs * lhs);
638 template <
class A,
class T,
unsigned int D,
class R>
640 return Dot(rhs, lhs * rhs);
646 template <
class A,
class B,
class T,
unsigned int D,
class R>
648 return Dot(rhs, lhs * rhs);
654 template <
class A,
class B,
class T,
unsigned int D,
class R>
656 return Dot(lhs, rhs * lhs);
670 template <
class T,
unsigned int D,
class R>
672 return Dot(rhs, lhs * rhs);
678 template <
class T,
unsigned int D,
class R>
680 return Dot(lhs, rhs * lhs);
686 template <
class A,
class T,
unsigned int D,
class R>
688 return Dot(rhs, lhs * rhs);
694 template <
class A,
class T,
unsigned int D,
class R>
696 return Dot(lhs, rhs * lhs);
702 template <
class A,
class T,
unsigned int D,
class R>
704 return Dot(lhs, rhs * lhs);
710 template <
class A,
class T,
unsigned int D,
class R>
712 return Dot(rhs, lhs * rhs);
718 template <
class A,
class B,
class T,
unsigned int D,
class R>
720 return Dot(rhs, lhs * rhs);
726 template <
class A,
class B,
class T,
unsigned int D,
class R>
728 return Dot(lhs, rhs * lhs);
743 template <
class T,
unsigned int D1,
unsigned int D2,
class R>
744 inline SMatrix<T,D1,D1,MatRepSym<T,D1> >
Similarity(
const SMatrix<T,D1,D2,R>& lhs,
const SMatrix<T,D2,D2,
MatRepSym<T,D2> >& rhs) {
757 template <
class A,
class T,
unsigned int D1,
unsigned int D2,
class R>
758 inline SMatrix<T,D1,D1,MatRepSym<T,D1> >
Similarity(
const Expr<A,T,D1,D2,R>& lhs,
const SMatrix<T,D2,D2,
MatRepSym<T,D2> >& rhs) {
772 template <
class T,
unsigned int D1>
773 inline SMatrix<T,D1,D1,MatRepSym<T,D1> >
Similarity(
const SMatrix<T,D1,D1,
MatRepSym<T,D1> >& lhs,
const SMatrix<T,D1,D1,
MatRepSym<T,D1> >& rhs) {
793 template <
class T,
unsigned int D1,
unsigned int D2,
class R>
794 inline SMatrix<T,D2,D2,MatRepSym<T,D2> >
SimilarityT(
const SMatrix<T,D1,D2,R>& lhs,
const SMatrix<T,D1,D1,
MatRepSym<T,D1> >& rhs) {
807 template <
class A,
class T,
unsigned int D1,
unsigned int D2,
class R>
808 inline SMatrix<T,D2,D2,MatRepSym<T,D2> >
SimilarityT(
const Expr<A,T,D1,D2,R>& lhs,
const SMatrix<T,D1,D1,
MatRepSym<T,D1> >& rhs) {
842 template <
class Vector1,
class Vector2>
854 inline typename Vector1::value_type
apply(
unsigned int i)
const {
857 inline typename Vector1::value_type operator() (
unsigned int i,
unsigned j)
const {
858 return lhs_.apply(i) * rhs_.apply(j);
861 inline bool IsInUse (
const typename Vector1::value_type * )
const {
889 template <
class T,
unsigned int D1,
unsigned int D2>
899 template <
class T,
unsigned int D1,
unsigned int D2,
class A>
909 template <
class T,
unsigned int D1,
unsigned int D2,
class A>
910 inline Expr<TensorMulOp<SVector<T,D1>, VecExpr<A,T,D2> >,
T, D1, D2 >
920 template <
class T,
unsigned int D1,
unsigned int D2,
class A,
class B>
921 inline Expr<TensorMulOp<VecExpr<A,T,D1>, VecExpr<B,T,D2> >,
T, D1, D2 >
934 template <
class T,
unsigned int D1,
unsigned int D2>
937 for (
unsigned int i=0; i< D1; ++i)
938 for (
unsigned int j=0; j< D2; ++j) {
939 tmp(i,j) = lhs[i]*rhs[j];
947 template <
class T,
unsigned int D1,
unsigned int D2,
class A>
950 for (
unsigned int i=0; i< D1; ++i)
951 for (
unsigned int j=0; j< D2; ++j)
959 template <
class T,
unsigned int D1,
unsigned int D2,
class A>
962 for (
unsigned int i=0; i< D1; ++i)
963 for (
unsigned int j=0; j< D2; ++j)
973 template <
class T,
unsigned int D1,
unsigned int D2,
class A,
class B>
976 for (
unsigned int i=0; i< D1; ++i)
977 for (
unsigned int j=0; j< D2; ++j)
990 template <
class T,
unsigned int D>
993 return decomp.
Solve(vec);
998 template <
class T,
unsigned int D>
1003 ifail = (ok) ? 0 : -1;
T Dot(const SVector< T, D > &lhs, const SVector< T, D > &rhs)
Vector dot product.
Class for Vector-Matrix multiplication.
T Similarity(const SMatrix< T, D, D, R > &lhs, const SVector< T, D > &rhs)
Similarity Vector - Matrix Product: v^T * A * v returning a scalar value of type T ...
static Double_t Product(const Double_t *x, const Float_t *y)
Product.
Class for Tensor Multiplication (outer product) of two vectors giving a matrix.
Class for Matrix-Matrix multiplication.
This namespace contains pre-defined functions to be used in conjuction with TExecutor::Map and TExecu...
Matrix::value_type apply(unsigned int i) const
calc
VectorMatrixRowOp(const Matrix &lhs, const Vector &rhs)
MatRepSym Matrix storage representation for a symmetric matrix of dimension NxN This class is a templ...
Class for Transpose Operations.
Expr< TransposeOp< SMatrix< T, D1, D2, R >, T, D1, D2 >, T, D2, D1, typename TranspPolicy< T, D1, D2, R >::RepType > Transpose(const SMatrix< T, D1, D2, R > &rhs)
Matrix Transpose B(i,j) = A(j,i) returning a matrix expression.
bool IsInUse(const T *p) const
bool SolveChol(SMatrix< T, D, D, MatRepSym< T, D > > &mat, SVector< T, D > &vec)
TensorMulOp(const Vector1 &lhs, const Vector2 &rhs)
header file containing the templated implementation of matrix inversion routines for use with ROOT's ...
class to compute the Cholesky decomposition of a matrix
SMatrix: a generic fixed size D1 x D2 Matrix class.
bool IsInUse(const T *p) const
TransposeOp(const Matrix &rhs)
Expression wrapper class for Matrix objects.
VectorMatrixColOp(const Vector &lhs, const Matrix &rhs)
Expr< TensorMulOp< SVector< T, D1 >, SVector< T, D2 > >, T, D1, D2 > TensorProd(const SVector< T, D1 > &lhs, const SVector< T, D2 > &rhs)
Tensor Vector Product : M(i,j) = v(i) * v(j) returning a matrix expression.
T apply(unsigned int i) const
access the parse tree. Index starts from zero
T apply(unsigned int i) const
bool IsInUse(const typename Vector1::value_type *) const
static void Evaluate(SMatrix< T, D, D, MatRepSym< T, D > > &lhs, const Expr< A, T, D, D, R > &rhs)
assign a symmetric matrix from an expression
Matrix::value_type apply(unsigned int i) const
calc
MatrixMulOp(const MatrixA &lhs, const MatrixB &rhs)
Namespace for new Math classes and functions.
T apply(unsigned int i) const
calc
Expression wrapper class for Vector objects.
bool Solve(V &rhs) const
solves a linear system for the given right hand side
SMatrix< T, D2, D2, MatRepSym< T, D2 > > SimilarityT(const SMatrix< T, D1, D2, R > &lhs, const SMatrix< T, D1, D1, MatRepSym< T, D1 > > &rhs)
Transpose Similarity Matrix Product : B = U^T * A * U for A symmetric returning a symmetric matrix ex...
bool IsInUse(const T *p) const
Vector1::value_type apply(unsigned int i) const
Vector2::kSize is the number of columns in the resulting matrix.
decltype(auto) constexpr apply(F &&f, Tuple &&t)
bool IsInUse(const T *p) const
AxisAngle operator*(RotationX const &r1, AxisAngle const &r2)
Multiplication of an axial rotation by an AxisAngle.
SVector: a generic fixed size Vector class.
T apply(unsigned int i) const