The ROOT::Math::SVector and ROOT::Math::SMatrix classes defines the following operators described below. The m1,m2,m3 are vectors or matrices of the same type (and size) and a is a scalar value:
The operator * defines an element by element multiplication between vectors. For the standard vector-vector multiplication, \( a = v^T v \), (dot product) one must use the ROOT::Math::Dot function. In addition, the Cross (only for vector sizes of 3), ROOT::Math::Cross, and the Tensor product, ROOT::Math::TensorProd, are defined.
The operator * defines the matrix-vector multiplication, \( y_i = \sum_{j} M_{ij} x_j\):
It compiles only if the matrix and the vectors have the right sizes.
The operator * defines the matrix-matrix multiplication, \( C_{ij} = \sum_{k} A_{ik} B_{kj}\):
The operation compiles only if the matrices have the right size. In the case that A and B are symmetric matrices, C is a general one, since their product is not guaranteed to be symmetric.
Special care must be taken when using the C++ auto
keyword with expression templates. Some expression can lead to temporary objects that the compiler might remove. One example is when dealing with an expression like:
while instead declaring directly the matrix as
will be fine, because it will force the evaluation of the expression template when constructing the matrix D. This is a limitation of the package, see ROOT-6731 and present in other similar libraries such as Eigen.
The most used matrix functions are:
See Matrix Template Functions for the documentation of all existing matrix functions in the package. The major Vector functions are:
See Vector Template Functions for the list and documentation of all of them.
One can print (or write in an output stream) Vectors (and also Matrices) using the Print method or the << operator, like:
In the ROOT distribution, the CINT dictionary is generated for SMatrix and SVector for double types and sizes up to 5. This allows the storage of them in a ROOT file.