SMT-RAT  24.02
Toolbox for Strategic and Parallel Satisfiability-Modulo-Theories Solving
eigen_helpers.h
Go to the documentation of this file.
2 
3 #include <eigen3/Eigen/Core>
4 #include <eigen3/Eigen/Dense>
5 #include <eigen3/Eigen/StdVector>
6 
7 namespace smtrat::qe::fm {
8 
9 using vector_t = Eigen::Matrix<Rational, Eigen::Dynamic, 1>;
10 using matrix_t = Eigen::Matrix<Rational, Eigen::Dynamic, Eigen::Dynamic>;
11 
12 
13 matrix_t selectRows(const matrix_t &original, const std::vector<std::size_t> &rowIndices) {
14  matrix_t res = matrix_t(rowIndices.size(), original.cols());
15  for (Eigen::Index index = 0; index < res.rows(); index++) {
16  res.row(index) = original.row(Eigen::Index(rowIndices[index]));
17  }
18  return res;
19 }
20 
21 
22 matrix_t removeRows(const matrix_t &original, const std::vector<std::size_t> &rowIndices) {
23  // compute all rows that need to remain, select those.
24  std::vector<std::size_t> remainingRows;
25  for (Eigen::Index i = 0; i < original.rows(); ++i) {
26  if (std::find(rowIndices.begin(), rowIndices.end(), std::size_t(i)) == rowIndices.end()) {
27  remainingRows.emplace_back(i);
28  }
29  }
30  return selectRows(original, remainingRows);
31 }
32 
33 matrix_t &appendRow(matrix_t &original, const vector_t &row) {
34  assert(row.rows() == original.cols());
35  original.conservativeResize(original.rows() + 1, original.cols());
36  original.row(original.rows() - 1) = row;
37  return original;
38 }
39 
40 matrix_t &concatenateVertically(matrix_t &original, const matrix_t &other) {
41  assert(original.cols() == other.cols());
42  Eigen::Index originalRowCount = original.rows();
43  original.conservativeResize(original.rows() + other.rows(), original.cols());
44  original.block(originalRowCount, 0, other.rows(), other.cols()) = other;
45  return original;
46 }
47 
48 vector_t &concatenateVertically(vector_t &original, const vector_t &other) {
49  Eigen::Index originalRowCount = original.rows();
50  original.conservativeResize(original.rows() + other.rows(), original.cols());
51  original.block(originalRowCount, 0, other.rows(), other.cols()) = other;
52  return original;
53 }
54 
55 vector_t &appendRow(vector_t &original, Rational entry) {
56  original.conservativeResize(original.rows() + 1);
57  original(original.rows() - 1) = entry;
58  return original;
59 }
60 
61 /**
62  * @brief Append a specified number of zeroes at the end of a vector_t
63  * @tparam Number The used number type
64  * @param original The original vector
65  * @param numberZeroes The number of zeroes that should be appended to original
66  * @return A reference to the updated vector_t
67  */
68 vector_t appendZeroes(vector_t &original, std::size_t numberZeroes) {
69  auto oldSize = original.rows();
70  original.conservativeResize(original.rows() + numberZeroes);
71  original.block(oldSize, 0, 1, numberZeroes) = vector_t::Zero(numberZeroes);
72  return original;
73 }
74 
75 
76 vector_t selectRows(const vector_t &original, const std::vector<std::size_t> &rowIndices) {
77  vector_t res = vector_t(rowIndices.size());
78  for (Eigen::Index index = 0; index < res.rows(); index++) {
79  res(index) = original(Eigen::Index(rowIndices[index]));
80  }
81  return res;
82 }
83 
84 
85 vector_t removeRows(const vector_t &original, const std::vector<std::size_t> &rowIndices) {
86  return vector_t(removeRows(matrix_t(original), rowIndices));
87 }
88 
89 
90 matrix_t removeCol(const matrix_t &original, std::size_t colIndex) {
91  if (colIndex == 0) {
92  return original.block(0, 1, original.rows(), original.cols() - 1);
93  }
94  if (Eigen::Index(colIndex) == original.cols() - 1) {
95  return original.block(0, 0, original.rows(), original.cols() - 1);
96  }
97  matrix_t res = matrix_t(original.rows(), original.cols() - 1);
98  res.block(0, 0, original.rows(), colIndex) = original.leftCols(colIndex);
99  res.block(0, colIndex, original.rows(), original.cols() - (colIndex + 1)) = original.rightCols(
100  original.cols() - (colIndex + 1));
101  return res;
102 }
103 
104 
105 matrix_t selectCols(const matrix_t &original, const std::vector<std::size_t> &colIndices) {
106  matrix_t res = matrix_t(original.rows(), Eigen::Index(colIndices.size()));
107  for (Eigen::Index index = 0; index < res.cols(); index++) {
108  res.col(index) = original.col(Eigen::Index(colIndices[index]));
109  }
110  return res;
111 }
112 
113 }
static bool find(V &ts, const T &t)
Definition: Alg.h:47
matrix_t & concatenateVertically(matrix_t &original, const matrix_t &other)
Definition: eigen_helpers.h:40
matrix_t removeRows(const matrix_t &original, const std::vector< std::size_t > &rowIndices)
Definition: eigen_helpers.h:22
matrix_t selectCols(const matrix_t &original, const std::vector< std::size_t > &colIndices)
Eigen::Matrix< Rational, Eigen::Dynamic, Eigen::Dynamic > matrix_t
Definition: eigen_helpers.h:10
Eigen::Matrix< Rational, Eigen::Dynamic, 1 > vector_t
Definition: eigen_helpers.h:9
matrix_t selectRows(const matrix_t &original, const std::vector< std::size_t > &rowIndices)
Definition: eigen_helpers.h:13
matrix_t & appendRow(matrix_t &original, const vector_t &row)
Definition: eigen_helpers.h:33
matrix_t removeCol(const matrix_t &original, std::size_t colIndex)
Definition: eigen_helpers.h:90
vector_t appendZeroes(vector_t &original, std::size_t numberZeroes)
Append a specified number of zeroes at the end of a vector_t.
Definition: eigen_helpers.h:68
mpq_class Rational
Definition: types.h:19