From c839ac1e96c4fb7f6620336dc8657941f76ea225 Mon Sep 17 00:00:00 2001 From: Lorenzo Moneta <Lorenzo.Moneta@cern.ch> Date: Thu, 8 Jun 2006 15:23:34 +0000 Subject: [PATCH] updated documentation for the classes. Group them in different doxygen groups. Add protection when including header files. git-svn-id: http://root.cern.ch/svn/root/trunk@15372 27541ba8-7e3a-0410-8455-c3a389f83636 --- smatrix/inc/Math/BinaryOpPolicy.h | 20 ++- smatrix/inc/Math/BinaryOperators.h | 24 +++- smatrix/inc/Math/CramerInversion.icc | 14 ++- smatrix/inc/Math/CramerInversionSym.icc | 17 ++- smatrix/inc/Math/Dfact.h | 5 +- smatrix/inc/Math/Dinv.h | 31 ++--- smatrix/inc/Math/Expression.h | 52 +++++--- smatrix/inc/Math/Functions.h | 7 +- smatrix/inc/Math/HelperOps.h | 41 ++++-- smatrix/inc/Math/MatrixFunctions.h | 26 +++- smatrix/inc/Math/MatrixInversion.icc | 14 ++- .../inc/Math/MatrixRepresentationsStatic.h | 10 +- smatrix/inc/Math/SMatrix.h | 119 ++++++++++++------ smatrix/inc/Math/SMatrix.icc | 19 ++- smatrix/inc/Math/SVector.h | 101 +++++++++------ smatrix/inc/Math/SVector.icc | 10 +- smatrix/inc/Math/UnaryOperators.h | 22 +++- 17 files changed, 391 insertions(+), 141 deletions(-) diff --git a/smatrix/inc/Math/BinaryOpPolicy.h b/smatrix/inc/Math/BinaryOpPolicy.h index 96bbfa698bd..1c78657e954 100644 --- a/smatrix/inc/Math/BinaryOpPolicy.h +++ b/smatrix/inc/Math/BinaryOpPolicy.h @@ -1,7 +1,7 @@ -// @(#)root/smatrix:$Name: $:$Id: BinaryOpPolicy.h,v 1.3 2006/02/28 15:54:33 moneta Exp $ +// @(#)root/smatrix:$Name: $:$Id: BinaryOpPolicy.h,v 1.4 2006/03/20 17:11:44 moneta Exp $ // Authors: J. Palacios 2006 -#ifndef ROOT_Math_BinaryOpPolicy_h -#define ROOT_Math_BinaryOpPolicy_h 1 +#ifndef ROOT_Math_BinaryOpPolicy +#define ROOT_Math_BinaryOpPolicy 1 // Include files @@ -17,14 +17,18 @@ * (and subtraction) */ -//#include "Math/MatrixRepresentations.h" + +#ifndef ROOT_Math_MatrixRepresentationsStatic #include "Math/MatrixRepresentationsStatic.h" +#endif namespace ROOT { namespace Math { - + /** + matrix-matrix multiplication policy + */ template <class T, class R1, class R2> struct MultPolicy { @@ -35,6 +39,9 @@ namespace ROOT { typedef MatRepStd<T, N1, N2> RepType; }; + /** + matrix addition policy + */ template <class T, unsigned int D1, unsigned int D2, class R1, class R2> struct AddPolicy { @@ -51,6 +58,9 @@ namespace ROOT { typedef MatRepSym<T,D1> RepType; }; + /** + matrix transpose policy + */ template <class T, unsigned int D1, unsigned int D2, class R> struct TranspPolicy { diff --git a/smatrix/inc/Math/BinaryOperators.h b/smatrix/inc/Math/BinaryOperators.h index b75a807cd62..07a6fab89e6 100644 --- a/smatrix/inc/Math/BinaryOperators.h +++ b/smatrix/inc/Math/BinaryOperators.h @@ -1,4 +1,4 @@ -// @(#)root/smatrix:$Name: $:$Id: BinaryOperators.h,v 1.4 2006/03/20 17:11:44 moneta Exp $ +// @(#)root/smatrix:$Name: $:$Id: BinaryOperators.h,v 1.5 2006/06/02 15:04:54 moneta Exp $ // Authors: T. Glebe, L. Moneta 2005 #ifndef ROOT_Math_BinaryOperators @@ -18,7 +18,9 @@ // //====================================================== +#ifndef ROOT_Math_BinaryOpPolicy #include "Math/BinaryOpPolicy.h" +#endif namespace ROOT { @@ -33,6 +35,11 @@ template <class T, unsigned int D1, unsigned int D2, class R> class SMatrix; //============================================================================== // AddOp //============================================================================== +/** + Addition Operation Class + + @ingroup Expression + */ template <class T> class AddOp { public: @@ -272,6 +279,11 @@ inline Expr<BinaryOpCopyL<AddOp<T>, Constant<A>, Expr<B,T,D,D2,R>, T>, T, D, D2, //============================================================================== // MinOp //============================================================================== +/** + Subtraction Operation Class + + @ingroup Expression + */ template <class T> class MinOp { public: @@ -506,6 +518,11 @@ inline Expr<BinaryOpCopyL<MinOp<T>, Constant<A>, Expr<B,T,D,D2,R>, T>, T, D, D2, } +/** + Multiplication (element-wise) Operation Class + + @ingroup Expression + */ //============================================================================== // MulOp //============================================================================== @@ -741,6 +758,11 @@ inline Expr<BinaryOpCopyL<MulOp<T>, Constant<A>, Expr<B,T,D,D2,R>, T>, T, D, D2, //============================================================================= // DivOp //============================================================================= +/** + Division (element-wise) Operation Class + + @ingroup Expression + */ template <class T> class DivOp { public: diff --git a/smatrix/inc/Math/CramerInversion.icc b/smatrix/inc/Math/CramerInversion.icc index fa91b80fd03..3398e7b0013 100644 --- a/smatrix/inc/Math/CramerInversion.icc +++ b/smatrix/inc/Math/CramerInversion.icc @@ -1,4 +1,4 @@ -// @(#)root/smatrix:$Name: $:$Id: CramerInversion.icc,v 1.2 2006/02/08 14:45:35 moneta Exp $ +// @(#)root/smatrix:$Name: $:$Id: CramerInversion.icc,v 1.3 2006/02/17 16:11:02 moneta Exp $ // Authors: L. Moneta 2005 @@ -30,6 +30,9 @@ namespace ROOT { // Inversion for 3x3 matrices //============================================================================== +/** + Inversion for a 3x3 matrix + */ template <class MatrixRep> bool Inverter<3>::Dinv(MatrixRep & rhs) { @@ -118,6 +121,9 @@ bool Inverter<3>::Dinv(MatrixRep & rhs) { #define F32 14 #define F33 15 +/** + Inversion for a 4x4 matrix + */ template <class MatrixRep> bool Inverter<4>::Dinv(MatrixRep & rhs) { @@ -256,6 +262,9 @@ bool Inverter<4>::Dinv(MatrixRep & rhs) { #define M44 24 +/** + Inversion for a 5x5 matrix + */ template <class MatrixRep> bool Inverter<5>::Dinv(MatrixRep & rhs) { @@ -493,6 +502,9 @@ bool Inverter<5>::Dinv(MatrixRep & rhs) { #define A55 35 +/** + Inversion for a 6x6 matrix + */ template <class MatrixRep> bool Inverter<6>::Dinv(MatrixRep & rhs) { diff --git a/smatrix/inc/Math/CramerInversionSym.icc b/smatrix/inc/Math/CramerInversionSym.icc index c52ddae85b4..4abddbf1eff 100644 --- a/smatrix/inc/Math/CramerInversionSym.icc +++ b/smatrix/inc/Math/CramerInversionSym.icc @@ -1,4 +1,4 @@ -// @(#)root/smatrix:$Name: $:$Id: CramerInversionSym.icc,v 1.1 2006/02/08 14:45:35 moneta Exp $ +// @(#)root/smatrix:$Name: $:$Id: CramerInversionSym.icc,v 1.2 2006/02/17 16:11:02 moneta Exp $ // Authors: L. Moneta 2005 @@ -26,9 +26,11 @@ namespace ROOT { + //============================================================================== -// Inversion for 3x3 matrices -//============================================================================== +/** + Inversion for a 3x3 symmetric matrix + */ template <class T> bool Inverter<3>::Dinv(MatRepSym<T,3> & rhs) { @@ -112,6 +114,9 @@ bool Inverter<3>::Dinv(MatRepSym<T,3> & rhs) { #define SF33 15 +/** + Inversion for a 4x4 symmetric matrix + */ template <class T> bool Inverter<4>::Dinv(MatRepSym<T,4> & rhs) { @@ -226,6 +231,9 @@ bool Inverter<4>::Dinv(MatRepSym<T,4> & rhs) { #define SM43 19 #define SM44 24 +/** + Inversion for a 5x5 symmetric matrix + */ template <class T> bool Inverter<5>::Dinv(MatRepSym<T,5> & rhs) { @@ -410,6 +418,9 @@ bool Inverter<5>::Dinv(MatRepSym<T,5> & rhs) { #define SA54 29 #define SA55 35 +/** + Inversion for a 6x6 symmetric matrix + */ template <class T> bool Inverter<6>::Dinv(MatRepSym<T,6> & rhs) { diff --git a/smatrix/inc/Math/Dfact.h b/smatrix/inc/Math/Dfact.h index 44483a49367..0189629a87c 100644 --- a/smatrix/inc/Math/Dfact.h +++ b/smatrix/inc/Math/Dfact.h @@ -1,4 +1,4 @@ -// @(#)root/smatrix:$Name: $:$Id: Dfact.h,v 1.3 2006/02/28 15:54:33 moneta Exp $ +// @(#)root/smatrix:$Name: $:$Id: Dfact.h,v 1.4 2006/06/02 15:04:54 moneta Exp $ // Authors: T. Glebe, L. Moneta 2005 #ifndef ROOT_Math_Dfact @@ -36,7 +36,8 @@ namespace ROOT { -/** Dfact. +/** + Detrminant for a general squared matrix Function to compute the determinant from a square matrix (\f$ \det(A)\f$) of dimension idim and order n. diff --git a/smatrix/inc/Math/Dinv.h b/smatrix/inc/Math/Dinv.h index a2e4eb2cdbe..94cfb33e270 100644 --- a/smatrix/inc/Math/Dinv.h +++ b/smatrix/inc/Math/Dinv.h @@ -1,4 +1,4 @@ -// @(#)root/smatrix:$Name: $:$Id: Dinv.h,v 1.5 2006/05/12 08:12:16 moneta Exp $ +// @(#)root/smatrix:$Name: $:$Id: Dinv.h,v 1.6 2006/06/02 15:04:54 moneta Exp $ // Authors: T. Glebe, L. Moneta 2005 #ifndef ROOT_Math_Dinv @@ -29,10 +29,11 @@ // 03 Apr 2001 (TG) creation // // ******************************************************************** +#ifdef OLD_IMPL #include "Math/Dfactir.h" #include "Math/Dfinv.h" #include "Math/Dsinv.h" - +#endif namespace ROOT { @@ -41,7 +42,8 @@ namespace ROOT { -/** Inverter. +/** + Matrix Inverter class (generic class used for matrix sizes larger than 6x6) Class to specialize calls to Dinv. Dinv computes the inverse of a square matrix if dimension idim and order n. The content of the matrix will be replaced by its inverse. In case the inversion fails, the matrix content is @@ -163,8 +165,8 @@ public: }; -/** Inverter<1>. - 1x1 (sub-)matrix. \f$a_{11} \to 1/a_{11}\f$ +/** + 1x1 matrix inversion \f$a_{11} \to 1/a_{11}\f$ @author T. Glebe */ @@ -187,8 +189,8 @@ public: }; -/** Inverter<2>. - 2x2 (sub-)matrix. Use Cramers rule. +/** + 2x2 matrix inversion using Cramers rule. @author T. Glebe */ @@ -243,9 +245,8 @@ public: }; -/** Inverter<3>. - 3x3 (sub-)matrix. Use pivotisation. - +/** + 3x3 direct matrix inversion @author T. Glebe */ //============================================================================== @@ -266,7 +267,6 @@ public: }; /** - Inverter<4> 4x4 matrix inversion using Cramers rule. */ template <> @@ -282,7 +282,6 @@ public: }; /** - Inverter<5> 5x5 Matrix inversion using Cramers rule. */ template <> @@ -298,7 +297,6 @@ public: }; /** - Inverter<6> 6x6 matrix inversion using Cramers rule. */ template <> @@ -318,9 +316,14 @@ public: } // namespace ROOT - +#ifndef ROOT_Math_CramerInversion_icc #include "CramerInversion.icc" +#endif +#ifndef ROOT_Math_CramerInversionSym_icc #include "CramerInversionSym.icc" +#endif +#ifndef ROOT_Math_MatrixInversion_icc #include "MatrixInversion.icc" +#endif #endif /* ROOT_Math_Dinv */ diff --git a/smatrix/inc/Math/Expression.h b/smatrix/inc/Math/Expression.h index 6c4fa176749..1de4244a269 100644 --- a/smatrix/inc/Math/Expression.h +++ b/smatrix/inc/Math/Expression.h @@ -1,4 +1,4 @@ -// @(#)root/smatrix:$Name: $:$Id: Expression.h,v 1.9 2006/03/20 17:11:44 moneta Exp $ +// @(#)root/smatrix:$Name: $:$Id: Expression.h,v 1.10 2006/04/25 13:54:01 moneta Exp $ // Authors: T. Glebe, L. Moneta 2005 #ifndef ROOT_Math_Expression @@ -30,12 +30,10 @@ // // ******************************************************************** -/** Expr. - An Expression wrapper class. +/** + @defgroup Expression Expression Template Classes + */ - @memo Expr. - @author T. Glebe -*/ //============================================================================== // Expr: class representing SVector expressions //============================================================================= @@ -55,6 +53,11 @@ namespace ROOT { // template <class T, unsigned int D, unsigned int D2> class MatRepStd; +/** + Expression wrapper class for Vector objects + + @ingroup Expression +*/ template <class ExprType, class T, unsigned int D > class VecExpr { @@ -107,6 +110,11 @@ private: }; +/** + Expression wrapper class for Matrix objects + + @ingroup Expression +*/ template <class T, unsigned int D, unsigned int D2> class MatRepStd; @@ -193,10 +201,12 @@ inline std::ostream& operator<<(std::ostream& os, const Expr<A,T,D1,D2,R1>& rhs) return rhs.print(os); } -/** BinaryOp. - A class representing binary operators in the parse tree. +/** + BinaryOperation class + A class representing binary operators in the parse tree. + This is the default case where objects are kept by reference - @memo BinaryOp + @ingroup Expression @author T. Glebe */ @@ -239,9 +249,13 @@ protected: //============================================================================== /** - Special case of BinaryOp where for the left argument a copy is stored instead of a reference - This is use in the coase for example of constant where we cannot store by reference - but need to copy since Constant is a temporary object + Binary Operation class with value storage for the left argument. + Special case of BinaryOp where for the left argument the passed object + is copied and stored by value instead of a reference. + This is used in the case of operations involving a constant, where we cannot store a + reference to the constant (we get a temporary object) and we need to copy it. + + @ingroup Expression */ //============================================================================== template <class Operator, class LHS, class RHS, class T> @@ -277,9 +291,12 @@ protected: //============================================================================== /** + Binary Operation class with value storage for the right argument. Special case of BinaryOp where for the wight argument a copy is stored instead of a reference This is use in the case for example of constant where we cannot store by reference but need to copy since Constant is a temporary object + + @ingroup Expression */ //============================================================================== template <class Operator, class LHS, class RHS, class T> @@ -314,10 +331,12 @@ protected: -/** UnaryOp. +/** + UnaryOperation class A class representing unary operators in the parse tree. + The objects are stored by reference - @memo UnaryOp + @ingroup Expression @author T. Glebe */ //============================================================================== @@ -352,10 +371,11 @@ protected: }; -/** Constant. +/** + Constant expression class A class representing constant expressions (literals) in the parse tree. - @memo Constant + @ingroup Expression @author T. Glebe */ //============================================================================== diff --git a/smatrix/inc/Math/Functions.h b/smatrix/inc/Math/Functions.h index ac8beb0a343..3a2dcffed68 100644 --- a/smatrix/inc/Math/Functions.h +++ b/smatrix/inc/Math/Functions.h @@ -1,4 +1,4 @@ -// @(#)root/smatrix:$Name: $:$Id: Functions.h,v 1.3 2006/02/08 14:45:35 moneta Exp $ +// @(#)root/smatrix:$Name: $:$Id: Functions.h,v 1.4 2006/06/02 15:04:54 moneta Exp $ // Authors: T. Glebe, L. Moneta 2005 #ifndef ROOT_Math_Functions @@ -32,7 +32,10 @@ // // ******************************************************************** #include <cmath> + +#ifndef ROOT_Math_Expression #include "Math/Expression.h" +#endif /** @defgroup TempFunction Template Functions @@ -58,7 +61,7 @@ template <class T, unsigned int D> class SVector; /** square - Template function to compute \f$x\cdot x$, for any type T returning a type T + Template function to compute \f$x\cdot x \f$, for any type T returning a type T @ingroup TempFunction @author T. Glebe diff --git a/smatrix/inc/Math/HelperOps.h b/smatrix/inc/Math/HelperOps.h index b484253e8d6..f8a86c2b2b5 100644 --- a/smatrix/inc/Math/HelperOps.h +++ b/smatrix/inc/Math/HelperOps.h @@ -1,8 +1,8 @@ -// @(#)root/smatrix:$Name: $:$Id: HelperOps.h,v 1.8 2006/04/25 13:54:01 moneta Exp $ +// @(#)root/smatrix:$Name: $:$Id: HelperOps.h,v 1.9 2006/04/25 14:59:54 moneta Exp $ // Authors: J. Palacios 2006 -#ifndef ROOT_Math_HelperOps_h -#define ROOT_Math_HelperOps_h 1 +#ifndef ROOT_Math_HelperOps +#define ROOT_Math_HelperOps 1 // Include files @@ -30,7 +30,11 @@ namespace ROOT { class Expr; //========================================================================= - // for generic matrices + /** + Evaluate the expression from general to general matrices. + If the matrix to assign the value is in use in the expression, + a temporary object is created to store the value (case A = B * A) + */ template <class T, unsigned int D1, unsigned int D2, class A, class R1, class R2> @@ -63,7 +67,12 @@ namespace ROOT { } }; - // specialization in case of symmetric expression to symmetric matrices : + + /** + Evaluate the expression from symmetric to symmetric matrices. + If the matrix to assign the value is in use in the expression, + a temporary object is created to store the value (case A = B * A) + */ template <class T, unsigned int D1, unsigned int D2, class A> @@ -98,7 +107,10 @@ namespace ROOT { }; - // case of general to symmetric matrices (flag an error !) + + /** + Expression evaluation from general to symmetric (flag an error !) + */ template <class T, unsigned int D1, unsigned int D2, class A> struct Assign<T, D1, D2, A, MatRepSym<T,D1>, MatRepStd<T,D1,D2> > { @@ -110,8 +122,12 @@ namespace ROOT { }; // struct Assign - // have a dedicated structure for symmetric matrices to be used when we are sure the resulting expression is - // symmetric (like in a smilarity operation). This cannot be used in the opersator= of the SMatrix class + + /** + Force Expression evaluation from general to symmetric. + To be used when is known (like in similarity products) that the result + is symmetric + */ struct AssignSym { // assign a symmetric matrix from an expression @@ -130,7 +146,11 @@ namespace ROOT { l++; } } - // assign a symmetric matrix from a general matrix that we assume is symmetric + /** + Force assignment from general to symmetric matrix. + To be used when is known (like in similarity products) that the result + is symmetric + */ template <class T, unsigned int D, class R> @@ -151,6 +171,9 @@ namespace ROOT { //========================================================================= + /** + Evaluate the expression performing a += operation + */ template <class T, unsigned int D1, unsigned int D2, class A, class R1, class R2> struct PlusEquals diff --git a/smatrix/inc/Math/MatrixFunctions.h b/smatrix/inc/Math/MatrixFunctions.h index 3d286709114..edff0df12f8 100644 --- a/smatrix/inc/Math/MatrixFunctions.h +++ b/smatrix/inc/Math/MatrixFunctions.h @@ -1,4 +1,4 @@ -// @(#)root/smatrix:$Name: $:$Id: MatrixFunctions.h,v 1.12 2006/05/12 14:15:32 moneta Exp $ +// @(#)root/smatrix:$Name: $:$Id: MatrixFunctions.h,v 1.13 2006/06/02 15:04:54 moneta Exp $ // Authors: T. Glebe, L. Moneta 2005 #ifndef ROOT_Math_MatrixFunctions @@ -39,7 +39,9 @@ a vector, like in the matrix-vector product or a scalar like in the Similarity vector-matrix product. */ +#ifndef ROOT_Math_BinaryOpPolicy #include "Math/BinaryOpPolicy.h" +#endif namespace ROOT { @@ -148,6 +150,11 @@ struct meta_col_dot<0> { //============================================================================== // VectorMatrixColOp //============================================================================== +/** + Class for Vector-Matrix multiplication + + @ingroup Expression + */ template <class Vector, class Matrix, unsigned int D1> class VectorMatrixColOp { public: @@ -308,6 +315,11 @@ struct meta_matrix_dot<0> { //============================================================================== // MatrixMulOp //============================================================================== +/** + Class for Matrix-Matrix multiplication + + @ingroup Expression + */ template <class MatrixA, class MatrixB, class T, unsigned int D> class MatrixMulOp { public: @@ -458,6 +470,11 @@ inline Expr<MatrixMulOp<Expr<A,T,D1,D,R1>, Expr<B,T,D,D2,R2>, D>, T, D1, D2, typ //============================================================================== // TransposeOp //============================================================================== +/** + Class for Transpose Operations + + @ingroup Expression + */ template <class Matrix, class T, unsigned int D1, unsigned int D2=D1> class TransposeOp { public: @@ -785,8 +802,13 @@ inline SMatrix<T,D2,D2,MatRepSym<T,D2> > SimilarityT(const Expr<A,T,D1,D2,R>& lh //============================================================================== // TensorMulOp -// tensor (or outer) product between two vectors giving a matrix //============================================================================== +/** + Class for Tensor Multiplication (outer product) of two vectors + giving a matrix + + @ingroup Expression + */ template <class Vector1, class Vector2> class TensorMulOp { public: diff --git a/smatrix/inc/Math/MatrixInversion.icc b/smatrix/inc/Math/MatrixInversion.icc index 78cfcd7ef50..fa61e517fb2 100644 --- a/smatrix/inc/Math/MatrixInversion.icc +++ b/smatrix/inc/Math/MatrixInversion.icc @@ -1,9 +1,13 @@ -// @(#)root/smatrix:$Name: $:$Id: MatrixInversion.icc,v 1.2 2006/05/12 10:02:48 moneta Exp $ +// @(#)root/smatrix:$Name: $:$Id: MatrixInversion.icc,v 1.3 2006/06/06 09:30:40 moneta Exp $ // Authors: CLHEP authors, L. Moneta 2006 #include "Math/SVector.h" #include <limits> + +#ifndef ROOT_Math_MatrixInversion_icc +#define ROOT_Math_MatrixInversion_icc + // inversion algorithms for matrices // taken from CLHEP (L. Moneta May 2006) @@ -12,7 +16,8 @@ namespace ROOT { namespace Math { - /** Bunch-Kaufman diagonal pivoting method + /** General Inversion for a symmetric matrix + Bunch-Kaufman diagonal pivoting method It is decribed in J.R. Bunch, L. Kaufman (1977). "Some Stable Methods for Calculating Inertia and Solving Symmetric Linear Systems", Math. Comp. 31, p. 162-179. or in Gene H. Golub, @@ -542,7 +547,8 @@ int Inverter<idim,n>::DfactMatrix(MatRepStd<T,idim,n> & rhs, T &det, unsigned in /** - Inversion for General square matrices. Code from dfinv routine from CERNLIB + Inversion for General square matrices. + Code from dfinv routine from CERNLIB Assumed first the LU decomposition via DfactMatrix function taken from CLHEP : L. Moneta May 2006 @@ -657,3 +663,5 @@ int Inverter<idim,n>::DfinvMatrix(MatRepStd<T,idim,n> & rhs,unsigned int * ir) { } // end namespace Math } // end namespace ROOT + +#endif diff --git a/smatrix/inc/Math/MatrixRepresentationsStatic.h b/smatrix/inc/Math/MatrixRepresentationsStatic.h index e2f4a128b44..86e7b43a59e 100644 --- a/smatrix/inc/Math/MatrixRepresentationsStatic.h +++ b/smatrix/inc/Math/MatrixRepresentationsStatic.h @@ -1,8 +1,8 @@ -// @(#)root/smatrix:$Name: $:$Id: MatrixRepresentationsStatic.h,v 1.6 2006/04/25 13:54:01 moneta Exp $ +// @(#)root/smatrix:$Name: $:$Id: MatrixRepresentationsStatic.h,v 1.7 2006/06/02 15:04:54 moneta Exp $ // Authors: L. Moneta, J. Palacios 2006 -#ifndef ROOT_Math_MatrixRepresentationsStatic_h -#define ROOT_Math_MatrixRepresentationsStatic_h 1 +#ifndef ROOT_Math_MatrixRepresentationsStatic +#define ROOT_Math_MatrixRepresentationsStatic 1 // Include files @@ -17,8 +17,10 @@ operators =, +=, -=, ==. */ -#include <iostream> + +#ifndef ROOT_Math_StaticCheck #include "Math/StaticCheck.h" +#endif namespace ROOT { namespace Math { diff --git a/smatrix/inc/Math/SMatrix.h b/smatrix/inc/Math/SMatrix.h index f70c29cc6e2..4dd85c47a38 100644 --- a/smatrix/inc/Math/SMatrix.h +++ b/smatrix/inc/Math/SMatrix.h @@ -1,4 +1,4 @@ -// @(#)root/smatrix:$Name: $:$Id: SMatrix.h,v 1.21 2006/05/12 08:12:16 moneta Exp $ +// @(#)root/smatrix:$Name: $:$Id: SMatrix.h,v 1.22 2006/06/02 15:04:54 moneta Exp $ // Authors: T. Glebe, L. Moneta 2005 #ifndef ROOT_Math_SMatrix @@ -37,7 +37,10 @@ // // ******************************************************************** // for platform specific configurations + +#ifndef ROOT_Math_MnConfig #include "Math/MConfig.h" +#endif #include <iosfwd> @@ -46,18 +49,24 @@ /** @defgroup SMatrix Matrix and Vector classes + Classes representing Matrices and Vectors of arbitrary type and dimension. + For a detailed description and usage examples see: <ul> <li>\ref SVectorDoc <li>\ref SMatrixDoc + <li>\ref MatVecFunctions </ul> + */ -// expression engine +#ifndef ROOT_Math_Expression #include "Math/Expression.h" -//#include "Math/MatrixRepresentations.h" +#endif +#ifndef ROOT_Math_MatrixRepresentationsStatic #include "Math/MatrixRepresentationsStatic.h" +#endif namespace ROOT { @@ -77,8 +86,8 @@ namespace ROOT { See \ref SMatrixDoc. @ingroup SMatrix - @memo SMatrix - @author T. Glebe + + @authors T. Glebe, L. Moneta and J. Palacios */ //============================================================================== // SMatrix: column-wise storage @@ -90,9 +99,11 @@ template <class T, class SMatrix { public: /** @name --- Typedefs --- */ - /// + + /** contained scalar type */ typedef T value_type; + /** storage representation type */ typedef R rep_type; /** STL iterator interface. */ @@ -103,7 +114,7 @@ public: - /** @name --- Constructors --- */ + /** @name --- Constructors and Assignment --- */ /** Default constructor: @@ -126,7 +137,7 @@ public: SMatrix(const SMatrix<T,D1,D2,R2>& rhs); /** - construct from an expression. + Construct from an expression. In case of symmetric matrices does not work if expression is of type general matrices. In case one needs to force the assignment from general to symmetric, one can use the ROOT::Math::AssignSym::Evaluate function. @@ -134,7 +145,7 @@ public: template <class A, class R2> SMatrix(const Expr<A,T,D1,D2,R2>& rhs); - // new constructs using STL iterator interface + /** Constructor with STL iterator interface. The data will be copied into the matrix \param begin start iterator position @@ -169,8 +180,8 @@ public: template<class InputIterator> SMatrix(InputIterator begin, unsigned int size, bool triang = false, bool lower = true); - // skip this methods (they are too ambigous) -#ifdef OLD_IMPL +#ifdef OLD_IMPL // skip this methods (they are too ambigous) + /// 2nd arg: set only diagonal? SMatrix(const T& rhs, bool diagonal=false); /// constructor via dyadic product @@ -202,16 +213,25 @@ public: SMatrix(const SVector<T,N> & v, bool lower = true ); #endif - /// + /** + Assign from another compatible matrix. + Possible Symmetirc to general but NOT vice-versa + */ template <class M> SMatrix<T,D1,D2,R>& operator=(const M& rhs); + /** + Assign from a matrix expression + */ template <class A, class R2> SMatrix<T,D1,D2,R>& operator=(const Expr<A,T,D1,D2,R2>& rhs); - /// assign from an identity + /** + Assign from an identity matrix + */ SMatrix<T,D1,D2,R> & operator=(SMatrixIdentity ); + /** @name --- Matrix dimension --- */ #ifdef OLD_IMPL /// return no. of matrix rows @@ -221,6 +241,10 @@ public: /// return no of elements: rows*columns static const unsigned int kSize = D1*D2; #else + /** + Enumeration defining the matrix dimension, + number of rows, columns and size = rows*columns) + */ enum { /// return no. of matrix rows kRows = D1, @@ -230,9 +254,13 @@ public: kSize = D1*D2 }; #endif + /** @name --- Access functions --- */ - /** access the parse tree with the index starting from zero and following the C convention for the order in accessing + + /** access the parse tree with the index starting from zero and + following the C convention for the order in accessing the matrix elements. + Same convention for general and symmetric matrices. */ T apply(unsigned int i) const; @@ -311,32 +339,38 @@ public: */ T& operator()(unsigned int i, unsigned int j); - /// + /** + self addition (element wise operation) + */ template <class M> SMatrix<T,D1,D2,R>&operator+=(const M& rhs); + /** + self subtruction (element wise operation) + */ template <class M> SMatrix<T,D1,D2,R>& operator-=(const M& rhs); #ifdef OLD_IMPL - // this operations are not well defines - // in th eold impl they were implemented not as matrix - matrix multiplication, but as - // m(i,j)*m(i,j) multiplication + // this operations are not well defines - they are implmented as element - wise operations + // not as matrix multiplication SMatrix<T,D1,D2,R>& operator*=(const SMatrix<T,D1,D2,R>& rhs); SMatrix<T,D1,D2,R>& operator/=(const SMatrix<T,D1,D2,R>& rhs); #endif #ifndef __CINT__ - /// + /** + self addition from a matrix expression (element wise operation) + */ template <class A, class R2> SMatrix<T,D1,D2,R>& operator+=(const Expr<A,T,D1,D2,R2>& rhs); - /// - /// + /** + self subtraction from a matrix expression (element wise operation) + */ template <class A, class R2> SMatrix<T,D1,D2,R>& operator-=(const Expr<A,T,D1,D2,R2>& rhs); - /// - /// + #ifdef OLD_IMPL template <class A, class R2> SMatrix<T,D1,D2,R>& operator*=(const Expr<A,T,D1,D2,R2>& rhs); @@ -348,8 +382,9 @@ public: #endif + /** @name --- Linear Algebra Functions --- */ + #ifdef OLD_IMPL - /** @name --- Expert functions --- */ /** invert symmetric, pos. def. Matrix via Dsinv. @@ -378,7 +413,7 @@ public: /** - invert square Matrix ( this method change the current matrix) + Invert a square Matrix ( this method change the current matrix) The method used for general square matrices is the LU factorization taken from Dinv routine from the CERNLIB (written in C++ from CLHEP authors) In case of symmetric matrices Bunch-Kaufman diagonal pivoting method is used @@ -387,7 +422,7 @@ public: bool Invert(); /** - invert a square Matrix and returns a new matrix. In case the inversion fails + Invert a square Matrix and returns a new matrix. In case the inversion fails the current matrix is returned. Return ifail = 0 when successfull. See ROOT::Math::SMatrix::Invert for the inversion algorithm @@ -395,18 +430,19 @@ public: SMatrix<T,D1,D2,R> Inverse(int & ifail ) const; /** - determinant of square Matrix via Dfact. \textbf{Note:} this will destroy + determinant of square Matrix via Dfact. \b Note: this will destroy the contents of the Matrix! */ bool Det(T& det); /** - determinant of square Matrix via Dfact. \textbf{Note:} this will preserve + determinant of square Matrix via Dfact. \b Note: this will preserve the content of the Matrix! */ bool Det2(T& det) const; + /** @name --- Matrix Slice Functions --- */ /// place a vector in a Matrix row template <unsigned int D> @@ -498,6 +534,7 @@ SMatrix<T,D1,D2,R>& Place_in_col(const VecExpr<A,T,D>& rhs, template<class SubVector> SubVector UpperBlock() const; #endif + /** return the lower Triangular block of the matrices (including the diagonal) as a vector of sizes N = D1 * (D1 + 1)/2. @@ -511,12 +548,15 @@ SMatrix<T,D1,D2,R>& Place_in_col(const VecExpr<A,T,D>& rhs, #endif + /** @name --- Other Functions --- */ + /** - check if matrix is sharing same memory location. - This functionis used by the expression to avoid the alias problem when - evaluating them. In case matrix is in use, a temporary object is automatically - created evaluating the expression. Then the correct result is obtained for operations - like A = B * A + Function to check if a matrix is sharing same memory location of the passed pointer + This function is used by the expression templates to avoid the alias problem during + expression evaluation. When the matrix is in use, for example in operations + like A = B * A, a temporary object storing the intermediate result is automatically + created when evaluating the expression. + */ bool IsInUse(const T* p) const; @@ -526,7 +566,12 @@ SMatrix<T,D1,D2,R>& Place_in_col(const VecExpr<A,T,D>& rhs, std::ostream& Print(std::ostream& os) const; public: - // T fArray[D1*D2]; + + /** @name --- Data Member --- */ + + /** + Matrix Storage Object containing matrix data + */ R fRep; }; // end of class SMatrix @@ -553,9 +598,13 @@ inline std::ostream& operator<<(std::ostream& os, const ROOT::Math::SMatrix<T,D1 #ifndef __CINT__ +#ifndef ROOT_Math_SMatrix_icc #include "Math/SMatrix.icc" -// include Matrix-Vector multiplication +#endif + +#ifndef ROOT_Math_MatrixFunctions #include "Math/MatrixFunctions.h" +#endif #endif //__CINT__ diff --git a/smatrix/inc/Math/SMatrix.icc b/smatrix/inc/Math/SMatrix.icc index 142ebddbb89..bd61d5d01d1 100644 --- a/smatrix/inc/Math/SMatrix.icc +++ b/smatrix/inc/Math/SMatrix.icc @@ -1,4 +1,4 @@ -// @(#)root/smatrix:$Name: $:$Id: SMatrix.icc,v 1.21 2006/05/12 08:12:16 moneta Exp $ +// @(#)root/smatrix:$Name: $:$Id: SMatrix.icc,v 1.22 2006/06/02 15:04:54 moneta Exp $ // Authors: T. Glebe, L. Moneta 2005 #ifndef ROOT_Math_SMatrix_icc @@ -36,14 +36,27 @@ #include <iostream> #include <iomanip> #include <assert.h> -#include "Math/Dsinv.h" +//#ifndef ROOT_Math_Dsinv +//#include "Math/Dsinv.h" +//#endif //#include "Math/Dsinv_array.h" -#include "Math/Dsfact.h" +//#include "Math/Dsfact.h" + +#ifndef ROOT_Math_Dfact #include "Math/Dfact.h" +#endif +#ifndef ROOT_Math_Dinv #include "Math/Dinv.h" +#endif +#ifndef ROOT_Math_Functions #include "Math/Functions.h" +#endif +#ifndef ROOT_Math_HelperOps #include "Math/HelperOps.h" +#endif +#ifndef ROOT_Math_StaticCheck #include "Math/StaticCheck.h" +#endif diff --git a/smatrix/inc/Math/SVector.h b/smatrix/inc/Math/SVector.h index 1f4cd82f7dc..e451b599866 100644 --- a/smatrix/inc/Math/SVector.h +++ b/smatrix/inc/Math/SVector.h @@ -1,4 +1,4 @@ -// @(#)root/smatrix:$Name: $:$Id: SVector.h,v 1.9 2006/05/12 08:12:16 moneta Exp $ +// @(#)root/smatrix:$Name: $:$Id: SVector.h,v 1.10 2006/06/02 15:04:54 moneta Exp $ // Authors: T. Glebe, L. Moneta 2005 #ifndef ROOT_Math_SVector @@ -35,12 +35,17 @@ // // ******************************************************************** +#ifndef ROOT_Math_MnConfig #include "Math/MConfig.h" +#endif #include <iosfwd> // expression engine + +#ifndef ROOT_Math_Expression #include "Math/Expression.h" +#endif @@ -61,8 +66,9 @@ namespace ROOT { @ingroup SMatrix - @memo SVector - @author T. Glebe + + @authors T. Glebe, L. Moneta and J. Palacios + */ //============================================================================== // SVector @@ -71,7 +77,7 @@ template <class T, unsigned int D> class SVector { public: /** @name --- Typedefs --- */ - /// + /// contained scalar type typedef T value_type; /** STL iterator interface. */ @@ -80,25 +86,29 @@ public: /** STL const_iterator interface. */ typedef const T* const_iterator; - /** @name --- Constructors --- */ - /** @name --- Constructors --- */ /** Default constructor: vector filled with zero values */ SVector(); - /// + /// contruct from a vector expression template <class A> SVector(const VecExpr<A,T,D>& rhs); - /// + /// copy contructor SVector(const SVector<T,D>& rhs); - /// $D1\le D$ required! + +#ifdef OLD_IMPL // skip these (too ambigous and not really useful + /** + construct from another vector with smaller size ( D1 <= D). + Remaining elements are set to zero + */ template <unsigned int D1> SVector(const SVector<T,D1>& rhs); - /// $D1\le D-1$ required! + /// D1 <= D-1$ required! template <unsigned int D1> SVector(const T& a1, const SVector<T,D1>& rhs); +#endif // new constructs using STL iterator interface // skip - need to solve the ambiguities @@ -118,58 +128,62 @@ public: #else // if you use iterator this is not necessary - /// fill from array, len must be equal to D! + /// fill from array with len must be equal to D! SVector( const T * a, unsigned int len); - /// fill from iterators - //(iterator is T* to skip ambiguities) + /** fill from a SVector iterator of type T* + (for ambiguities iterator cannot be generic ) + */ SVector(const_iterator begin, const_iterator end); #endif - /// + /// construct setting all elements to the passed scalar value SVector(const T& rhs); - /// + /// construct a vector of size >=2 from 2 scalar values SVector(const T& a1, const T& a2); - /// + /// construct a vector of size >=3 from 3 scalar values SVector(const T& a1, const T& a2, const T& a3); - /// + /// construct a vector of size >=4 from 4 scalar values SVector(const T& a1, const T& a2, const T& a3, const T& a4); - /// + /// construct a vector of size >=5 from 5 scalar values SVector(const T& a1, const T& a2, const T& a3, const T& a4, const T& a5); - /// + /// construct a vector of size >=6 from 6 scalar values SVector(const T& a1, const T& a2, const T& a3, const T& a4, const T& a5, const T& a6); - /// + /// construct a vector of size >=7 from 7 scalar values SVector(const T& a1, const T& a2, const T& a3, const T& a4, const T& a5, const T& a6, const T& a7); - /// + /// construct a vector of size >=8 from 8 scalar values SVector(const T& a1, const T& a2, const T& a3, const T& a4, const T& a5, const T& a6, const T& a7, const T& a8); - /// + /// construct a vector of size >=9 from 9 scalar values SVector(const T& a1, const T& a2, const T& a3, const T& a4, const T& a5, const T& a6, const T& a7, const T& a8, const T& a9); - /// + /// construct a vector of size >=10 from 10 scalar values SVector(const T& a1, const T& a2, const T& a3, const T& a4, const T& a5, const T& a6, const T& a7, const T& a8, const T& a9, const T& a10); - /// + /// copy constructor SVector<T,D>& operator=(const T& rhs); - /// + ///copy constructor from Vector Expression template <class A> SVector<T,D>& operator=(const VecExpr<A,T,D>& rhs); + /** @name --- Access functions --- */ + /** + Enumeration defining the Vector size + */ enum { /// return vector size kSize = D }; - /** @name --- Access functions --- */ /// return dimension $D$ inline static unsigned int Dim() { return D; } @@ -177,7 +191,7 @@ public: T apply(unsigned int i) const; /// return read-only pointer to internal array const T* Array() const; - /// return pointer to internal array + /// return non-const pointer to internal array T* Array(); /** @name --- STL-like interface --- */ @@ -197,6 +211,7 @@ public: /** @name --- Operators --- */ + /// element wise comparison bool operator==(const T& rhs) const; /// element wise comparison @@ -236,27 +251,27 @@ public: /// read/write access of vector elements. Index starts from 0. T& operator()(unsigned int i); - /// + /// self addition with another vector SVector<T,D>& operator+=(const SVector<T,D>& rhs); - /// + /// self subtraction with another vector SVector<T,D>& operator-=(const SVector<T,D>& rhs); - /// + /// self element-wise multiplication with another vector SVector<T,D>& operator*=(const SVector<T,D>& rhs); - /// + /// self element-wise division with another vector SVector<T,D>& operator/=(const SVector<T,D>& rhs); #ifndef __CINT__ - /// + /// self addition with a vector expression template <class A> SVector<T,D>& operator+=(const VecExpr<A,T,D>& rhs); - /// + /// self subtraction with a vector expression template <class A> SVector<T,D>& operator-=(const VecExpr<A,T,D>& rhs); - /// + /// self element-wise multiplication with a vector expression template <class A> SVector<T,D>& operator*=(const VecExpr<A,T,D>& rhs); - /// + /// self element-wise division with a vector expression template <class A> SVector<T,D>& operator/=(const VecExpr<A,T,D>& rhs); @@ -265,10 +280,10 @@ public: /** @name --- Expert functions --- */ /// transform vector into a vector of lenght 1 SVector<T,D>& Unit(); - /// place a sub-vector starting at <row> + /// place a sub-vector starting from the given position template <unsigned int D2> SVector<T,D>& Place_at(const SVector<T,D2>& rhs, unsigned int row); - /// place a sub-vector starting at <row> + /// place a sub-vector expression starting from the given position template <class A, unsigned int D2> SVector<T,D>& Place_at(const VecExpr<A,T,D2>& rhs, unsigned int row); @@ -285,6 +300,10 @@ public: std::ostream& Print(std::ostream& os) const; private: + + /** @name --- Data member --- */ + + /// SVector data T fArray[D]; }; // end of class SVector @@ -306,12 +325,20 @@ std::ostream& operator<<(std::ostream& os, const ROOT::Math::SVector<T,D>& rhs); #ifndef __CINT__ // include implementation file +#ifndef ROOT_Math_SVector_icc #include "Math/SVector.icc" +#endif // include operators and functions +#ifndef ROOT_Math_UnaryOperators #include "Math/UnaryOperators.h" +#endif +#ifndef ROOT_Math_BinaryOperators #include "Math/BinaryOperators.h" +#endif +#ifndef ROOT_Math_MatrixFunctions #include "Math/Functions.h" +#endif #endif // __CINT__ diff --git a/smatrix/inc/Math/SVector.icc b/smatrix/inc/Math/SVector.icc index 10f36322733..460e5f7d9da 100644 --- a/smatrix/inc/Math/SVector.icc +++ b/smatrix/inc/Math/SVector.icc @@ -1,4 +1,4 @@ -// @(#)root/smatrix:$Name: $:$Id: SVector.icc,v 1.7 2006/02/27 18:41:58 moneta Exp $ +// @(#)root/smatrix:$Name: $:$Id: SVector.icc,v 1.8 2006/05/12 08:12:16 moneta Exp $ // Authors: T. Glebe, L. Moneta 2005 #ifndef ROOT_Math_SVector_icc @@ -33,8 +33,9 @@ #include <iostream> #include <assert.h> - +#ifndef ROOT_Math_StaticCheck #include "Math/StaticCheck.h" +#endif namespace ROOT { @@ -61,12 +62,15 @@ SVector<T,D>::SVector(const SVector<T,D>& rhs) { fArray[i] = rhs.fArray[i]; } +#ifdef OLD_IMPL template <class T, unsigned int D> template <unsigned int D1> SVector<T,D>::SVector(const SVector<T,D1>& rhs) { STATIC_CHECK( D >= D1,SVector_dimension_too_small); for(unsigned int i=0; i<D1; ++i) fArray[i] = rhs.fArray[i]; + for(unsigned int i=D1; i<D; ++i) + fArray[i] = 0; } template <class T, unsigned int D> @@ -77,7 +81,7 @@ SVector<T,D>::SVector(const T& a1, const SVector<T,D1>& rhs) { for(unsigned int i=0; i<D1; ++i) fArray[i+1] = rhs[i]; } - +#endif template <class T, unsigned int D> SVector<T,D>::SVector(const T& rhs) { diff --git a/smatrix/inc/Math/UnaryOperators.h b/smatrix/inc/Math/UnaryOperators.h index 2421b5aaa2c..1c9be3e767a 100644 --- a/smatrix/inc/Math/UnaryOperators.h +++ b/smatrix/inc/Math/UnaryOperators.h @@ -1,4 +1,4 @@ -// @(#)root/smatrix:$Name: $:$Id: UnaryOperators.h,v 1.2 2006/02/08 14:45:35 moneta Exp $ +// @(#)root/smatrix:$Name: $:$Id: UnaryOperators.h,v 1.3 2006/06/02 15:04:54 moneta Exp $ // Authors: T. Glebe, L. Moneta 2005 #ifndef ROOT_Math_UnaryOperators @@ -30,6 +30,11 @@ template <class T, unsigned int D> class SVector; template <class T, unsigned int D1, unsigned int D2, class R> class SMatrix; +/** + Unary Minus Operation Class + + @ingroup Expression + */ //============================================================================== // Minus //============================================================================== @@ -103,6 +108,11 @@ inline Expr<UnaryOp<Minus<T>, SMatrix<T,D,D2,R>, T>, T, D, D2,R> //============================================================================== // Fabs //============================================================================== +/** + Unary abs Operation Class + + @ingroup Expression + */ template <class T> class Fabs { public: @@ -170,6 +180,11 @@ inline Expr<UnaryOp<Fabs<T>, SMatrix<T,D,D2,R>, T>, T, D, D2, R> } +/** + Unary Square Operation Class + + @ingroup Expression + */ //============================================================================== // Sqr //============================================================================== @@ -243,6 +258,11 @@ inline Expr<UnaryOp<Sqr<T>, SMatrix<T,D,D2,R>, T>, T, D, D2, R> //============================================================================== // Sqrt //============================================================================== +/** + Unary Square Root Operation Class + + @ingroup Expression + */ template <class T> class Sqrt { public: -- GitLab