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 #include <vector>
6 
7 namespace btag {
8 
9 template<typename T>
10 class SimpleMatrix {
11  public:
12  typedef T value_type;
14 
15  SimpleMatrix(size_type rows, size_type cols) :
16  width(cols), height(rows), container(rows * cols) {}
17 
19 
20  inline size_type rows() const { return height; }
21  inline size_type cols() const { return width; }
22  inline size_type size() const { return container.size(); }
23 
24  inline double &operator () (size_type row, size_type col)
25  { return container[index(row, col)]; }
26  inline double operator () (size_type row, size_type col) const
27  { return container[index(row, col)]; }
28 
29  inline double &operator [] (size_type index)
30  { return container[index]; }
31  inline double operator [] (size_type index) const
32  { return container[index]; }
33 
34  inline size_type row(size_type index) const { return index / width; }
35  inline size_type col(size_type index) const { return index % width; }
36 
37  protected:
38  size_type index(size_type row, size_type col) const
39  { return row * width + col; }
40 
41  private:
42  size_type width, height;
43  std::vector<T> container;
44 };
45 
46 } // namespace btag
47 
48 #endif // GeneratorEvent_Analysis_SimpleMatrix_h
size_type rows() const
Definition: SimpleMatrix.h:20
size_type col(size_type index) const
Definition: SimpleMatrix.h:35
size_type row(size_type index) const
Definition: SimpleMatrix.h:34
double & operator()(size_type row, size_type col)
Definition: SimpleMatrix.h:24
std::vector< T > container
Definition: SimpleMatrix.h:43
size_type cols() const
Definition: SimpleMatrix.h:21
uint16_t size_type
Definition: Matching.h:11
size_type size() const
Definition: SimpleMatrix.h:22
double & operator[](size_type index)
Definition: SimpleMatrix.h:29
std::vector< T >::size_type size_type
Definition: SimpleMatrix.h:13
SimpleMatrix(size_type rows, size_type cols)
Definition: SimpleMatrix.h:15
long double T
size_type index(size_type row, size_type col) const
Definition: SimpleMatrix.h:38