17#include <unordered_set>
27#pragma GCC diagnostic push
28#if !defined(__clang__) && defined(__GNUC__)
29 #pragma GCC diagnostic ignored "-Wvirtual-move-assign"
47template<
typename Scalar,
int Rows,
int Cols>
51 Eigen::Matrix<Scalar, Rows, Cols>
matrix;
54 template<
typename Scalar_,
typename RowKeyType_,
typename ColKeyType_,
int Rows_,
int Cols_>
56 template<
typename Scalar_,
typename RowKeyType_,
int Rows_>
58 template<
typename Scalar_,
typename ColKeyType_,
int Cols_>
69template<
typename Scalar,
typename RowKeyType,
int Rows,
int Cols>
74 [[nodiscard]]
decltype(
auto)
rows()
const {
return this->
matrix.rows(); }
85 bool hasRows(
const std::vector<RowKeyType>& keys)
const
87 return std::all_of(keys.begin(), keys.end(), [&](
const RowKeyType& key) { return hasRow(key); });
92 bool hasAnyRows(
const std::vector<RowKeyType>& keys)
const
94 return std::any_of(keys.begin(), keys.end(), [&](
const RowKeyType& key) { return hasRow(key); });
120 template<
typename Scalar_,
typename RowKeyType_,
typename ColKeyType_,
int Rows_,
int Cols_>
122 template<
typename Scalar_,
typename RowKeyType_,
int Rows_>
131template<
typename Scalar,
typename RowKeyType,
int Rows,
int Cols>
139template<
typename Scalar,
typename RowKeyType,
int Cols>
145 void addRow(
const RowKeyType& rowKey) { addRows({ rowKey }); }
154 auto initialSize =
static_cast<Eigen::Index
>(this->
rowIndices.size());
157 std::copy(
rowKeys.begin(),
rowKeys.end(), std::back_inserter(this->rowKeysVector));
158 auto finalSize =
static_cast<Eigen::Index
>(this->
rowIndices.size());
160 if (finalSize > initialSize)
162 this->
matrix.conservativeResize(finalSize, Eigen::NoChange);
163 this->
matrix.block(initialSize, 0, finalSize - initialSize, this->
matrix.cols()) = Eigen::MatrixX<Scalar>::Zero(finalSize - initialSize, this->
matrix.cols());
176 std::vector<int> indices;
177 for (
const auto& rowKey :
rowKeys)
179 auto iter = std::find_if(this->
rowIndices.begin(), this->rowIndices.end(), [&](
const auto& item) { return item.first == rowKey; });
183 indices.push_back(
static_cast<int>(iter->second));
188 for (
const auto& rowKey :
rowKeys)
190 auto iter = std::find_if(this->
rowIndices.begin(), this->rowIndices.end(), [&](
const auto& item) { return item.first == rowKey; });
193 std::erase_if(this->
rowKeysVector, [&](
const auto& item) {
return item == rowKey; });
195 auto idx = iter->second;
198 if (rowIndex.second > idx) { rowIndex.second--; }
213template<
typename Scalar,
typename ColKeyType,
int Rows,
int Cols>
218 [[nodiscard]]
decltype(
auto)
cols()
const {
return this->
matrix.cols(); }
229 bool hasCols(
const std::vector<ColKeyType>& keys)
const
231 return std::all_of(keys.begin(), keys.end(), [&](
const ColKeyType& key) { return hasCol(key); });
238 return std::any_of(keys.begin(), keys.end(), [&](
const ColKeyType& key) { return hasCol(key); });
264 template<
typename Scalar_,
typename RowKeyType_,
typename ColKeyType_,
int Rows_,
int Cols_>
266 template<
typename Scalar_,
typename ColKeyType_,
int Cols_>
275template<
typename Scalar,
typename ColKeyType,
int Rows,
int Cols>
283template<
typename Scalar,
typename ColKeyType,
int Rows>
289 void addCol(
const ColKeyType& colKey) { addCols({ colKey }); }
298 auto initialSize =
static_cast<Eigen::Index
>(this->
colIndices.size());
301 std::copy(
colKeys.begin(),
colKeys.end(), std::back_inserter(this->colKeysVector));
302 auto finalSize =
static_cast<Eigen::Index
>(this->
colIndices.size());
304 if (finalSize > initialSize)
306 this->
matrix.conservativeResize(Eigen::NoChange, finalSize);
307 this->
matrix.block(0, initialSize, this->
matrix.rows(), finalSize - initialSize) = Eigen::MatrixX<Scalar>::Zero(this->
matrix.rows(), finalSize - initialSize);
320 std::vector<int> indices;
321 for (
const auto& colKey :
colKeys)
323 auto iter = std::find_if(this->
colIndices.begin(), this->colIndices.end(), [&](
const auto& item) { return item.first == colKey; });
327 indices.push_back(
static_cast<int>(iter->second));
332 for (
const auto& colKey :
colKeys)
334 auto iter = std::find_if(this->
colIndices.begin(), this->colIndices.end(), [&](
const auto& item) { return item.first == colKey; });
337 std::erase_if(this->
colKeysVector, [&](
const auto& item) {
return item == colKey; });
339 auto idx = iter->second;
342 if (colIndex.second > idx) { colIndex.second--; }
352template<
typename Scalar,
typename ColKeyType,
int Cols>
353class KeyedRowVectorBase;
359template<
typename Scalar,
typename RowKeyType,
int Rows>
365 template<
typename Derived>
374 template<
typename Derived>
380 INS_ASSERT_USER_ERROR(Rows == Eigen::Dynamic || vector.rows() ==
static_cast<int>(
rowKeys.size()),
"Number of vector rows doesn't correspond to the amount of row keys");
382 for (
size_t i = 0; i <
rowKeys.size(); i++) { this->
rowIndices.insert({ rowKeys.at(i),
static_cast<Eigen::Index
>(i) }); }
408 if (
this == &other) {
return *
this; }
421 this->
matrix = std::move(other.matrix);
422 this->
rowIndices = std::move(other.rowIndices);
430 if (
this == &other) {
return *
this; }
432 this->
matrix = std::move(other.matrix);
433 this->
rowIndices = std::move(other.rowIndices);
449 INS_ASSERT_USER_ERROR(Rows == Eigen::Dynamic || other.
rows() == Rows,
"Can only copy construct dynamic<=>static matrices if the rows match");
477 INS_ASSERT_USER_ERROR(Rows == Eigen::Dynamic || other.rows() == Rows,
"Can only copy construct dynamic<=>static matrices if the rows match");
479 this->
matrix = std::move(other.matrix);
480 this->
rowIndices = std::move(other.rowIndices);
491 INS_ASSERT_USER_ERROR(other.rowKeys() == this->rowKeys(),
"Can only copy assign matrices if the row keys match");
493 this->
matrix = std::move(other.matrix);
494 this->
rowIndices = std::move(other.rowIndices);
523 decltype(
auto)
operator()(
const std::vector<RowKeyType>&
rowKeys)
const
533 decltype(
auto)
operator()(
const std::vector<RowKeyType>&
rowKeys)
546 explicit operator Eigen::Vector<Scalar, Rows>() {
return this->
matrix; }
558 checkContinuousSegment(
rowKeys, P);
560 return this->
matrix.template middleRows<P>(this->
rowIndices.at(rowKeys.at(0)));
568 checkContinuousSegment(
rowKeys, P);
570 return this->
matrix.template middleRows<P>(this->
rowIndices.at(rowKeys.at(0)));
605 void checkContinuousSegment([[maybe_unused]]
const std::vector<RowKeyType>&
rowKeys, [[maybe_unused]]
size_t P)
const
610 std::vector<Eigen::Index> consecutiveRows(
rowKeys.size());
611 std::iota(std::begin(consecutiveRows), std::end(consecutiveRows), this->
rowIndices.at(rowKeys.at(0)));
614 for (
const auto& rowKey :
rowKeys) {
rowIndices.push_back(this->rowIndices.at(rowKey)); }
624template<
typename Scalar,
typename ColKeyType,
int Cols>
630 template<
typename Derived>
639 template<
typename Derived>
645 INS_ASSERT_USER_ERROR(Cols == Eigen::Dynamic || vector.cols() ==
static_cast<Eigen::Index
>(
colKeys.size()),
"Number of vector cols doesn't correspond to the amount of col keys");
647 for (
size_t i = 0; i <
colKeys.size(); i++) { this->
colIndices.insert({ colKeys.at(i),
static_cast<Eigen::Index
>(i) }); }
673 if (
this == &other) {
return *
this; }
686 this->
matrix = std::move(other.matrix);
687 this->
colIndices = std::move(other.colIndices);
695 if (
this == &other) {
return *
this; }
697 this->
matrix = std::move(other.matrix);
698 this->
colIndices = std::move(other.colIndices);
714 INS_ASSERT_USER_ERROR(Cols == Eigen::Dynamic || other.
cols() == Cols,
"Can only copy construct dynamic<=>static matrices if the cols match");
742 INS_ASSERT_USER_ERROR(Cols == Eigen::Dynamic || other.cols() == Cols,
"Can only copy construct dynamic<=>static matrices if the cols match");
744 this->
matrix = std::move(other.matrix);
745 this->
colIndices = std::move(other.colIndices);
756 INS_ASSERT_USER_ERROR(other.colKeys() == this->colKeys(),
"Can only copy assign matrices if the col keys match");
758 this->
matrix = std::move(other.matrix);
759 this->
colIndices = std::move(other.colIndices);
788 decltype(
auto)
operator()(
const std::vector<ColKeyType>&
colKeys)
const
798 decltype(
auto)
operator()(
const std::vector<ColKeyType>&
colKeys)
811 explicit operator Eigen::RowVector<Scalar, Cols>() {
return this->
matrix; }
823 checkContinuousSegment(
colKeys, Q);
825 return this->
matrix.template middleCols<Q>(this->
colIndices.at(colKeys.at(0)));
833 checkContinuousSegment(
colKeys, Q);
835 return this->
matrix.template middleCols<Q>(this->
colIndices.at(colKeys.at(0)));
870 void checkContinuousSegment([[maybe_unused]]
const std::vector<ColKeyType>&
colKeys, [[maybe_unused]]
size_t Q)
const
875 std::vector<Eigen::Index> consecutiveCols(
colKeys.size());
876 std::iota(std::begin(consecutiveCols), std::end(consecutiveCols), this->
colIndices.at(colKeys.at(0)));
879 for (
const auto& colKey :
colKeys) {
colIndices.push_back(this->colIndices.at(colKey)); }
891template<
typename Scalar,
typename RowKeyType,
typename ColKeyType,
int Rows,
int Cols>
897 template<
typename Derived>
906 template<
typename Derived>
915 INS_ASSERT_USER_ERROR(Rows == Eigen::Dynamic || Rows ==
static_cast<int>(
rowKeys.size()),
"Number of matrix rows doesn't correspond to the static amount of row keys");
916 INS_ASSERT_USER_ERROR(Cols == Eigen::Dynamic || Cols ==
static_cast<int>(
colKeys.size()),
"Number of matrix cols doesn't correspond to the static amount of col keys");
918 for (
size_t i = 0; i <
rowKeys.size(); i++) { this->rowIndices.insert({
rowKeys.at(i),
static_cast<Eigen::Index
>(i) }); }
919 for (
size_t i = 0; i <
colKeys.size(); i++) { this->colIndices.insert({
colKeys.at(i),
static_cast<Eigen::Index
>(i) }); }
950 if (
this == &other) {
return *
this; }
966 this->
matrix = std::move(other.matrix);
967 this->rowIndices = std::move(other.rowIndices);
969 this->colIndices = std::move(other.colIndices);
978 if (
this == &other) {
return *
this; }
980 this->
matrix = std::move(other.matrix);
981 this->rowIndices = std::move(other.rowIndices);
983 this->colIndices = std::move(other.colIndices);
997 template<
int oRows,
int oCols>
1000 INS_ASSERT_USER_ERROR(Rows == Eigen::Dynamic || other.
rows() == Rows,
"Can only copy construct dynamic<=>static matrices if the rows match");
1001 INS_ASSERT_USER_ERROR(Cols == Eigen::Dynamic || other.
cols() == Cols,
"Can only copy construct dynamic<=>static matrices if the cols match");
1013 template<
int oRows,
int oCols>
1033 template<
int oRows,
int oCols>
1036 INS_ASSERT_USER_ERROR(Rows == Eigen::Dynamic || other.rows() == Rows,
"Can only copy construct dynamic<=>static matrices if the rows match");
1037 INS_ASSERT_USER_ERROR(Cols == Eigen::Dynamic || other.cols() == Cols,
"Can only copy construct dynamic<=>static matrices if the cols match");
1039 this->
matrix = std::move(other.matrix);
1040 this->rowIndices = std::move(other.rowIndices);
1042 this->colIndices = std::move(other.colIndices);
1049 template<
int oRows,
int oCols>
1054 INS_ASSERT_USER_ERROR(other.rowKeys() == this->rowKeys(),
"Can only copy assign matrices if the row keys match");
1055 INS_ASSERT_USER_ERROR(other.colKeys() == this->colKeys(),
"Can only copy assign matrices if the col keys match");
1057 this->
matrix = std::move(other.matrix);
1058 this->rowIndices = std::move(other.rowIndices);
1060 this->colIndices = std::move(other.colIndices);
1076 const Scalar&
operator()(
const RowKeyType& rowKey,
const ColKeyType& colKey)
const
1078 return this->
matrix(this->rowIndices.at(rowKey), this->colIndices.at(colKey));
1084 Scalar&
operator()(
const RowKeyType& rowKey,
const ColKeyType& colKey)
1086 return this->
matrix(this->rowIndices.at(rowKey), this->colIndices.at(colKey));
1093 decltype(
auto)
operator()(
const std::vector<RowKeyType>&
rowKeys,
const std::vector<ColKeyType>&
colKeys)
const
1096 for (
const auto& rowKey :
rowKeys) { this->
rowSlice.push_back(this->rowIndices.at(rowKey)); }
1099 for (
const auto& colKey :
colKeys) { this->
colSlice.push_back(this->colIndices.at(colKey)); }
1107 decltype(
auto)
operator()(
const std::vector<RowKeyType>&
rowKeys,
const std::vector<ColKeyType>&
colKeys)
1110 for (
const auto& rowKey :
rowKeys) { this->
rowSlice.push_back(this->rowIndices.at(rowKey)); }
1113 for (
const auto& colKey :
colKeys) { this->
colSlice.push_back(this->colIndices.at(colKey)); }
1121 decltype(
auto)
operator()(
const std::vector<RowKeyType>&
rowKeys,
const ColKeyType& colKey)
const {
return (*
this)(
rowKeys, std::vector{ colKey }); }
1126 decltype(
auto)
operator()(
const std::vector<RowKeyType>&
rowKeys,
const ColKeyType& colKey) {
return (*
this)(
rowKeys, std::vector{ colKey }); }
1131 decltype(
auto)
operator()(
const RowKeyType& rowKey,
const std::vector<ColKeyType>&
colKeys)
const {
return (*
this)(std::vector{ rowKey },
colKeys); }
1136 decltype(
auto)
operator()(
const RowKeyType& rowKey,
const std::vector<ColKeyType>&
colKeys) {
return (*
this)(std::vector{ rowKey },
colKeys); }
1141 decltype(
auto)
operator()(
const RowKeyType& rowKey,
all_t )
const {
return (*
this)(std::vector{ rowKey }, this->
colKeys()); }
1145 decltype(
auto)
operator()(
const RowKeyType& rowKey,
all_t ) {
return (*
this)(std::vector{ rowKey }, this->
colKeys()); }
1149 decltype(
auto)
operator()(
all_t ,
const ColKeyType& colKey)
const {
return *
this(this->
rowKeys(), std::vector{ colKey }); }
1153 decltype(
auto)
operator()(
all_t ,
const ColKeyType& colKey) {
return (*
this)(this->
rowKeys(), std::vector{ colKey }); }
1176 explicit operator Eigen::Matrix<Scalar, Rows, Cols>() {
return this->
matrix; }
1186 template<
size_t P,
size_t Q = P>
1191 return this->
matrix.template block<P, Q>(this->rowIndices.at(
rowKeys.at(0)), this->colIndices.at(
colKeys.at(0)));
1197 template<
size_t P,
size_t Q = P>
1202 return this->
matrix.template block<P, Q>(this->rowIndices.at(
rowKeys.at(0)), this->colIndices.at(
colKeys.at(0)));
1209 decltype(
auto)
block(
const std::vector<RowKeyType>&
rowKeys,
const ColKeyType& colKey)
const
1211 return this->block<P, 1>(
rowKeys, std::vector{ colKey });
1218 decltype(
auto)
block(
const std::vector<RowKeyType>&
rowKeys,
const ColKeyType& colKey)
1220 return this->block<P, 1>(
rowKeys, std::vector{ colKey });
1227 decltype(
auto)
block(
const RowKeyType& rowKey,
const std::vector<ColKeyType>&
colKeys)
const
1229 return this->block<1, Q>(std::vector{ rowKey },
colKeys);
1236 decltype(
auto)
block(
const RowKeyType& rowKey,
const std::vector<ColKeyType>&
colKeys)
1238 return this->block<1, Q>(std::vector{ rowKey },
colKeys);
1249 return this->
matrix.template middleRows<P>(this->rowIndices.at(
rowKeys.at(0)));
1259 return this->
matrix.template middleRows<P>(this->rowIndices.at(
rowKeys.at(0)));
1267 checkContinuousBlock(this->
rowKeys(), colKeys, this->
rowKeys().size(), Q);
1269 return this->
matrix.template middleCols<Q>(this->colIndices.at(
colKeys.at(0)));
1277 checkContinuousBlock(this->
rowKeys(), colKeys, this->
rowKeys().size(), Q);
1279 return this->
matrix.template middleCols<Q>(this->colIndices.at(
colKeys.at(0)));
1284 decltype(
auto)
row(
const RowKeyType& rowKey)
const {
return this->
matrix.row(this->rowIndices.at(rowKey)); }
1288 decltype(
auto)
row(
const RowKeyType& rowKey) {
return this->
matrix.row(this->rowIndices.at(rowKey)); }
1292 decltype(
auto)
col(
const ColKeyType& colKey)
const {
return this->
matrix.col(this->colIndices.at(colKey)); }
1296 decltype(
auto)
col(
const ColKeyType& colKey) {
return this->
matrix.col(this->colIndices.at(colKey)); }
1331 decltype(
auto)
block(
const std::vector<RowKeyType>&
rowKeys,
const ColKeyType& colKey)
const
1333 return this->
block(rowKeys, std::vector{ colKey });
1339 decltype(
auto)
block(
const std::vector<RowKeyType>&
rowKeys,
const ColKeyType& colKey)
1341 return this->
block(rowKeys, std::vector{ colKey });
1347 decltype(
auto)
block(
const RowKeyType& rowKey,
const std::vector<ColKeyType>&
colKeys)
const
1355 decltype(
auto)
block(
const RowKeyType& rowKey,
const std::vector<ColKeyType>&
colKeys)
1365 checkContinuousBlock(
rowKeys, this->
colKeys(), rowKeys.size(), this->colKeys().size());
1374 checkContinuousBlock(
rowKeys, this->
colKeys(), rowKeys.size(), this->colKeys().size());
1419 void checkContinuousBlock([[maybe_unused]]
const std::vector<RowKeyType>&
rowKeys, [[maybe_unused]]
const std::vector<ColKeyType>&
colKeys,
1420 [[maybe_unused]]
size_t P, [[maybe_unused]]
size_t Q)
const
1426 std::vector<Eigen::Index> consecutiveRows(
rowKeys.size());
1427 std::iota(std::begin(consecutiveRows), std::end(consecutiveRows), this->rowIndices.at(
rowKeys.at(0)));
1430 for (
const auto& rowKey :
rowKeys) {
rowIndices.push_back(this->rowIndices.at(rowKey)); }
1433 std::vector<Eigen::Index> consecutiveCols(
colKeys.size());
1434 std::iota(std::begin(consecutiveCols), std::end(consecutiveCols), this->colIndices.at(
colKeys.at(0)));
1437 for (
const auto& colKey :
colKeys) {
colIndices.push_back(this->colIndices.at(colKey)); }
1448template<
typename Scalar,
typename ColKeyType,
int Cols>
1455template<
typename Scalar,
typename RowKeyType,
int Rows>
1463 template<
typename Derived>
1483 if (
this == &other) {
return *
this; }
1499 if (
this == &other) {
return *
this; }
1516 INS_ASSERT_USER_ERROR(other.
rows() == Rows,
"Can only copy assign dynamic matrices from static ones if the size matches");
1524 INS_ASSERT_USER_ERROR(other.
rows() == Rows,
"Can only copy assign dynamic matrices from static ones if the size matches");
1536 INS_ASSERT_USER_ERROR(this->
rows() == Rows,
"Can only move construct dynamic matrices from static ones if the size matches");
1544 INS_ASSERT_USER_ERROR(other.rows() == Rows,
"Can only move assign dynamic matrices from static ones if the size matches");
1560 return { transpose(
all), transpose.colKeys() };
1567template<
typename Scalar,
typename RowKeyType>
1573 : internal::KeyedVectorBase<Scalar, RowKeyType, Eigen::Dynamic>(Eigen::VectorX<Scalar>()) {}
1579 template<
typename Derived>
1581 : internal::KeyedVectorBase<Scalar, RowKeyType, Eigen::Dynamic>(vector,
rowKeys)
1593 : internal::KeyedVectorBase<Scalar, RowKeyType, Eigen::Dynamic>(other)
1599 if (
this == &other) {
return *
this; }
1615 if (
this == &other) {
return *
this; }
1631 : internal::KeyedVectorBase<Scalar, RowKeyType, Eigen::Dynamic>(other)
1672 return { transpose(
all), transpose.colKeys() };
1680template<
typename Scalar,
typename ColKeyType,
int Cols>
1688 template<
typename Derived>
1708 if (
this == &other) {
return *
this; }
1724 if (
this == &other) {
return *
this; }
1741 INS_ASSERT_USER_ERROR(other.
cols() == Cols,
"Can only copy assign dynamic matrices from static ones if the size matches");
1749 INS_ASSERT_USER_ERROR(other.
cols() == Cols,
"Can only copy assign dynamic matrices from static ones if the size matches");
1761 INS_ASSERT_USER_ERROR(this->
cols() == Cols,
"Can only move construct dynamic matrices from static ones if the size matches");
1769 INS_ASSERT_USER_ERROR(other.cols() == Cols,
"Can only move assign dynamic matrices from static ones if the size matches");
1785 return { transpose(
all), transpose.rowKeys() };
1792template<
typename Scalar,
typename ColKeyType>
1799 : internal::KeyedRowVectorBase<Scalar, ColKeyType, Eigen::Dynamic>(Eigen::RowVectorX<Scalar>()) {}
1805 template<
typename Derived>
1807 : internal::KeyedRowVectorBase<Scalar, ColKeyType, Eigen::Dynamic>(vector,
colKeys)
1819 : internal::KeyedRowVectorBase<Scalar, ColKeyType, Eigen::Dynamic>(other)
1825 if (
this == &other) {
return *
this; }
1841 if (
this == &other) {
return *
this; }
1857 : internal::KeyedRowVectorBase<Scalar, ColKeyType, Eigen::Dynamic>(other)
1898 return { transpose(
all), transpose.rowKeys() };
1908template<
typename Scalar,
typename RowKeyType,
typename ColKeyType,
int Rows,
int Cols>
1917 template<
typename Derived>
1926 template<
typename Derived>
1940 : internal::
KeyedMatrixBase<Scalar, RowKeyType, ColKeyType, Rows, Cols>(other)
1946 if (
this == &other) {
return *
this; }
1962 if (
this == &other) {
return *
this; }
1977 : internal::
KeyedMatrixBase<Scalar, RowKeyType, ColKeyType, Rows, Cols>(other)
1979 INS_ASSERT_USER_ERROR(other.
rows() == Rows && other.
cols() == Cols,
"Can only copy assign dynamic matrices from static ones if the size matches");
1987 INS_ASSERT_USER_ERROR(other.
rows() == Rows && other.
cols() == Cols,
"Can only copy assign dynamic matrices from static ones if the size matches");
1999 INS_ASSERT_USER_ERROR(this->
rows() == Rows && this->
cols() == Cols,
"Can only move construct dynamic matrices from static ones if the size matches");
2007 INS_ASSERT_USER_ERROR(other.rows() == Rows && other.cols() == Cols,
"Can only move assign dynamic matrices from static ones if the size matches");
2037 return { transpose(
all,
all), transpose.rowKeys(), transpose.colKeys() };
2044 return { inv(
all,
all), inv.rowKeys(), inv.colKeys() };
2052template<
typename Scalar,
typename RowKeyType,
typename ColKeyType>
2053class KeyedMatrix<Scalar, RowKeyType, ColKeyType, Eigen::Dynamic, Eigen::Dynamic>
2059 : internal::KeyedMatrixBase<Scalar, RowKeyType, ColKeyType, Eigen::Dynamic, Eigen::Dynamic>(Eigen::MatrixX<Scalar>()) {}
2066 template<
typename Derived>
2068 : internal::KeyedMatrixBase<Scalar, RowKeyType, ColKeyType, Eigen::Dynamic, Eigen::Dynamic>(
matrix,
rowKeys,
colKeys)
2075 template<
typename Derived>
2077 :
KeyedMatrix<Scalar, RowKeyType, ColKeyType, Eigen::Dynamic, Eigen::Dynamic>(
matrix, keys, keys)
2089 : internal::KeyedMatrixBase<Scalar, RowKeyType, ColKeyType, Eigen::Dynamic, Eigen::Dynamic>(other)
2095 if (
this == &other) {
return *
this; }
2111 if (
this == &other) {
return *
this; }
2125 template<
int oRows,
int oCols>
2127 : internal::KeyedMatrixBase<Scalar, RowKeyType, ColKeyType, Eigen::Dynamic, Eigen::Dynamic>(other)
2131 template<
int oRows,
int oCols>
2143 template<
int oRows,
int oCols>
2149 template<
int oRows,
int oCols>
2174 auto initialRowSize =
static_cast<Eigen::Index
>(this->rowIndices.size());
2175 for (
const auto& rowKey :
rowKeys) { this->rowIndices.insert({ rowKey,
static_cast<Eigen::Index
>(this->rowIndices.size()) }); }
2177 std::copy(
rowKeys.begin(),
rowKeys.end(), std::back_inserter(this->rowKeysVector));
2178 auto finalRowSize =
static_cast<Eigen::Index
>(this->rowIndices.size());
2180 auto initialColSize =
static_cast<Eigen::Index
>(this->colIndices.size());
2181 for (
const auto& colKey :
colKeys) { this->colIndices.insert({ colKey,
static_cast<Eigen::Index
>(this->colIndices.size()) }); }
2183 std::copy(
colKeys.begin(),
colKeys.end(), std::back_inserter(this->colKeysVector));
2184 auto finalColSize =
static_cast<Eigen::Index
>(this->colIndices.size());
2186 auto rows = finalRowSize - initialRowSize;
2187 auto cols = finalColSize - initialColSize;
2190 this->
matrix.conservativeResize(finalRowSize, finalColSize);
2204 for (
const auto& rowKey :
rowKeys)
2206 auto iter = std::find_if(this->rowIndices.begin(), this->rowIndices.end(), [&](
const auto& item) { return item.first == rowKey; });
2207 INS_ASSERT_USER_ERROR(iter != this->rowIndices.end(),
"You tried removing a row key, which did not exist.");
2208 if (iter != this->rowIndices.end())
2210 rowIndices.push_back(
static_cast<int>(iter->second));
2214 for (
const auto& colKey :
colKeys)
2216 auto iter = std::find_if(this->colIndices.begin(), this->colIndices.end(), [&](
const auto& item) { return item.first == colKey; });
2217 INS_ASSERT_USER_ERROR(iter != this->colIndices.end(),
"You tried removing a col key, which did not exist.");
2218 if (iter != this->colIndices.end())
2220 colIndices.push_back(
static_cast<int>(iter->second));
2226 for (
const auto& rowKey :
rowKeys)
2228 auto iter = std::find_if(this->rowIndices.begin(), this->rowIndices.end(), [&](
const auto& item) { return item.first == rowKey; });
2229 if (iter != this->rowIndices.end())
2231 std::erase_if(this->
rowKeysVector, [&](
const auto& item) {
return item == rowKey; });
2233 auto idx = iter->second;
2236 if (rowIndex.second > idx) { rowIndex.second--; }
2238 this->rowIndices.erase(iter);
2241 for (
const auto& colKey :
colKeys)
2243 auto iter = std::find_if(this->colIndices.begin(), this->colIndices.end(), [&](
const auto& item) { return item.first == colKey; });
2244 if (iter != this->colIndices.end())
2246 std::erase_if(this->
colKeysVector, [&](
const auto& item) {
return item == colKey; });
2248 auto idx = iter->second;
2251 if (colIndex.second > idx) { colIndex.second--; }
2253 this->colIndices.erase(iter);
2280 return { transpose(
all,
all), transpose.rowKeys(), transpose.colKeys() };
2287 return { inv(
all,
all), inv.rowKeys(), inv.colKeys() };
2295template<
typename Scalar,
typename RowKeyType,
typename ColKeyType = RowKeyType>
2300template<
typename RowKeyType,
typename ColKeyType = RowKeyType>
2305template<
typename RowKeyType,
typename ColKeyType = RowKeyType>
2310template<
typename RowKeyType,
typename ColKeyType = RowKeyType>
2315template<
typename RowKeyType,
typename ColKeyType = RowKeyType>
2321template<
typename Scalar,
typename RowKeyType>
2325template<
typename RowKeyType>
2329template<
typename RowKeyType>
2333template<
typename RowKeyType>
2337template<
typename RowKeyType>
2342template<
typename Scalar,
typename ColKeyType>
2346template<
typename ColKeyType>
2350template<
typename ColKeyType>
2354template<
typename ColKeyType>
2358template<
typename ColKeyType>
2363#pragma GCC diagnostic pop
2365#ifndef DOXYGEN_IGNORE
2368template<
typename Scalar,
typename RowKeyType,
typename ColKeyType,
int Rows,
int Cols>
2369struct fmt::formatter<NAV::KeyedMatrix<Scalar, RowKeyType, ColKeyType, Rows, Cols>> : fmt::formatter<std::string>
2378 auto rows =
static_cast<size_t>(mat.
rows());
2379 auto cols =
static_cast<size_t>(mat.
cols());
2381 if (rows > 0 && cols > 0)
2383 std::vector<std::string> rowKeysStr;
2384 std::vector<size_t> rowKeysLength;
2385 rowKeysStr.reserve(rows);
2386 rowKeysLength.reserve(rows);
2387 size_t rowKeysColSpace = 0;
2388 for (
const auto& rowKey : mat.
rowKeys())
2390 rowKeysStr.push_back(fmt::format(
"{}", rowKey));
2391 auto rowKeyLength = rowKeysStr.back().length();
2392 rowKeysColSpace = std::max(rowKeysColSpace, rowKeyLength);
2393 rowKeysLength.push_back(rowKeyLength);
2396 constexpr size_t colMinLength = 9UL;
2398 std::vector<std::string> colKeysStr;
2399 std::vector<size_t> colKeysLength;
2400 size_t rowLineLength = rowKeysColSpace + 1;
2401 colKeysStr.reserve(cols);
2402 colKeysLength.reserve(cols);
2403 for (
const auto& colKey : mat.
colKeys())
2405 colKeysStr.push_back(fmt::format(
"{}", colKey));
2406 auto colKeyLength = colKeysStr.back().length();
2407 colKeysLength.push_back(colKeyLength);
2408 rowLineLength += 2 + std::max(colKeysStr.back().length(), colMinLength);
2411 result.reserve((rows + 1) * rowLineLength);
2413 result +=
" " + std::string(rowKeysColSpace,
' ');
2414 for (
size_t c = 0; c < cols; c++)
2417 if (colMinLength > colKeysLength.at(c))
2419 result += std::string(colMinLength - colKeysLength.at(c),
' ');
2421 result += colKeysStr.at(c);
2425 for (
size_t r = 0; r < rows; r++)
2427 if (rowKeysColSpace > rowKeysLength.at(r))
2429 result += std::string(rowKeysColSpace - rowKeysLength.at(r),
' ');
2431 result += rowKeysStr.at(r) +
" ";
2432 for (
size_t c = 0; c < cols; c++)
2434 auto colLength = std::max(colKeysStr.at(c).length(), colMinLength);
2436 std::string tmp = fmt::format(
" {:> {}.{}g}", mat(NAV::all, NAV::all)(
static_cast<int>(r),
static_cast<int>(c)), colLength, colLength - 2);
2437 if (tmp.length() > colLength)
2439 tmp = fmt::format(
" {:> {}.{}g}", mat(NAV::all, NAV::all)(
static_cast<int>(r),
static_cast<int>(c)), colLength, colLength - 6);
2443 if (r != rows - 1) { result +=
'\n'; }
2447 return fmt::formatter<std::string>::format(result, ctx);
2452template<
typename Scalar,
typename RowKeyType,
int Rows>
2453struct fmt::formatter<NAV::KeyedVector<Scalar, RowKeyType, Rows>> : fmt::formatter<std::string>
2462 auto rows =
static_cast<size_t>(vec.
rows());
2466 std::vector<std::string> rowKeysStr;
2467 std::vector<size_t> rowKeysLength;
2468 rowKeysStr.reserve(rows);
2469 rowKeysLength.reserve(rows);
2470 size_t rowKeysColSpace = 0;
2471 for (
const auto& rowKey : vec.rowKeys())
2473 rowKeysStr.push_back(fmt::format(
"{}", rowKey));
2474 auto rowKeyLength = rowKeysStr.back().length();
2475 rowKeysColSpace = std::max(rowKeysColSpace, rowKeyLength);
2476 rowKeysLength.push_back(rowKeyLength);
2479 size_t colLength = 9UL;
2481 result.reserve(rows * (rowKeysColSpace + 2 + colLength));
2483 for (
size_t r = 0; r < rows; r++)
2485 if (rowKeysColSpace > rowKeysLength.at(r))
2487 result += std::string(rowKeysColSpace - rowKeysLength.at(r),
' ');
2489 result += rowKeysStr.at(r);
2491 std::string tmp = fmt::format(
" {:> {}.{}g}", vec(NAV::all)(
static_cast<int>(r)), colLength, colLength - 2);
2492 if (tmp.length() > colLength)
2494 tmp = fmt::format(
" {:> {}.{}g}", vec(NAV::all)(
static_cast<int>(r)), colLength, colLength - 6);
2498 if (r != rows - 1) { result +=
'\n'; }
2502 return fmt::formatter<std::string>::format(result, ctx);
2507template<
typename Scalar,
typename ColKeyType,
int Cols>
2508struct fmt::formatter<NAV::KeyedRowVector<Scalar, ColKeyType, Cols>> : fmt::formatter<std::string>
2517 auto cols =
static_cast<size_t>(vec.
cols());
2521 size_t colMinLength = 9UL;
2523 std::vector<std::string> colKeysStr;
2524 std::vector<size_t> colKeysLength;
2525 size_t rowLineLength = 1;
2526 colKeysStr.reserve(cols);
2527 colKeysLength.reserve(cols);
2528 for (
const auto& colKey : vec.colKeys())
2530 colKeysStr.push_back(fmt::format(
"{}", colKey));
2531 auto colKeyLength = colKeysStr.back().length();
2532 colKeysLength.push_back(colKeyLength);
2533 rowLineLength += 2 + std::max(colKeysStr.back().length(), colMinLength);
2536 result.reserve(2 * rowLineLength);
2538 for (
size_t c = 0; c < cols; c++)
2540 if (c != 0) { result +=
" "; }
2541 if (colMinLength > colKeysLength.at(c))
2543 result += std::string(colMinLength - colKeysLength.at(c),
' ');
2545 result += colKeysStr.at(c);
2550 for (
size_t c = 0; c < cols; c++)
2552 auto colLength = std::max(colKeysStr.at(c).length(), colMinLength);
2553 if (c != 0) { result +=
" "; }
2554 std::string tmp = fmt::format(
"{:> {}.{}g}", vec(NAV::all)(
static_cast<int>(c)), colLength, colLength - 2);
2555 if (tmp.length() > colLength)
2557 tmp = fmt::format(
"{:> {}.{}g}", vec(NAV::all)(
static_cast<int>(c)), colLength, colLength - 6);
2563 return fmt::formatter<std::string>::format(result, ctx);
2573template<
typename Scalar,
typename RowKeyType,
typename ColKeyType,
int Rows,
int Cols>
2576 return os << fmt::format(
"{}", obj);
2582template<
typename Scalar,
typename RowKeyType,
int Rows>
2585 return os << fmt::format(
"{}", obj);
2591template<
typename Scalar,
typename ColKeyType,
int Cols>
2594 return os << fmt::format(
"{}", obj);
#define INS_ASSERT_USER_ERROR(_EXP, _MSG)
Assert function with message.
Definition Assert.h:21
void removeRows(Eigen::DenseBase< Derived > &matrix, size_t index, size_t length)
Removes rows from a matrix or vector.
Definition Eigen.hpp:116
void removeCols(Eigen::DenseBase< Derived > &matrix, size_t index, size_t length)
Removes columns from a matrix or vector.
Definition Eigen.hpp:152
void removeRowsAndCols(Eigen::DenseBase< Derived > &matrix, size_t row, size_t rows, size_t col, size_t cols)
Removes rows and columns from a matrix or vector.
Definition Eigen.hpp:190
ankerl::unordered_dense::map< Key, T > unordered_map
Unordered map type.
Definition Unordered_map.hpp:34
Dynamic sized KeyedMatrix.
Definition KeyedMatrix.hpp:2055
KeyedMatrix< Scalar, RowKeyType, ColKeyType, Eigen::Dynamic, Eigen::Dynamic > transposed() const
Calculates the transposed matrix.
Definition KeyedMatrix.hpp:2277
KeyedMatrix< Scalar, RowKeyType, ColKeyType, Eigen::Dynamic, Eigen::Dynamic > getSubMatrix(const std::vector< RowKeyType > &rowKeys, const std::vector< ColKeyType > &colKeys) const
Returns a submatrix specified by the row and col keys.
Definition KeyedMatrix.hpp:2266
KeyedMatrix(const Eigen::MatrixBase< Derived > &matrix, const std::vector< RowKeyType > &rowKeys, const std::vector< ColKeyType > &colKeys)
Non-symmetric matrix constructor.
Definition KeyedMatrix.hpp:2067
KeyedMatrix & operator=(KeyedMatrix &&other) noexcept
Move assignment operator.
Definition KeyedMatrix.hpp:2109
KeyedMatrix(KeyedMatrix< Scalar, RowKeyType, ColKeyType, oRows, oCols > &&other) noexcept
Move constructor.
Definition KeyedMatrix.hpp:2144
~KeyedMatrix()=default
Destructor.
KeyedMatrix(const KeyedMatrix &other)
Copy constructor.
Definition KeyedMatrix.hpp:2088
KeyedMatrix(KeyedMatrix &&other) noexcept
Move constructor.
Definition KeyedMatrix.hpp:2104
KeyedMatrix & operator=(const KeyedMatrix< Scalar, RowKeyType, ColKeyType, oRows, oCols > &other)
Copy assignment operator.
Definition KeyedMatrix.hpp:2132
void addRowsCols(const std::vector< RowKeyType > &rowKeys, const std::vector< ColKeyType > &colKeys)
Adds new rows and cols to the matrix.
Definition KeyedMatrix.hpp:2167
KeyedMatrix(const Eigen::MatrixBase< Derived > &matrix, const std::vector< RowKeyType > &keys)
Symmetric matrix constructor.
Definition KeyedMatrix.hpp:2076
KeyedMatrix & operator=(const KeyedMatrix &other)
Copy assignment operator.
Definition KeyedMatrix.hpp:2093
KeyedMatrix & operator=(KeyedMatrix< Scalar, RowKeyType, ColKeyType, oRows, oCols > &&other) noexcept
Move assignment operator.
Definition KeyedMatrix.hpp:2150
KeyedMatrix(const KeyedMatrix< Scalar, RowKeyType, ColKeyType, oRows, oCols > &other)
Copy constructor.
Definition KeyedMatrix.hpp:2126
void removeRowsCols(const std::vector< RowKeyType > &rowKeys, const std::vector< ColKeyType > &colKeys)
Removes the rows and cols from the matrix.
Definition KeyedMatrix.hpp:2201
KeyedMatrix()
Default Constructor.
Definition KeyedMatrix.hpp:2058
KeyedMatrix< Scalar, RowKeyType, ColKeyType, Eigen::Dynamic, Eigen::Dynamic > inverse() const
Calculates the inverse matrix.
Definition KeyedMatrix.hpp:2284
Static sized KeyedMatrix.
Definition KeyedMatrix.hpp:1910
KeyedMatrix(const KeyedMatrix< Scalar, RowKeyType, ColKeyType, Eigen::Dynamic, Eigen::Dynamic > &other)
Copy constructor.
Definition KeyedMatrix.hpp:1976
KeyedMatrix(const KeyedMatrix &other)
Copy constructor.
Definition KeyedMatrix.hpp:1939
KeyedMatrix & operator=(const KeyedMatrix &other)
Copy assignment operator.
Definition KeyedMatrix.hpp:1944
~KeyedMatrix()=default
Destructor.
KeyedMatrix(const Eigen::MatrixBase< Derived > &matrix, const std::vector< RowKeyType > &rowKeys, const std::vector< ColKeyType > &colKeys)
Non-symmetric matrix constructor.
Definition KeyedMatrix.hpp:1918
KeyedMatrix< Scalar, RowKeyType, ColKeyType, Eigen::Dynamic, Eigen::Dynamic > getSubMatrix(const std::vector< RowKeyType > &rowKeys, const std::vector< ColKeyType > &colKeys) const
Returns a submatrix specified by the row and col keys.
Definition KeyedMatrix.hpp:2023
KeyedMatrix< Scalar, RowKeyType, ColKeyType, Rows, Cols > transposed() const
Calculates the transposed matrix.
Definition KeyedMatrix.hpp:2034
KeyedMatrix & operator=(const KeyedMatrix< Scalar, RowKeyType, ColKeyType, Eigen::Dynamic, Eigen::Dynamic > &other)
Copy assignment operator.
Definition KeyedMatrix.hpp:1983
KeyedMatrix & operator=(KeyedMatrix &&other) noexcept
Move assignment operator.
Definition KeyedMatrix.hpp:1960
KeyedMatrix(const Eigen::MatrixBase< Derived > &matrix, const std::vector< RowKeyType > &keys)
Symmetric matrix constructor.
Definition KeyedMatrix.hpp:1927
KeyedMatrix< Scalar, RowKeyType, ColKeyType, Rows, Cols > inverse() const
Calculates the inverse matrix.
Definition KeyedMatrix.hpp:2041
KeyedMatrix(KeyedMatrix &&other) noexcept
Move constructor.
Definition KeyedMatrix.hpp:1955
KeyedMatrix & operator=(KeyedMatrix< Scalar, RowKeyType, ColKeyType, Eigen::Dynamic, Eigen::Dynamic > &&other) noexcept
Move assignment operator.
Definition KeyedMatrix.hpp:2003
KeyedMatrix(KeyedMatrix< Scalar, RowKeyType, ColKeyType, Eigen::Dynamic, Eigen::Dynamic > &&other) noexcept
Move constructor.
Definition KeyedMatrix.hpp:1996
Dynamic sized KeyedRowVector.
Definition KeyedMatrix.hpp:1795
KeyedRowVector(KeyedRowVector &&other) noexcept
Move constructor.
Definition KeyedMatrix.hpp:1834
KeyedRowVector & operator=(KeyedRowVector &&other) noexcept
Move assignment operator.
Definition KeyedMatrix.hpp:1839
~KeyedRowVector()=default
Destructor.
KeyedRowVector(KeyedRowVector< Scalar, ColKeyType, oCols > &&other) noexcept
Move constructor.
Definition KeyedMatrix.hpp:1874
KeyedRowVector & operator=(const KeyedRowVector &other)
Copy assignment operator.
Definition KeyedMatrix.hpp:1823
KeyedRowVector()
Default Constructor.
Definition KeyedMatrix.hpp:1798
KeyedRowVector & operator=(KeyedRowVector< Scalar, ColKeyType, oCols > &&other) noexcept
Move assignment operator.
Definition KeyedMatrix.hpp:1880
KeyedRowVector(const Eigen::MatrixBase< Derived > &vector, const std::vector< ColKeyType > &colKeys)
RowVector constructor.
Definition KeyedMatrix.hpp:1806
KeyedVector< Scalar, ColKeyType, Eigen::Dynamic > transposed() const
Calculates the transposed vector.
Definition KeyedMatrix.hpp:1895
KeyedRowVector & operator=(const KeyedRowVector< Scalar, ColKeyType, oCols > &other)
Copy assignment operator.
Definition KeyedMatrix.hpp:1862
KeyedRowVector(const KeyedRowVector< Scalar, ColKeyType, oCols > &other)
Copy constructor.
Definition KeyedMatrix.hpp:1856
KeyedRowVector(const KeyedRowVector &other)
Copy constructor.
Definition KeyedMatrix.hpp:1818
Static sized KeyedRowVector.
Definition KeyedMatrix.hpp:1682
KeyedRowVector(KeyedRowVector &&other) noexcept
Move constructor.
Definition KeyedMatrix.hpp:1717
~KeyedRowVector()=default
Destructor.
KeyedRowVector & operator=(KeyedRowVector &&other) noexcept
Move assignment operator.
Definition KeyedMatrix.hpp:1722
KeyedRowVector(KeyedRowVector< Scalar, ColKeyType, Eigen::Dynamic > &&other) noexcept
Move constructor.
Definition KeyedMatrix.hpp:1758
KeyedRowVector(const KeyedRowVector &other)
Copy constructor.
Definition KeyedMatrix.hpp:1701
KeyedVector< Scalar, ColKeyType, Cols > transposed() const
Calculates the transposed vector.
Definition KeyedMatrix.hpp:1782
KeyedRowVector(const Eigen::MatrixBase< Derived > &vector, const std::vector< ColKeyType > &colKeys)
RowVector constructor.
Definition KeyedMatrix.hpp:1689
KeyedRowVector(const KeyedRowVector< Scalar, ColKeyType, Eigen::Dynamic > &other)
Copy constructor.
Definition KeyedMatrix.hpp:1738
KeyedRowVector & operator=(const KeyedRowVector< Scalar, ColKeyType, Eigen::Dynamic > &other)
Copy assignment operator.
Definition KeyedMatrix.hpp:1745
KeyedRowVector & operator=(const KeyedRowVector &other)
Copy assignment operator.
Definition KeyedMatrix.hpp:1706
KeyedRowVector & operator=(KeyedRowVector< Scalar, ColKeyType, Eigen::Dynamic > &&other) noexcept
Move assignment operator.
Definition KeyedMatrix.hpp:1765
Dynamic sized KeyedVector.
Definition KeyedMatrix.hpp:1569
KeyedVector(KeyedVector< Scalar, RowKeyType, oRows > &&other) noexcept
Move constructor.
Definition KeyedMatrix.hpp:1648
KeyedVector(const KeyedVector< Scalar, RowKeyType, oRows > &other)
Copy constructor.
Definition KeyedMatrix.hpp:1630
KeyedVector(const Eigen::MatrixBase< Derived > &vector, const std::vector< RowKeyType > &rowKeys)
Vector constructor.
Definition KeyedMatrix.hpp:1580
~KeyedVector()=default
Destructor.
KeyedVector(KeyedVector &&other) noexcept
Move constructor.
Definition KeyedMatrix.hpp:1608
KeyedVector()
Default Constructor.
Definition KeyedMatrix.hpp:1572
KeyedRowVector< Scalar, RowKeyType, Eigen::Dynamic > transposed() const
Calculates the transposed vector.
Definition KeyedMatrix.hpp:1669
KeyedVector & operator=(const KeyedVector &other)
Copy assignment operator.
Definition KeyedMatrix.hpp:1597
KeyedVector(const KeyedVector &other)
Copy constructor.
Definition KeyedMatrix.hpp:1592
KeyedVector & operator=(KeyedVector &&other) noexcept
Move assignment operator.
Definition KeyedMatrix.hpp:1613
KeyedVector & operator=(const KeyedVector< Scalar, RowKeyType, oRows > &other)
Copy assignment operator.
Definition KeyedMatrix.hpp:1636
KeyedVector & operator=(KeyedVector< Scalar, RowKeyType, oRows > &&other) noexcept
Move assignment operator.
Definition KeyedMatrix.hpp:1654
Static sized KeyedVector.
Definition KeyedMatrix.hpp:1457
KeyedVector(KeyedVector< Scalar, RowKeyType, Eigen::Dynamic > &&other) noexcept
Move constructor.
Definition KeyedMatrix.hpp:1533
KeyedVector(const KeyedVector &other)
Copy constructor.
Definition KeyedMatrix.hpp:1476
KeyedVector(const Eigen::MatrixBase< Derived > &vector, const std::vector< RowKeyType > &rowKeys)
Vector constructor.
Definition KeyedMatrix.hpp:1464
KeyedVector & operator=(KeyedVector &&other) noexcept
Move assignment operator.
Definition KeyedMatrix.hpp:1497
KeyedVector(KeyedVector &&other) noexcept
Move constructor.
Definition KeyedMatrix.hpp:1492
KeyedVector & operator=(KeyedVector< Scalar, RowKeyType, Eigen::Dynamic > &&other) noexcept
Move assignment operator.
Definition KeyedMatrix.hpp:1540
KeyedVector(const KeyedVector< Scalar, RowKeyType, Eigen::Dynamic > &other)
Copy constructor.
Definition KeyedMatrix.hpp:1513
KeyedVector & operator=(const KeyedVector &other)
Copy assignment operator.
Definition KeyedMatrix.hpp:1481
KeyedRowVector< Scalar, RowKeyType, Rows > transposed() const
Calculates the transposed vector.
Definition KeyedMatrix.hpp:1557
KeyedVector & operator=(const KeyedVector< Scalar, RowKeyType, Eigen::Dynamic > &other)
Copy assignment operator.
Definition KeyedMatrix.hpp:1520
~KeyedVector()=default
Destructor.
Class to inherit common methods for static and dynamic sized matrices.
Definition KeyedMatrix.hpp:893
decltype(auto) row(const RowKeyType &rowKey) const
Gets the values for the row key.
Definition KeyedMatrix.hpp:1284
decltype(auto) middleRows(const std::vector< RowKeyType > &rowKeys)
Gets the values for the row keys.
Definition KeyedMatrix.hpp:1255
KeyedMatrixBase< Scalar, ColKeyType, RowKeyType, Cols, Rows > transposed() const
Calculates the transposed matrix.
Definition KeyedMatrix.hpp:1402
KeyedMatrixBase(const Eigen::MatrixBase< Derived > &matrix, const std::vector< RowKeyType > &rowKeys, const std::vector< ColKeyType > &colKeys)
Non-symmetric matrix constructor.
Definition KeyedMatrix.hpp:907
decltype(auto) block(const RowKeyType &rowKey, const std::vector< ColKeyType > &colKeys)
Gets the values for the row and col keys.
Definition KeyedMatrix.hpp:1355
KeyedMatrixBase(KeyedMatrixBase &&other) noexcept
Move constructor.
Definition KeyedMatrix.hpp:964
Scalar & operator()(const RowKeyType &rowKey, const ColKeyType &colKey)
Gets the value for the row and col key.
Definition KeyedMatrix.hpp:1084
decltype(auto) block(const std::vector< RowKeyType > &rowKeys, const ColKeyType &colKey)
Gets the values for the row and col keys.
Definition KeyedMatrix.hpp:1218
KeyedMatrixBase(const Eigen::MatrixBase< Derived > &matrix)
Constructor.
Definition KeyedMatrix.hpp:898
const Eigen::Matrix< Scalar, Rows, Cols > & block(all_t, all_t) const
Requests the full matrix.
Definition KeyedMatrix.hpp:1299
decltype(auto) middleRows(const std::vector< RowKeyType > &rowKeys)
Gets the values for the row keys.
Definition KeyedMatrix.hpp:1372
decltype(auto) row(const RowKeyType &rowKey)
Gets the values for the row key.
Definition KeyedMatrix.hpp:1288
decltype(auto) block(const RowKeyType &rowKey, const std::vector< ColKeyType > &colKeys) const
Gets the values for the row and col keys.
Definition KeyedMatrix.hpp:1347
KeyedMatrixBase(const KeyedMatrixBase &other)
Copy constructor.
Definition KeyedMatrix.hpp:936
decltype(auto) middleCols(const std::vector< ColKeyType > &colKeys) const
Gets the values for the col keys.
Definition KeyedMatrix.hpp:1265
Eigen::Matrix< Scalar, Rows, Cols > & operator()(all_t, all_t)
Requests the full matrix.
Definition KeyedMatrix.hpp:1174
KeyedMatrixBase(KeyedMatrixBase< Scalar, RowKeyType, ColKeyType, oRows, oCols > &&other) noexcept
Move constructor.
Definition KeyedMatrix.hpp:1034
decltype(auto) middleCols(const std::vector< ColKeyType > &colKeys)
Gets the values for the col keys.
Definition KeyedMatrix.hpp:1390
decltype(auto) block(const std::vector< RowKeyType > &rowKeys, const ColKeyType &colKey) const
Gets the values for the row and col keys.
Definition KeyedMatrix.hpp:1209
decltype(auto) middleCols(const std::vector< ColKeyType > &colKeys) const
Gets the values for the col keys.
Definition KeyedMatrix.hpp:1381
KeyedMatrixBase & operator=(const KeyedMatrixBase &other)
Copy assignment operator.
Definition KeyedMatrix.hpp:948
decltype(auto) block(const std::vector< RowKeyType > &rowKeys, const ColKeyType &colKey)
Gets the values for the row and col keys.
Definition KeyedMatrix.hpp:1339
decltype(auto) block(const std::vector< RowKeyType > &rowKeys, const std::vector< ColKeyType > &colKeys) const
Gets the values for the row and col keys.
Definition KeyedMatrix.hpp:1187
decltype(auto) block(const std::vector< RowKeyType > &rowKeys, const std::vector< ColKeyType > &colKeys) const
Gets the values for the row and col keys.
Definition KeyedMatrix.hpp:1311
~KeyedMatrixBase()=default
Destructor.
decltype(auto) block(const std::vector< RowKeyType > &rowKeys, const ColKeyType &colKey) const
Gets the values for the row and col keys.
Definition KeyedMatrix.hpp:1331
KeyedMatrixBase & operator=(KeyedMatrixBase< Scalar, RowKeyType, ColKeyType, oRows, oCols > &&other) noexcept
Move assignment operator.
Definition KeyedMatrix.hpp:1050
const Scalar & operator()(const RowKeyType &rowKey, const ColKeyType &colKey) const
Gets the value for the row and col key.
Definition KeyedMatrix.hpp:1076
decltype(auto) middleCols(const std::vector< ColKeyType > &colKeys)
Gets the values for the col keys.
Definition KeyedMatrix.hpp:1275
decltype(auto) block(const std::vector< RowKeyType > &rowKeys, const std::vector< ColKeyType > &colKeys)
Gets the values for the row and col keys.
Definition KeyedMatrix.hpp:1198
Eigen::Matrix< Scalar, Rows, Cols > & block(all_t, all_t)
Requests the full matrix.
Definition KeyedMatrix.hpp:1301
decltype(auto) col(const ColKeyType &colKey) const
Gets the values for the col key.
Definition KeyedMatrix.hpp:1292
KeyedMatrixBase & operator=(const KeyedMatrixBase< Scalar, RowKeyType, ColKeyType, oRows, oCols > &other)
Copy assignment operator.
Definition KeyedMatrix.hpp:1014
decltype(auto) middleRows(const std::vector< RowKeyType > &rowKeys) const
Gets the values for the row keys.
Definition KeyedMatrix.hpp:1363
decltype(auto) block(const RowKeyType &rowKey, const std::vector< ColKeyType > &colKeys) const
Gets the values for the row and col keys.
Definition KeyedMatrix.hpp:1227
decltype(auto) block(const RowKeyType &rowKey, const std::vector< ColKeyType > &colKeys)
Gets the values for the row and col keys.
Definition KeyedMatrix.hpp:1236
decltype(auto) block(const std::vector< RowKeyType > &rowKeys, const std::vector< ColKeyType > &colKeys)
Gets the values for the row and col keys.
Definition KeyedMatrix.hpp:1321
decltype(auto) middleRows(const std::vector< RowKeyType > &rowKeys) const
Gets the values for the row keys.
Definition KeyedMatrix.hpp:1245
decltype(auto) col(const ColKeyType &colKey)
Gets the values for the col key.
Definition KeyedMatrix.hpp:1296
KeyedMatrixBase & operator=(KeyedMatrixBase &&other) noexcept
Move assignment operator.
Definition KeyedMatrix.hpp:976
KeyedMatrixBase< Scalar, RowKeyType, ColKeyType, Rows, Cols > inverse() const
Calculates the inverse matrix.
Definition KeyedMatrix.hpp:1408
KeyedMatrixBase(const KeyedMatrixBase< Scalar, RowKeyType, ColKeyType, oRows, oCols > &other)
Copy constructor.
Definition KeyedMatrix.hpp:998
const Eigen::Matrix< Scalar, Rows, Cols > & operator()(all_t, all_t) const
Requests the full matrix.
Definition KeyedMatrix.hpp:1172
Base class for Keyed matrices with multiple columns.
Definition KeyedMatrix.hpp:215
void replaceColKey(const ColKeyType &oldKey, const ColKeyType &newKey)
Replace the old with the new key.
Definition KeyedMatrix.hpp:244
std::vector< ColKeyType > colKeysVector
Col Keys.
Definition KeyedMatrix.hpp:258
bool hasCols(const std::vector< ColKeyType > &keys) const
Checks if the matrix has multiple keys.
Definition KeyedMatrix.hpp:229
std::vector< Eigen::Index > colSlice
Col Slice used for accessing.
Definition KeyedMatrix.hpp:261
bool hasAnyCols(const std::vector< ColKeyType > &keys) const
Checks if the matrix has any keys.
Definition KeyedMatrix.hpp:236
const std::vector< ColKeyType > & colKeys() const
Returns the col keys.
Definition KeyedMatrix.hpp:221
unordered_map< ColKeyType, Eigen::Index > colIndices
ColKey to Col Index mapping.
Definition KeyedMatrix.hpp:256
decltype(auto) cols() const
Return the cols of the underlying Eigen matrix.
Definition KeyedMatrix.hpp:218
bool hasCol(const ColKeyType &key) const
Checks if the matrix has the key.
Definition KeyedMatrix.hpp:225
void addCols(const std::vector< ColKeyType > &colKeys)
Adds new cols to the matrix.
Definition KeyedMatrix.hpp:293
void removeCols(const std::vector< ColKeyType > &colKeys)
Removes the cols from the matrix.
Definition KeyedMatrix.hpp:318
void removeCol(const ColKeyType &colKey)
Removes the col from the matrix.
Definition KeyedMatrix.hpp:314
void addCol(const ColKeyType &colKey)
Adds a new col to the matrix.
Definition KeyedMatrix.hpp:289
Base class for Keyed matrices with multiple columns of static size.
Definition KeyedMatrix.hpp:277
Base class for Keyed matrices with multiple rows.
Definition KeyedMatrix.hpp:71
std::vector< Eigen::Index > rowSlice
Row Slice used for accessing.
Definition KeyedMatrix.hpp:117
unordered_map< RowKeyType, Eigen::Index > rowIndices
RowKey to Row Index mapping.
Definition KeyedMatrix.hpp:112
decltype(auto) rows() const
Return the rows of the underlying Eigen matrix.
Definition KeyedMatrix.hpp:74
bool hasRow(const RowKeyType &key) const
Checks if the matrix has the key.
Definition KeyedMatrix.hpp:81
bool hasRows(const std::vector< RowKeyType > &keys) const
Checks if the matrix has multiple keys.
Definition KeyedMatrix.hpp:85
bool hasAnyRows(const std::vector< RowKeyType > &keys) const
Checks if the matrix has any key.
Definition KeyedMatrix.hpp:92
const std::vector< RowKeyType > & rowKeys() const
Returns the row keys.
Definition KeyedMatrix.hpp:77
std::vector< RowKeyType > rowKeysVector
Row Keys.
Definition KeyedMatrix.hpp:114
void replaceRowKey(const RowKeyType &oldKey, const RowKeyType &newKey)
Replace the old with the new key.
Definition KeyedMatrix.hpp:100
void addRow(const RowKeyType &rowKey)
Adds a new row to the matrix.
Definition KeyedMatrix.hpp:145
void removeRows(const std::vector< RowKeyType > &rowKeys)
Removes the rows from the matrix.
Definition KeyedMatrix.hpp:174
void addRows(const std::vector< RowKeyType > &rowKeys)
Adds new rows to the matrix.
Definition KeyedMatrix.hpp:149
void removeRow(const RowKeyType &rowKey)
Removes the row from the matrix.
Definition KeyedMatrix.hpp:170
Base class for Keyed matrices with multiple rows of static size.
Definition KeyedMatrix.hpp:133
KeyedMatrix storage class.
Definition KeyedMatrix.hpp:49
Eigen::Matrix< Scalar, Rows, Cols > matrix
Data storage of the type.
Definition KeyedMatrix.hpp:51
Class to inherit common methods for static and dynamic sized row vectors.
Definition KeyedMatrix.hpp:626
KeyedRowVectorBase(const Eigen::MatrixBase< Derived > &vector)
Constructor.
Definition KeyedMatrix.hpp:631
Eigen::Matrix< Scalar, 1, Cols > & operator()(all_t)
Requests the full vector.
Definition KeyedMatrix.hpp:809
const Scalar & operator()(const ColKeyType &colKey) const
Gets the value for the col key.
Definition KeyedMatrix.hpp:773
decltype(auto) segment(const std::vector< ColKeyType > &colKeys)
Gets the values for the col keys.
Definition KeyedMatrix.hpp:831
decltype(auto) segment(const std::vector< ColKeyType > &colKeys) const
Gets the values for the col keys.
Definition KeyedMatrix.hpp:821
const Eigen::Matrix< Scalar, 1, Cols > & operator()(all_t) const
Requests the full vector.
Definition KeyedMatrix.hpp:807
KeyedRowVectorBase(KeyedRowVectorBase &&other) noexcept
Move constructor.
Definition KeyedMatrix.hpp:684
KeyedRowVectorBase(const KeyedRowVectorBase< Scalar, ColKeyType, oCols > &other)
Copy constructor.
Definition KeyedMatrix.hpp:712
KeyedRowVectorBase & operator=(KeyedRowVectorBase< Scalar, ColKeyType, oCols > &&other) noexcept
Move assignment operator.
Definition KeyedMatrix.hpp:752
KeyedRowVectorBase & operator=(const KeyedRowVectorBase &other)
Copy assignment operator.
Definition KeyedMatrix.hpp:671
KeyedRowVectorBase & operator=(const KeyedRowVectorBase< Scalar, ColKeyType, oCols > &other)
Copy assignment operator.
Definition KeyedMatrix.hpp:724
~KeyedRowVectorBase()=default
Destructor.
decltype(auto) segment(const std::vector< ColKeyType > &colKeys) const
Gets the values for the col keys.
Definition KeyedMatrix.hpp:840
Scalar & operator()(const ColKeyType &colKey)
Gets the value for the col key.
Definition KeyedMatrix.hpp:780
KeyedRowVectorBase & operator=(KeyedRowVectorBase &&other) noexcept
Move assignment operator.
Definition KeyedMatrix.hpp:693
KeyedRowVectorBase(const KeyedRowVectorBase &other)
Copy constructor.
Definition KeyedMatrix.hpp:662
KeyedRowVectorBase(KeyedRowVectorBase< Scalar, ColKeyType, oCols > &&other) noexcept
Move constructor.
Definition KeyedMatrix.hpp:740
KeyedRowVectorBase(const Eigen::MatrixBase< Derived > &vector, const std::vector< ColKeyType > &colKeys)
Constructor.
Definition KeyedMatrix.hpp:640
KeyedVectorBase< Scalar, ColKeyType, Cols > transposed() const
Calculates the transposed vector.
Definition KeyedMatrix.hpp:861
decltype(auto) segment(const std::vector< ColKeyType > &colKeys)
Gets the values for the col keys.
Definition KeyedMatrix.hpp:849
Class to inherit common methods for static and dynamic sized vectors.
Definition KeyedMatrix.hpp:361
decltype(auto) segment(const std::vector< RowKeyType > &rowKeys)
Gets the values for the row keys.
Definition KeyedMatrix.hpp:566
KeyedVectorBase(const Eigen::MatrixBase< Derived > &vector, const std::vector< RowKeyType > &rowKeys)
Constructor.
Definition KeyedMatrix.hpp:375
KeyedVectorBase & operator=(KeyedVectorBase &&other) noexcept
Move assignment operator.
Definition KeyedMatrix.hpp:428
~KeyedVectorBase()=default
Destructor.
Scalar & operator()(const RowKeyType &rowKey)
Gets the value for the row key.
Definition KeyedMatrix.hpp:515
Eigen::Matrix< Scalar, Rows, 1 > & operator()(all_t)
Requests the full vector.
Definition KeyedMatrix.hpp:544
KeyedVectorBase & operator=(const KeyedVectorBase< Scalar, RowKeyType, oRows > &other)
Copy assignment operator.
Definition KeyedMatrix.hpp:459
KeyedVectorBase & operator=(KeyedVectorBase< Scalar, RowKeyType, oRows > &&other) noexcept
Move assignment operator.
Definition KeyedMatrix.hpp:487
KeyedVectorBase(const Eigen::MatrixBase< Derived > &vector)
Constructor.
Definition KeyedMatrix.hpp:366
decltype(auto) segment(const std::vector< RowKeyType > &rowKeys)
Gets the values for the row keys.
Definition KeyedMatrix.hpp:584
KeyedVectorBase(KeyedVectorBase &&other) noexcept
Move constructor.
Definition KeyedMatrix.hpp:419
decltype(auto) segment(const std::vector< RowKeyType > &rowKeys) const
Gets the values for the row keys.
Definition KeyedMatrix.hpp:575
const Eigen::Matrix< Scalar, Rows, 1 > & operator()(all_t) const
Requests the full vector.
Definition KeyedMatrix.hpp:542
const Scalar & operator()(const RowKeyType &rowKey) const
Gets the value for the row key.
Definition KeyedMatrix.hpp:508
KeyedVectorBase(KeyedVectorBase< Scalar, RowKeyType, oRows > &&other) noexcept
Move constructor.
Definition KeyedMatrix.hpp:475
KeyedVectorBase & operator=(const KeyedVectorBase &other)
Copy assignment operator.
Definition KeyedMatrix.hpp:406
KeyedVectorBase(const KeyedVectorBase< Scalar, RowKeyType, oRows > &other)
Copy constructor.
Definition KeyedMatrix.hpp:447
KeyedVectorBase(const KeyedVectorBase &other)
Copy constructor.
Definition KeyedMatrix.hpp:397
decltype(auto) segment(const std::vector< RowKeyType > &rowKeys) const
Gets the values for the row keys.
Definition KeyedMatrix.hpp:556
KeyedRowVectorBase< Scalar, RowKeyType, Rows > transposed() const
Calculates the transposed vector.
Definition KeyedMatrix.hpp:596
All type to request all rows or columns in KeyedMatrices.
Definition KeyedMatrix.hpp:38
all_t()=default
Default Constructor.
std::ostream & operator<<(std::ostream &os, const NAV::KeyedMatrix< Scalar, RowKeyType, ColKeyType, Rows, Cols > &obj)
Stream insertion operator overload.
Definition KeyedMatrix.hpp:2574
static const internal::all_t all
Used to request all rows or columns in KeyedMatrices.
Definition KeyedMatrix.hpp:1446