File indexing completed on 2024-04-06 12:09:48
0001 #ifndef RecoBTag_Analysis_SimpleMatrix_h
0002 #define RecoBTag_Analysis_SimpleMatrix_h
0003
0004 #include <memory>
0005 #include <vector>
0006
0007 namespace btag {
0008
0009 template <typename T>
0010 class SimpleMatrix {
0011 public:
0012 typedef T value_type;
0013 typedef typename std::vector<T>::size_type size_type;
0014
0015 SimpleMatrix(size_type rows, size_type cols) : width(cols), height(rows), container(rows * cols) {}
0016
0017 ~SimpleMatrix() {}
0018
0019 inline size_type rows() const { return height; }
0020 inline size_type cols() const { return width; }
0021 inline size_type size() const { return container.size(); }
0022
0023 inline double &operator()(size_type row, size_type col) { return container[index(row, col)]; }
0024 inline double operator()(size_type row, size_type col) const { return container[index(row, col)]; }
0025
0026 inline double &operator[](size_type index) { return container[index]; }
0027 inline double operator[](size_type index) const { return container[index]; }
0028
0029 inline size_type row(size_type index) const { return index / width; }
0030 inline size_type col(size_type index) const { return index % width; }
0031
0032 protected:
0033 size_type index(size_type row, size_type col) const { return row * width + col; }
0034
0035 private:
0036 size_type width, height;
0037 std::vector<T> container;
0038 };
0039
0040 }
0041
0042 #endif