CMS 3D CMS Logo

SimpleMatrix.h
Go to the documentation of this file.
1 #ifndef RecoBTag_Analysis_SimpleMatrix_h
2 #define RecoBTag_Analysis_SimpleMatrix_h
3 
4 #include <memory>
5 
6 namespace btag {
7 
8 template<typename T>
9 class SimpleMatrix {
10  public:
11  typedef T value_type;
13 
14  SimpleMatrix(size_type rows, size_type cols) :
15  width(cols), height(rows), container(rows * cols) {}
16 
18 
19  inline size_type rows() const { return height; }
20  inline size_type cols() const { return width; }
21  inline size_type size() const { return container.size(); }
22 
23  inline double &operator () (size_type row, size_type col)
24  { return container[index(row, col)]; }
25  inline double operator () (size_type row, size_type col) const
26  { return container[index(row, col)]; }
27 
28  inline double &operator [] (size_type index)
29  { return container[index]; }
30  inline double operator [] (size_type index) const
31  { return container[index]; }
32 
33  inline size_type row(size_type index) const { return index / width; }
34  inline size_type col(size_type index) const { return index % width; }
35 
36  protected:
37  size_type index(size_type row, size_type col) const
38  { return row * width + col; }
39 
40  private:
41  size_type width, height;
42  std::vector<T> container;
43 };
44 
45 } // namespace btag
46 
47 #endif // GeneratorEvent_Analysis_SimpleMatrix_h
size_type rows() const
Definition: SimpleMatrix.h:19
size_type col(size_type index) const
Definition: SimpleMatrix.h:34
size_type row(size_type index) const
Definition: SimpleMatrix.h:33
double & operator()(size_type row, size_type col)
Definition: SimpleMatrix.h:23
std::vector< T > container
Definition: SimpleMatrix.h:42
size_type cols() const
Definition: SimpleMatrix.h:20
uint16_t size_type
Definition: Matching.h:11
size_type size() const
Definition: SimpleMatrix.h:21
double & operator[](size_type index)
Definition: SimpleMatrix.h:28
std::vector< T >::size_type size_type
Definition: SimpleMatrix.h:12
SimpleMatrix(size_type rows, size_type cols)
Definition: SimpleMatrix.h:14
long double T
size_type index(size_type row, size_type col) const
Definition: SimpleMatrix.h:37