AIToolbox
A library that offers tools for AI problem solving.
StorageEigen.hpp
Go to the documentation of this file.
1 #ifndef AI_TOOLBOX_UTILS_STORAGE_EIGEN_HEADER_FILE
2 #define AI_TOOLBOX_UTILS_STORAGE_EIGEN_HEADER_FILE
3 
4 #include <AIToolbox/Types.hpp>
5 
6 namespace AIToolbox {
16  class StorageVector {
17  private:
18  Vector storage_;
19 
20  public:
24  Eigen::Ref<Vector> vector;
25 
31  StorageVector(size_t startSize);
32 
39 
45  void pop_back(size_t num = 1);
46 
52  void push_back(double val);
53 
62  void resize(size_t size);
63 
72  void reserve(size_t size);
73  };
74 
87  private:
88  Matrix2D storage_;
89 
90  public:
94  Eigen::Ref<Matrix2D> matrix;
95 
102  StorageMatrix2D(size_t startRows, size_t cols);
103 
110 
116  void pop_back(size_t num = 1);
117 
124  void push_back();
125 
131  template <typename V>
132  void push_back(const Eigen::MatrixBase<V> & row);
133 
142  void resize(size_t rows);
143 
152  void reserve(size_t rows);
153  };
154 
155  template <typename V>
156  void StorageMatrix2D::push_back(const Eigen::MatrixBase<V> & row) {
157  const auto currRows = matrix.rows();
158 
159  if (storage_.rows() == currRows)
160  storage_.conservativeResize(currRows * 2, Eigen::NoChange);
161 
162  storage_.row(currRows) = row;
163 
164  new (&matrix) Eigen::Ref<Matrix2D>(storage_.topRows(currRows + 1));
165  }
166 }
167 
168 #endif
AIToolbox::StorageMatrix2D::pop_back
void pop_back(size_t num=1)
This function removes rows from the view matrix.
AIToolbox::StorageVector::reserve
void reserve(size_t size)
This function reserves space in the underlying storage.
AIToolbox::StorageMatrix2D
This class provides an Eigen-compatible automatically resized Matrix2D.
Definition: StorageEigen.hpp:86
AIToolbox::StorageVector::push_back
void push_back(double val)
This function inserts a value in storage, and expands the view accordingly.
AIToolbox::Matrix2D
Eigen::Matrix< double, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor|Eigen::AutoAlign > Matrix2D
Definition: Types.hpp:18
AIToolbox::StorageMatrix2D::reserve
void reserve(size_t rows)
This function reserves row space in the underlying storage.
AIToolbox::Vector
Eigen::Matrix< double, Eigen::Dynamic, 1 > Vector
Definition: Types.hpp:16
AIToolbox::StorageVector::vector
Eigen::Ref< Vector > vector
This member provides a view of the pushed data.
Definition: StorageEigen.hpp:24
AIToolbox
Definition: Experience.hpp:6
AIToolbox::StorageMatrix2D::resize
void resize(size_t rows)
This function resizes the view to the requested rows.
AIToolbox::StorageVector::StorageVector
StorageVector(size_t startSize)
Basic constructor.
Types.hpp
AIToolbox::StorageMatrix2D::matrix
Eigen::Ref< Matrix2D > matrix
This member provides a view of the pushed data.
Definition: StorageEigen.hpp:94
AIToolbox::StorageVector
This class provides an Eigen-compatible automatically resized Vector.
Definition: StorageEigen.hpp:16
AIToolbox::StorageMatrix2D::StorageMatrix2D
StorageMatrix2D(size_t startRows, size_t cols)
Basic constructor.
AIToolbox::StorageMatrix2D::push_back
void push_back()
This function inserts a new row in storage, and expands the view accordingly.
AIToolbox::StorageVector::resize
void resize(size_t size)
This function resizes the view to the requested size.
AIToolbox::StorageVector::pop_back
void pop_back(size_t num=1)
This function removes elements from the view vector.