FEDRA emulsion software from the OPERA Collaboration
SMatrix.hh
Go to the documentation of this file.
1 #ifndef __SMATRIX_HH
2 #define __SMATRIX_HH
3 // ********************************************************************
4 //
5 // source:
6 //
7 // type: source code
8 //
9 // created: 20. Mar 2001
10 //
11 // author: Thorsten Glebe
12 // HERA-B Collaboration
13 // Max-Planck-Institut fuer Kernphysik
14 // Saupfercheckweg 1
15 // 69117 Heidelberg
16 // Germany
17 // E-mail: T.Glebe@mpi-hd.mpg.de
18 //
19 // Description: A fixed size two dimensional Matrix class
20 //
21 // changes:
22 // 20 Mar 2001 (TG) creation
23 // 21 Mar 2001 (TG) added operators +=, -=, *=, /=
24 // 26 Mar 2001 (TG) place_in_row(), place_in_col() added
25 // 02 Apr 2001 (TG) non-const Array() added
26 // 03 Apr 2001 (TG) invert() added
27 // 07 Apr 2001 (TG) CTOR from SVertex (dyadic product) added
28 // 09 Apr 2001 (TG) CTOR from array added
29 // 11 Apr 2001 (TG) rows(), cols(), size() replaced by rows, cols, size
30 // 25 Mai 2001 (TG) row(), col() added
31 // 04 Sep 2001 (TG) moved inlined functions to .icc file
32 // 11 Jan 2002 (TG) added operator==(), operator!=()
33 // 14 Jan 2002 (TG) added more operator==(), operator!=(), operator>(), operator<()
34 //
35 // ********************************************************************
36 #include <iosfwd>
37 
38 template <class T, unsigned int D> class SVector;
39 
40 // expression engine
41 #include "Expression.hh"
42 
49 //==============================================================================
50 // SMatrix: column-wise storage
51 //==============================================================================
52 template <class T, unsigned int D1, unsigned int D2 = D1>
53 class SMatrix {
54 public:
57  typedef T value_type;
58 
65  template <class A>
66  SMatrix(const Expr<A,T,D1,D2>& rhs);
68  SMatrix(const T& rhs, const bool diagonal=false);
70  SMatrix(const SVector<T,D1>& rhs);
72  template <class A>
73  SMatrix(const Expr<A,T,D1>& rhs);
76  template <class T1>
77  SMatrix(const T1* a, const bool triang=false, const unsigned int len=D1*D2);
78 
80  SMatrix<T,D1,D2>& operator=(const T& rhs);
82  template <class A>
84 
86  static const unsigned int rows = D1;
88  static const unsigned int cols = D2;
90  static const unsigned int size = D1*D2;
91 
94  T apply(unsigned int i) const;
96  const T* Array() const;
98  T* Array();
99 
102  bool operator==(const T& rhs) const;
104  bool operator!=(const T& rhs) const;
106  bool operator==(const SMatrix<T,D1,D2>& rhs) const;
108  bool operator!=(const SMatrix<T,D1,D2>& rhs) const;
110  template <class A>
111  bool operator==(const Expr<A,T,D1,D2>& rhs) const;
113  template <class A>
114  bool operator!=(const Expr<A,T,D1,D2>& rhs) const;
115 
117  bool operator>(const T& rhs) const;
119  bool operator<(const T& rhs) const;
121  bool operator>(const SMatrix<T,D1,D2>& rhs) const;
123  bool operator<(const SMatrix<T,D1,D2>& rhs) const;
125  template <class A>
126  bool operator>(const Expr<A,T,D1,D2>& rhs) const;
128  template <class A>
129  bool operator<(const Expr<A,T,D1,D2>& rhs) const;
130 
132  const T& operator()(unsigned int i, unsigned int j) const;
134  T& operator()(unsigned int i, unsigned int j);
138  template <class A>
143  template <class A>
148  template <class A>
153  template <class A>
155 
158  bool sinvert();
161  bool sdet(T& det);
163  bool invert();
166  bool det(T& det);
168  template <unsigned int D>
170  const unsigned int row,
171  const unsigned int col);
173  template <class A, unsigned int D>
175  const unsigned int row,
176  const unsigned int col);
178  template <unsigned int D>
180  const unsigned int row,
181  const unsigned int col);
183  template <class A, unsigned int D>
185  const unsigned int row,
186  const unsigned int col);
188  template <unsigned int D3, unsigned int D4>
190  const unsigned int row,
191  const unsigned int col);
193  template <class A, unsigned int D3, unsigned int D4>
195  const unsigned int row,
196  const unsigned int col);
198  SVector<T,D2> row(const unsigned int therow) const;
200  SVector<T,D1> col(const unsigned int thecol) const;
202  std::ostream& print(std::ostream& os) const;
203 
204 private:
205  T array[D1*D2];
206 }; // end of class SMatrix
207 
208 //==============================================================================
209 // operator<<
210 //==============================================================================
211 template <class T, unsigned int D1, unsigned int D2>
212 inline std::ostream& operator<<(std::ostream& os, const SMatrix<T,D1,D2>& rhs) {
213  return rhs.print(os);
214 }
215 
216 #include "SMatrix.icc"
217 // include Matrix-Vector multiplication
218 #include "MatrixFunctions.hh"
219 
220 #endif
std::ostream & operator<<(std::ostream &os, const SMatrix< T, D1, D2 > &rhs)
Definition: SMatrix.hh:212
void a()
Definition: check_aligned.C:59
Definition: Expression.hh:43
Definition: SMatrix.hh:53
SMatrix< T, D1, D2 > & operator+=(const SMatrix< T, D1, D2 > &rhs)
SMatrix(const SVector< T, D1 > &rhs)
constructor via dyadic product
SMatrix(const Expr< A, T, D1, D2 > &rhs)
SMatrix< T, D1, D2 > & place_in_col(const SVector< T, D > &rhs, const unsigned int row, const unsigned int col)
place a vector in a Matrix column
static const unsigned int size
return no of elements: rows*columns
Definition: SMatrix.hh:90
SVector< T, D1 > col(const unsigned int thecol) const
return a Matrix column as a vector
bool invert()
invert square Matrix via Dinv
const T * Array() const
return read-only pointer to internal array
SMatrix(const T1 *a, const bool triang=false, const unsigned int len=D1 *D2)
bool operator>(const T &rhs) const
element wise comparison
bool operator>(const SMatrix< T, D1, D2 > &rhs) const
element wise comparison
SMatrix< T, D1, D2 > & operator-=(const SMatrix< T, D1, D2 > &rhs)
SMatrix< T, D1, D2 > & operator*=(const Expr< A, T, D1, D2 > &rhs)
SMatrix(const Expr< A, T, D1 > &rhs)
constructor via dyadic product
T array[D1 *D2]
Definition: SMatrix.hh:205
T apply(unsigned int i) const
access the parse tree
SMatrix< T, D1, D2 > & place_in_row(const Expr< A, T, D > &rhs, const unsigned int row, const unsigned int col)
place a vector expression in a Matrix row
bool operator!=(const T &rhs) const
element wise comparison
bool operator>(const Expr< A, T, D1, D2 > &rhs) const
element wise comparison
T & operator()(unsigned int i, unsigned int j)
read/write access
SMatrix(const T &rhs, const bool diagonal=false)
2nd arg: set only diagonal?
bool det(T &det)
SMatrix< T, D1, D2 > & place_at(const Expr< A, T, D3, D4 > &rhs, const unsigned int row, const unsigned int col)
place a matrix expression in this matrix
bool sdet(T &det)
SMatrix< T, D1, D2 > & operator*=(const SMatrix< T, D1, D2 > &rhs)
bool operator!=(const SMatrix< T, D1, D2 > &rhs) const
element wise comparison
bool sinvert()
invert symmetric, pos. def. Matrix via Dsinv
bool operator==(const T &rhs) const
element wise comparison
bool operator<(const SMatrix< T, D1, D2 > &rhs) const
element wise comparison
bool operator<(const T &rhs) const
element wise comparison
T * Array()
return pointer to internal array
bool operator==(const Expr< A, T, D1, D2 > &rhs) const
element wise comparison
T value_type
Definition: SMatrix.hh:57
static const unsigned int rows
return no. of matrix rows
Definition: SMatrix.hh:86
SMatrix< T, D1, D2 > & place_in_row(const SVector< T, D > &rhs, const unsigned int row, const unsigned int col)
place a vector in a Matrix row
bool operator<(const Expr< A, T, D1, D2 > &rhs) const
element wise comparison
SMatrix< T, D1, D2 > & operator+=(const Expr< A, T, D1, D2 > &rhs)
std::ostream & print(std::ostream &os) const
used by operator<<()
const T & operator()(unsigned int i, unsigned int j) const
read-only access
SMatrix< T, D1, D2 > & operator=(const Expr< A, T, D1, D2 > &rhs)
bool operator==(const SMatrix< T, D1, D2 > &rhs) const
element wise comparison
SMatrix< T, D1, D2 > & operator/=(const SMatrix< T, D1, D2 > &rhs)
SMatrix(const SMatrix< T, D1, D2 > &rhs)
static const unsigned int cols
return no. of matrix columns
Definition: SMatrix.hh:88
SMatrix< T, D1, D2 > & operator-=(const Expr< A, T, D1, D2 > &rhs)
SMatrix< T, D1, D2 > & place_in_col(const Expr< A, T, D > &rhs, const unsigned int row, const unsigned int col)
place a vector expression in a Matrix column
bool operator!=(const Expr< A, T, D1, D2 > &rhs) const
element wise comparison
SVector< T, D2 > row(const unsigned int therow) const
return a Matrix row as a vector
SMatrix< T, D1, D2 > & place_at(const SMatrix< T, D3, D4 > &rhs, const unsigned int row, const unsigned int col)
place a matrix in this matrix
SMatrix< T, D1, D2 > & operator/=(const Expr< A, T, D1, D2 > &rhs)
SMatrix< T, D1, D2 > & operator=(const T &rhs)
Definition: SVector.hh:51