17#include <unordered_set>
29#if defined(__GNUC__) && !defined(__clang__)
30 #pragma GCC diagnostic push
31 #pragma GCC diagnostic ignored "-Wvirtual-move-assign"
49template<
typename Scalar,
int Rows,
int Cols>
53 Eigen::Matrix<Scalar, Rows, Cols>
matrix;
57 template<
typename Scalar_,
typename RowKeyType_,
typename ColKeyType_,
int Rows_,
int Cols_>
59 template<
typename Scalar_,
typename RowKeyType_,
int Rows_>
61 template<
typename Scalar_,
typename ColKeyType_,
int Cols_>
72template<
typename Scalar,
typename RowKeyType,
int Rows,
int Cols>
77 [[nodiscard]]
decltype(
auto)
rows()
const {
return this->
matrix.rows(); }
88 bool hasRows(std::span<const RowKeyType> keys)
const
90 return std::ranges::all_of(keys, [&](
const RowKeyType& key) {
return hasRow(key); });
97 return std::ranges::any_of(keys, [&](
const RowKeyType& key) {
return hasRow(key); });
123 template<
typename Scalar_,
typename RowKeyType_,
typename ColKeyType_,
int Rows_,
int Cols_>
125 template<
typename Scalar_,
typename RowKeyType_,
int Rows_>
134template<
typename Scalar,
typename RowKeyType,
int Rows,
int Cols>
142template<
typename Scalar,
typename RowKeyType,
int Cols>
148 void addRow(
const RowKeyType& rowKey) {
addRows(std::initializer_list<RowKeyType>{ rowKey }); }
157 auto initialSize =
static_cast<Eigen::Index
>(this->
rowIndices.size());
160 std::copy(
rowKeys.begin(),
rowKeys.end(), std::back_inserter(this->rowKeysVector));
161 auto finalSize =
static_cast<Eigen::Index
>(this->
rowIndices.size());
163 if (finalSize > initialSize)
165 this->
matrix.conservativeResize(finalSize, Eigen::NoChange);
166 this->
matrix.block(initialSize, 0, finalSize - initialSize, this->
matrix.cols()) = Eigen::MatrixX<Scalar>::Zero(finalSize - initialSize, this->
matrix.cols());
168 std::lock_guard<std::mutex> lg{ this->
_sliceMutex };
180 std::vector<int> indices;
181 for (
const auto& rowKey :
rowKeys)
187 indices.push_back(
static_cast<int>(iter->second));
192 for (
const auto& rowKey :
rowKeys)
197 std::erase_if(this->
rowKeysVector, [&](
const auto& item) {
return item == rowKey; });
199 auto idx = iter->second;
202 if (rowIndex.second > idx) { rowIndex.second--; }
204 this->rowIndices.erase(iter);
217template<
typename Scalar,
typename ColKeyType,
int Rows,
int Cols>
222 [[nodiscard]]
decltype(
auto)
cols()
const {
return this->
matrix.cols(); }
233 bool hasCols(std::span<const ColKeyType> keys)
const
235 return std::ranges::all_of(keys, [&](
const ColKeyType& key) {
return hasCol(key); });
242 return std::ranges::any_of(keys, [&](
const ColKeyType& key) {
return hasCol(key); });
268 template<
typename Scalar_,
typename RowKeyType_,
typename ColKeyType_,
int Rows_,
int Cols_>
270 template<
typename Scalar_,
typename ColKeyType_,
int Cols_>
279template<
typename Scalar,
typename ColKeyType,
int Rows,
int Cols>
287template<
typename Scalar,
typename ColKeyType,
int Rows>
293 void addCol(
const ColKeyType& colKey) {
addCols(std::initializer_list<ColKeyType>{ colKey }); }
302 auto initialSize =
static_cast<Eigen::Index
>(this->
colIndices.size());
305 std::copy(
colKeys.begin(),
colKeys.end(), std::back_inserter(this->colKeysVector));
306 auto finalSize =
static_cast<Eigen::Index
>(this->
colIndices.size());
308 if (finalSize > initialSize)
310 this->
matrix.conservativeResize(Eigen::NoChange, finalSize);
311 this->
matrix.block(0, initialSize, this->
matrix.rows(), finalSize - initialSize) = Eigen::MatrixX<Scalar>::Zero(this->
matrix.rows(), finalSize - initialSize);
313 std::lock_guard<std::mutex> lg{ this->
_sliceMutex };
325 std::vector<int> indices;
326 for (
const auto& colKey :
colKeys)
332 indices.push_back(
static_cast<int>(iter->second));
337 for (
const auto& colKey :
colKeys)
342 std::erase_if(this->
colKeysVector, [&](
const auto& item) {
return item == colKey; });
344 auto idx = iter->second;
347 if (colIndex.second > idx) { colIndex.second--; }
349 this->colIndices.erase(iter);
357template<
typename Scalar,
typename ColKeyType,
int Cols>
358class KeyedRowVectorBase;
364template<
typename Scalar,
typename RowKeyType,
int Rows>
370 template<
typename Derived>
379 template<
typename Derived>
385 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");
387 for (
size_t i = 0; i <
rowKeys.size(); i++) { this->
rowIndices.insert({
rowKeys[i],
static_cast<Eigen::Index
>(i) }); }
413 if (
this == &other) {
return *
this; }
426 this->
matrix = std::move(other.matrix);
427 this->
rowIndices = std::move(other.rowIndices);
435 if (
this == &other) {
return *
this; }
437 this->
matrix = std::move(other.matrix);
438 this->
rowIndices = std::move(other.rowIndices);
454 INS_ASSERT_USER_ERROR(Rows == Eigen::Dynamic || other.
rows() == Rows,
"Can only copy construct dynamic<=>static matrices if the rows match");
482 INS_ASSERT_USER_ERROR(Rows == Eigen::Dynamic || other.rows() == Rows,
"Can only copy construct dynamic<=>static matrices if the rows match");
484 this->
matrix = std::move(other.matrix);
485 this->
rowIndices = std::move(other.rowIndices);
496 INS_ASSERT_USER_ERROR(other.rowKeys() == this->rowKeys(),
"Can only copy assign matrices if the row keys match");
498 this->
matrix = std::move(other.matrix);
499 this->
rowIndices = std::move(other.rowIndices);
528 decltype(
auto)
operator()(std::span<const RowKeyType>
rowKeys)
const
530 std::lock_guard<std::mutex> lg{ this->
_sliceMutex };
539 decltype(
auto)
operator()(std::span<const RowKeyType>
rowKeys)
541 std::lock_guard<std::mutex> lg{ this->
_sliceMutex };
553 explicit operator Eigen::Vector<Scalar, Rows>() {
return this->
matrix; }
617 std::vector<Eigen::Index> consecutiveRows(
rowKeys.size());
618 std::iota(std::begin(consecutiveRows), std::end(consecutiveRows), this->
rowIndices.at(
rowKeys.front()));
621 for (
const auto& rowKey :
rowKeys) {
rowIndices.push_back(this->rowIndices.at(rowKey)); }
631template<
typename Scalar,
typename ColKeyType,
int Cols>
637 template<
typename Derived>
646 template<
typename Derived>
652 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");
654 for (
size_t i = 0; i <
colKeys.size(); i++) { this->
colIndices.insert({
colKeys[i],
static_cast<Eigen::Index
>(i) }); }
680 if (
this == &other) {
return *
this; }
693 this->
matrix = std::move(other.matrix);
694 this->
colIndices = std::move(other.colIndices);
702 if (
this == &other) {
return *
this; }
704 this->
matrix = std::move(other.matrix);
705 this->
colIndices = std::move(other.colIndices);
721 INS_ASSERT_USER_ERROR(Cols == Eigen::Dynamic || other.
cols() == Cols,
"Can only copy construct dynamic<=>static matrices if the cols match");
749 INS_ASSERT_USER_ERROR(Cols == Eigen::Dynamic || other.cols() == Cols,
"Can only copy construct dynamic<=>static matrices if the cols match");
751 this->
matrix = std::move(other.matrix);
752 this->
colIndices = std::move(other.colIndices);
763 INS_ASSERT_USER_ERROR(other.colKeys() == this->colKeys(),
"Can only copy assign matrices if the col keys match");
765 this->
matrix = std::move(other.matrix);
766 this->
colIndices = std::move(other.colIndices);
795 decltype(
auto)
operator()(std::span<const ColKeyType>
colKeys)
const
797 std::lock_guard<std::mutex> lg{ this->
_sliceMutex };
806 decltype(
auto)
operator()(std::span<const ColKeyType>
colKeys)
808 std::lock_guard<std::mutex> lg{ this->
_sliceMutex };
820 explicit operator Eigen::RowVector<Scalar, Cols>() {
return this->
matrix; }
884 std::vector<Eigen::Index> consecutiveCols(
colKeys.size());
885 std::iota(std::begin(consecutiveCols), std::end(consecutiveCols), this->
colIndices.at(
colKeys.front()));
888 for (
const auto& colKey :
colKeys) {
colIndices.push_back(this->colIndices.at(colKey)); }
900template<
typename Scalar,
typename RowKeyType,
typename ColKeyType,
int Rows,
int Cols>
906 template<
typename Derived>
915 template<
typename Derived>
924 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");
925 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");
927 for (
size_t i = 0; i <
rowKeys.size(); i++) { this->
rowIndices.insert({
rowKeys[i],
static_cast<Eigen::Index
>(i) }); }
928 for (
size_t i = 0; i <
colKeys.size(); i++) { this->
colIndices.insert({
colKeys[i],
static_cast<Eigen::Index
>(i) }); }
959 if (
this == &other) {
return *
this; }
975 this->
matrix = std::move(other.matrix);
976 this->
rowIndices = std::move(other.rowIndices);
978 this->
colIndices = std::move(other.colIndices);
987 if (
this == &other) {
return *
this; }
989 this->
matrix = std::move(other.matrix);
990 this->
rowIndices = std::move(other.rowIndices);
992 this->
colIndices = std::move(other.colIndices);
1006 template<
int oRows,
int oCols>
1009 INS_ASSERT_USER_ERROR(Rows == Eigen::Dynamic || other.
rows() == Rows,
"Can only copy construct dynamic<=>static matrices if the rows match");
1010 INS_ASSERT_USER_ERROR(Cols == Eigen::Dynamic || other.
cols() == Cols,
"Can only copy construct dynamic<=>static matrices if the cols match");
1022 template<
int oRows,
int oCols>
1042 template<
int oRows,
int oCols>
1045 INS_ASSERT_USER_ERROR(Rows == Eigen::Dynamic || other.rows() == Rows,
"Can only copy construct dynamic<=>static matrices if the rows match");
1046 INS_ASSERT_USER_ERROR(Cols == Eigen::Dynamic || other.cols() == Cols,
"Can only copy construct dynamic<=>static matrices if the cols match");
1048 this->
matrix = std::move(other.matrix);
1049 this->
rowIndices = std::move(other.rowIndices);
1051 this->
colIndices = std::move(other.colIndices);
1058 template<
int oRows,
int oCols>
1063 INS_ASSERT_USER_ERROR(other.rowKeys() == this->rowKeys(),
"Can only copy assign matrices if the row keys match");
1064 INS_ASSERT_USER_ERROR(other.colKeys() == this->colKeys(),
"Can only copy assign matrices if the col keys match");
1066 this->
matrix = std::move(other.matrix);
1067 this->
rowIndices = std::move(other.rowIndices);
1069 this->
colIndices = std::move(other.colIndices);
1085 const Scalar&
operator()(
const RowKeyType& rowKey,
const ColKeyType& colKey)
const
1087 return this->
matrix(this->
rowIndices.at(rowKey), this->colIndices.at(colKey));
1093 Scalar&
operator()(
const RowKeyType& rowKey,
const ColKeyType& colKey)
1095 return this->
matrix(this->
rowIndices.at(rowKey), this->colIndices.at(colKey));
1102 decltype(
auto)
operator()(std::span<const RowKeyType>
rowKeys, std::span<const ColKeyType>
colKeys)
const
1104 std::lock_guard<std::mutex> lg{ this->
_sliceMutex };
1117 decltype(
auto)
operator()(std::span<const RowKeyType>
rowKeys, std::span<const ColKeyType>
colKeys)
1119 std::lock_guard<std::mutex> lg{ this->
_sliceMutex };
1132 decltype(
auto)
operator()(std::span<const RowKeyType>
rowKeys,
const ColKeyType& colKey)
const {
return (*
this)(
rowKeys, std::initializer_list<ColKeyType>{ colKey }); }
1137 decltype(
auto)
operator()(std::span<const RowKeyType>
rowKeys,
const ColKeyType& colKey) {
return (*
this)(
rowKeys, std::initializer_list<ColKeyType>{ colKey }); }
1142 decltype(
auto)
operator()(
const RowKeyType& rowKey, std::span<const ColKeyType>
colKeys)
const {
return (*
this)(std::initializer_list<RowKeyType>{ rowKey },
colKeys); }
1147 decltype(
auto)
operator()(
const RowKeyType& rowKey, std::span<const ColKeyType>
colKeys) {
return (*
this)(std::initializer_list<RowKeyType>{ rowKey },
colKeys); }
1152 decltype(
auto)
operator()(
const RowKeyType& rowKey,
all_t )
const {
return (*
this)(std::initializer_list<RowKeyType>{ rowKey }, this->
colKeys()); }
1156 decltype(
auto)
operator()(
const RowKeyType& rowKey,
all_t ) {
return (*
this)(std::initializer_list<RowKeyType>{ rowKey }, this->
colKeys()); }
1160 decltype(
auto)
operator()(
all_t ,
const ColKeyType& colKey)
const {
return *
this(this->
rowKeys(), std::initializer_list<ColKeyType>{ colKey }); }
1164 decltype(
auto)
operator()(
all_t ,
const ColKeyType& colKey) {
return (*
this)(this->
rowKeys(), std::initializer_list<ColKeyType>{ colKey }); }
1176 decltype(
auto)
operator()(
all_t , std::span<const ColKeyType>
colKeys)
const {
return (*
this)(this->
rowKeys(), colKeys); }
1180 decltype(
auto)
operator()(
all_t , std::span<const ColKeyType>
colKeys) {
return (*
this)(this->
rowKeys(), colKeys); }
1187 explicit operator Eigen::Matrix<Scalar, Rows, Cols>() {
return this->
matrix; }
1197 template<
size_t P,
size_t Q = P>
1208 template<
size_t P,
size_t Q = P>
1220 decltype(
auto)
block(std::span<const RowKeyType>
rowKeys,
const ColKeyType& colKey)
const
1222 return this->
block<P, 1>(rowKeys, std::initializer_list<ColKeyType>{ colKey });
1229 decltype(
auto)
block(std::span<const RowKeyType>
rowKeys,
const ColKeyType& colKey)
1231 return this->
block<P, 1>(rowKeys, std::initializer_list<ColKeyType>{ colKey });
1238 decltype(
auto)
block(
const RowKeyType& rowKey, std::span<const ColKeyType>
colKeys)
const
1247 decltype(
auto)
block(
const RowKeyType& rowKey, std::span<const ColKeyType>
colKeys)
1342 decltype(
auto)
block(std::span<const RowKeyType>
rowKeys,
const ColKeyType& colKey)
const
1344 return this->
block(rowKeys, std::initializer_list<ColKeyType>{ colKey });
1350 decltype(
auto)
block(std::span<const RowKeyType>
rowKeys,
const ColKeyType& colKey)
1352 return this->
block(rowKeys, std::initializer_list<ColKeyType>{ colKey });
1358 decltype(
auto)
block(
const RowKeyType& rowKey, std::span<const ColKeyType>
colKeys)
const
1360 return this->
block(std::initializer_list<RowKeyType>{ rowKey },
colKeys);
1366 decltype(
auto)
block(
const RowKeyType& rowKey, std::span<const ColKeyType>
colKeys)
1368 return this->
block(std::initializer_list<RowKeyType>{ rowKey },
colKeys);
1431 [[maybe_unused]]
size_t P, [[maybe_unused]]
size_t Q)
const
1437 std::vector<Eigen::Index> consecutiveRows(
rowKeys.size());
1438 std::iota(std::begin(consecutiveRows), std::end(consecutiveRows), this->
rowIndices.at(
rowKeys.front()));
1441 for (
const auto& rowKey :
rowKeys) {
rowIndices.push_back(this->rowIndices.at(rowKey)); }
1444 std::vector<Eigen::Index> consecutiveCols(
colKeys.size());
1445 std::iota(std::begin(consecutiveCols), std::end(consecutiveCols), this->
colIndices.at(
colKeys.front()));
1448 for (
const auto& colKey :
colKeys) {
colIndices.push_back(this->colIndices.at(colKey)); }
1459template<
typename Scalar,
typename ColKeyType,
int Cols>
1466template<
typename Scalar,
typename RowKeyType,
int Rows>
1474 template<
typename Derived>
1494 if (
this == &other) {
return *
this; }
1510 if (
this == &other) {
return *
this; }
1527 INS_ASSERT_USER_ERROR(other.
rows() == Rows,
"Can only copy assign dynamic matrices from static ones if the size matches");
1535 INS_ASSERT_USER_ERROR(other.
rows() == Rows,
"Can only copy assign dynamic matrices from static ones if the size matches");
1547 INS_ASSERT_USER_ERROR(this->
rows() == Rows,
"Can only move construct dynamic matrices from static ones if the size matches");
1555 INS_ASSERT_USER_ERROR(other.rows() == Rows,
"Can only move assign dynamic matrices from static ones if the size matches");
1571 return { transpose(
all), transpose.colKeys() };
1578template<
typename Scalar,
typename RowKeyType>
1579class KeyedVector<Scalar, RowKeyType,
Eigen::Dynamic> :
public internal::KeyedVectorBase<Scalar, RowKeyType, Eigen::Dynamic>
1590 template<
typename Derived>
1591 KeyedVector(
const Eigen::MatrixBase<Derived>& vector, std::span<const RowKeyType>
rowKeys)
1604 : internal::
KeyedVectorBase<Scalar, RowKeyType, Eigen::Dynamic>(other)
1610 if (
this == &other) {
return *
this; }
1612 static_cast<internal::KeyedVectorBase<Scalar, RowKeyType, Eigen::Dynamic>&
>(*this) =
1613 static_cast<const internal::KeyedVectorBase<Scalar, RowKeyType, Eigen::Dynamic>&
>(other);
1620 : internal::KeyedVectorBase<Scalar, RowKeyType, Eigen::Dynamic>(std::move(other))
1626 if (
this == &other) {
return *
this; }
1628 static_cast<internal::KeyedVectorBase<Scalar, RowKeyType, Eigen::Dynamic>&
>(*this) =
1629 std::move(
static_cast<internal::KeyedVectorBase<Scalar, RowKeyType, Eigen::Dynamic>&
>(other));
1642 : internal::
KeyedVectorBase<Scalar, RowKeyType, Eigen::Dynamic>(other)
1651 static_cast<internal::KeyedVectorBase<Scalar, RowKeyType, Eigen::Dynamic>&
>(*this) =
1652 static_cast<const internal::KeyedVectorBase<Scalar, RowKeyType, oRows>&
>(other);
1660 : internal::KeyedVectorBase<Scalar, RowKeyType, Eigen::Dynamic>(std::move(other))
1669 static_cast<internal::KeyedVectorBase<Scalar, RowKeyType, Eigen::Dynamic>&
>(*this) =
1670 std::move(
static_cast<internal::KeyedVectorBase<Scalar, RowKeyType, oRows>&
>(other));
1680 [[nodiscard]] KeyedRowVector<Scalar, RowKeyType, Eigen::Dynamic>
transposed()
const
1682 auto transpose =
static_cast<const internal::KeyedVectorBase<Scalar, RowKeyType, Eigen::Dynamic>&
>(*this).
transposed();
1683 return { transpose(
all), transpose.colKeys() };
1691template<
typename Scalar,
typename ColKeyType,
int Cols>
1699 template<
typename Derived>
1719 if (
this == &other) {
return *
this; }
1735 if (
this == &other) {
return *
this; }
1752 INS_ASSERT_USER_ERROR(other.
cols() == Cols,
"Can only copy assign dynamic matrices from static ones if the size matches");
1760 INS_ASSERT_USER_ERROR(other.
cols() == Cols,
"Can only copy assign dynamic matrices from static ones if the size matches");
1772 INS_ASSERT_USER_ERROR(this->
cols() == Cols,
"Can only move construct dynamic matrices from static ones if the size matches");
1780 INS_ASSERT_USER_ERROR(other.cols() == Cols,
"Can only move assign dynamic matrices from static ones if the size matches");
1796 return { transpose(
all), transpose.rowKeys() };
1803template<
typename Scalar,
typename ColKeyType>
1804class KeyedRowVector<Scalar, ColKeyType,
Eigen::Dynamic>
1805 :
public internal::KeyedRowVectorBase<Scalar, ColKeyType, Eigen::Dynamic>
1816 template<
typename Derived>
1836 if (
this == &other) {
return *
this; }
1838 static_cast<internal::KeyedRowVectorBase<Scalar, ColKeyType, Eigen::Dynamic>&
>(*this) =
1839 static_cast<const internal::KeyedRowVectorBase<Scalar, ColKeyType, Eigen::Dynamic>&
>(other);
1846 : internal::KeyedRowVectorBase<Scalar, ColKeyType, Eigen::Dynamic>(std::move(other))
1852 if (
this == &other) {
return *
this; }
1854 static_cast<internal::KeyedRowVectorBase<Scalar, ColKeyType, Eigen::Dynamic>&
>(*this) =
1855 std::move(
static_cast<internal::KeyedRowVectorBase<Scalar, ColKeyType, Eigen::Dynamic>&
>(other));
1877 static_cast<internal::KeyedRowVectorBase<Scalar, ColKeyType, Eigen::Dynamic>&
>(*this) =
1878 static_cast<const internal::KeyedRowVectorBase<Scalar, ColKeyType, oCols>&
>(other);
1886 : internal::KeyedRowVectorBase<Scalar, ColKeyType, Eigen::Dynamic>(std::move(other))
1895 static_cast<internal::KeyedRowVectorBase<Scalar, ColKeyType, Eigen::Dynamic>&
>(*this) =
1896 std::move(
static_cast<internal::KeyedRowVectorBase<Scalar, ColKeyType, oCols>&
>(other));
1906 [[nodiscard]] KeyedVector<Scalar, ColKeyType, Eigen::Dynamic>
transposed()
const
1908 auto transpose =
static_cast<const internal::KeyedRowVectorBase<Scalar, ColKeyType, Eigen::Dynamic>&
>(*this).
transposed();
1909 return { transpose(
all), transpose.rowKeys() };
1919template<
typename Scalar,
typename RowKeyType,
typename ColKeyType,
int Rows,
int Cols>
1928 template<
typename Derived>
1937 template<
typename Derived>
1957 if (
this == &other) {
return *
this; }
1973 if (
this == &other) {
return *
this; }
1990 INS_ASSERT_USER_ERROR(other.
rows() == Rows && other.
cols() == Cols,
"Can only copy assign dynamic matrices from static ones if the size matches");
1998 INS_ASSERT_USER_ERROR(other.
rows() == Rows && other.
cols() == Cols,
"Can only copy assign dynamic matrices from static ones if the size matches");
2010 INS_ASSERT_USER_ERROR(this->
rows() == Rows && this->
cols() == Cols,
"Can only move construct dynamic matrices from static ones if the size matches");
2018 INS_ASSERT_USER_ERROR(other.rows() == Rows && other.cols() == Cols,
"Can only move assign dynamic matrices from static ones if the size matches");
2048 return { transpose(
all,
all), transpose.rowKeys(), transpose.colKeys() };
2055 return { inv(
all,
all), inv.rowKeys(), inv.colKeys() };
2063template<
typename Scalar,
typename RowKeyType,
typename ColKeyType>
2064class KeyedMatrix<Scalar, RowKeyType, ColKeyType,
Eigen::Dynamic, Eigen::Dynamic>
2065 :
public internal::KeyedMatrixBase<Scalar, RowKeyType, ColKeyType, Eigen::Dynamic, Eigen::Dynamic>
2077 template<
typename Derived>
2086 template<
typename Derived>
2087 KeyedMatrix(
const Eigen::MatrixBase<Derived>&
matrix, std::span<const RowKeyType> keys)
2088 :
KeyedMatrix<Scalar, RowKeyType, ColKeyType, Eigen::Dynamic, Eigen::Dynamic>(
matrix, keys, keys)
2100 : internal::
KeyedMatrixBase<Scalar, RowKeyType, ColKeyType, Eigen::Dynamic, Eigen::Dynamic>(other)
2106 if (
this == &other) {
return *
this; }
2108 static_cast<internal::KeyedMatrixBase<Scalar, RowKeyType, ColKeyType, Eigen::Dynamic, Eigen::Dynamic>&
>(*this) =
2109 static_cast<const internal::KeyedMatrixBase<Scalar, RowKeyType, ColKeyType, Eigen::Dynamic, Eigen::Dynamic>&
>(other);
2116 : internal::KeyedMatrixBase<Scalar, RowKeyType, ColKeyType, Eigen::Dynamic, Eigen::Dynamic>(std::move(other))
2122 if (
this == &other) {
return *
this; }
2124 static_cast<internal::KeyedMatrixBase<Scalar, RowKeyType, ColKeyType, Eigen::Dynamic, Eigen::Dynamic>&
>(*this) =
2125 std::move(
static_cast<internal::KeyedMatrixBase<Scalar, RowKeyType, ColKeyType, Eigen::Dynamic, Eigen::Dynamic>&
>(other));
2136 template<
int oRows,
int oCols>
2138 : internal::
KeyedMatrixBase<Scalar, RowKeyType, ColKeyType, Eigen::Dynamic, Eigen::Dynamic>(other)
2142 template<
int oRows,
int oCols>
2147 static_cast<internal::KeyedMatrixBase<Scalar, RowKeyType, ColKeyType, Eigen::Dynamic, Eigen::Dynamic>&
>(*this) =
2148 static_cast<const internal::KeyedMatrixBase<Scalar, RowKeyType, ColKeyType, oRows, oCols>&
>(other);
2154 template<
int oRows,
int oCols>
2156 : internal::KeyedMatrixBase<Scalar, RowKeyType, ColKeyType, Eigen::Dynamic, Eigen::Dynamic>(std::move(other))
2160 template<
int oRows,
int oCols>
2165 static_cast<internal::KeyedMatrixBase<Scalar, RowKeyType, ColKeyType, Eigen::Dynamic, Eigen::Dynamic>&
>(*this) =
2166 std::move(
static_cast<internal::KeyedMatrixBase<Scalar, RowKeyType, ColKeyType, oRows, oCols>&
>(other));
2178 void addRowsCols(std::span<const RowKeyType>
rowKeys, std::span<const ColKeyType>
colKeys)
2185 auto initialRowSize =
static_cast<Eigen::Index
>(this->
rowIndices.size());
2188 std::copy(
rowKeys.begin(),
rowKeys.end(), std::back_inserter(this->rowKeysVector));
2189 auto finalRowSize =
static_cast<Eigen::Index
>(this->
rowIndices.size());
2191 auto initialColSize =
static_cast<Eigen::Index
>(this->
colIndices.size());
2194 std::copy(
colKeys.begin(),
colKeys.end(), std::back_inserter(this->colKeysVector));
2195 auto finalColSize =
static_cast<Eigen::Index
>(this->
colIndices.size());
2197 auto rows = finalRowSize - initialRowSize;
2198 auto cols = finalColSize - initialColSize;
2201 this->
matrix.conservativeResize(finalRowSize, finalColSize);
2205 std::lock_guard<std::mutex> lg{ this->
_sliceMutex };
2213 void removeRowsCols(std::span<const RowKeyType>
rowKeys, std::span<const ColKeyType>
colKeys)
2216 for (
const auto& rowKey :
rowKeys)
2222 rowIndices.push_back(
static_cast<int>(iter->second));
2226 for (
const auto& colKey :
colKeys)
2232 colIndices.push_back(
static_cast<int>(iter->second));
2238 for (
const auto& rowKey :
rowKeys)
2243 std::erase_if(this->
rowKeysVector, [&](
const auto& item) {
return item == rowKey; });
2245 auto idx = iter->second;
2248 if (rowIndex.second > idx) { rowIndex.second--; }
2253 for (
const auto& colKey :
colKeys)
2258 std::erase_if(this->
colKeysVector, [&](
const auto& item) {
return item == colKey; });
2260 auto idx = iter->second;
2263 if (colIndex.second > idx) { colIndex.second--; }
2291 auto transpose =
static_cast<const internal::KeyedMatrixBase<Scalar, RowKeyType, ColKeyType, Eigen::Dynamic, Eigen::Dynamic>&
>(*this).transposed();
2292 return { transpose(
all,
all), transpose.rowKeys(), transpose.colKeys() };
2298 auto inv =
static_cast<const internal::KeyedMatrixBase<Scalar, RowKeyType, ColKeyType, Eigen::Dynamic, Eigen::Dynamic>&
>(*this).inverse();
2299 return { inv(
all,
all), inv.rowKeys(), inv.colKeys() };
2307template<
typename Scalar,
typename RowKeyType,
typename ColKeyType = RowKeyType>
2312template<
typename RowKeyType,
typename ColKeyType = RowKeyType>
2317template<
typename RowKeyType,
typename ColKeyType = RowKeyType>
2322template<
typename RowKeyType,
typename ColKeyType = RowKeyType>
2327template<
typename RowKeyType,
typename ColKeyType = RowKeyType>
2332template<
typename RowKeyType,
typename ColKeyType = RowKeyType>
2337template<
typename RowKeyType,
typename ColKeyType = RowKeyType>
2343template<
typename Scalar,
typename RowKeyType>
2347template<
typename RowKeyType>
2351template<
typename RowKeyType>
2355template<
typename RowKeyType>
2359template<
typename RowKeyType>
2363template<
typename RowKeyType>
2367template<
typename RowKeyType>
2372template<
typename Scalar,
typename ColKeyType>
2376template<
typename ColKeyType>
2380template<
typename ColKeyType>
2384template<
typename ColKeyType>
2388template<
typename ColKeyType>
2392template<
typename ColKeyType>
2396template<
typename ColKeyType>
2401#if defined(__GNUC__) && !defined(__clang__)
2402 #pragma GCC diagnostic pop
2405#ifndef DOXYGEN_IGNORE
2408template<
typename Scalar,
typename RowKeyType,
typename ColKeyType,
int Rows,
int Cols>
2409struct fmt::formatter<
NAV::KeyedMatrix<Scalar, RowKeyType, ColKeyType, Rows, Cols>> : fmt::formatter<std::string>
2418 auto rows =
static_cast<size_t>(mat.
rows());
2419 auto cols =
static_cast<size_t>(mat.
cols());
2421 if (rows > 0 && cols > 0)
2423 std::vector<std::string> rowKeysStr;
2424 std::vector<size_t> rowKeysLength;
2425 rowKeysStr.reserve(rows);
2426 rowKeysLength.reserve(rows);
2427 size_t rowKeysColSpace = 0;
2428 for (
const auto& rowKey : mat.
rowKeys())
2430 rowKeysStr.push_back(fmt::format(
"{}", rowKey));
2431 auto rowKeyLength = rowKeysStr.back().length();
2432 rowKeysColSpace = std::max(rowKeysColSpace, rowKeyLength);
2433 rowKeysLength.push_back(rowKeyLength);
2436 constexpr size_t colMinLength = 9UL;
2438 std::vector<std::string> colKeysStr;
2439 std::vector<size_t> colKeysLength;
2440 size_t rowLineLength = rowKeysColSpace + 1;
2441 colKeysStr.reserve(cols);
2442 colKeysLength.reserve(cols);
2443 for (
const auto& colKey : mat.
colKeys())
2445 colKeysStr.push_back(fmt::format(
"{}", colKey));
2446 auto colKeyLength = colKeysStr.back().length();
2447 colKeysLength.push_back(colKeyLength);
2448 rowLineLength += 2 + std::max(colKeysStr.back().length(), colMinLength);
2451 result.reserve((rows + 1) * rowLineLength);
2453 result +=
" " + std::string(rowKeysColSpace,
' ');
2454 for (
size_t c = 0; c < cols; c++)
2457 if (colMinLength > colKeysLength.at(c))
2459 result += std::string(colMinLength - colKeysLength.at(c),
' ');
2461 result += colKeysStr.at(c);
2465 for (
size_t r = 0; r < rows; r++)
2467 if (rowKeysColSpace > rowKeysLength.at(r))
2469 result += std::string(rowKeysColSpace - rowKeysLength.at(r),
' ');
2471 result += rowKeysStr.at(r) +
" ";
2472 for (
size_t c = 0; c < cols; c++)
2474 auto colLength = std::max(colKeysStr.at(c).length(), colMinLength);
2476 std::string tmp = fmt::format(
" {:> {}.{}g}", mat(
NAV::all,
NAV::all)(
static_cast<int>(r),
static_cast<int>(c)), colLength, colLength - 2);
2477 if (tmp.length() > colLength)
2479 tmp = fmt::format(
" {:> {}.{}g}", mat(
NAV::all,
NAV::all)(
static_cast<int>(r),
static_cast<int>(c)), colLength, colLength - 6);
2483 if (r != rows - 1) { result +=
'\n'; }
2487 return fmt::formatter<std::string>::format(result, ctx);
2492template<
typename Scalar,
typename RowKeyType,
int Rows>
2493struct fmt::formatter<
NAV::KeyedVector<Scalar, RowKeyType, Rows>> : fmt::formatter<std::string>
2499 auto format(
const NAV::KeyedVector<Scalar, RowKeyType, Rows>& vec, format_context& ctx)
const
2502 auto rows =
static_cast<size_t>(vec.
rows());
2506 std::vector<std::string> rowKeysStr;
2507 std::vector<size_t> rowKeysLength;
2508 rowKeysStr.reserve(rows);
2509 rowKeysLength.reserve(rows);
2510 size_t rowKeysColSpace = 0;
2511 for (
const auto& rowKey : vec.
rowKeys())
2513 rowKeysStr.push_back(fmt::format(
"{}", rowKey));
2514 auto rowKeyLength = rowKeysStr.back().length();
2515 rowKeysColSpace = std::max(rowKeysColSpace, rowKeyLength);
2516 rowKeysLength.push_back(rowKeyLength);
2519 size_t colLength = 9UL;
2521 result.reserve(rows * (rowKeysColSpace + 2 + colLength));
2523 for (
size_t r = 0; r < rows; r++)
2525 if (rowKeysColSpace > rowKeysLength.at(r))
2527 result += std::string(rowKeysColSpace - rowKeysLength.at(r),
' ');
2529 result += rowKeysStr.at(r);
2531 std::string tmp = fmt::format(
" {:> {}.{}g}", vec(
NAV::all)(
static_cast<int>(r)), colLength, colLength - 2);
2532 if (tmp.length() > colLength)
2534 tmp = fmt::format(
" {:> {}.{}g}", vec(
NAV::all)(
static_cast<int>(r)), colLength, colLength - 6);
2538 if (r != rows - 1) { result +=
'\n'; }
2542 return fmt::formatter<std::string>::format(result, ctx);
2547template<
typename Scalar,
typename ColKeyType,
int Cols>
2548struct fmt::formatter<
NAV::KeyedRowVector<Scalar, ColKeyType, Cols>> : fmt::formatter<std::string>
2554 auto format(
const NAV::KeyedRowVector<Scalar, ColKeyType, Cols>& vec, format_context& ctx)
const
2557 auto cols =
static_cast<size_t>(vec.
cols());
2561 size_t colMinLength = 9UL;
2563 std::vector<std::string> colKeysStr;
2564 std::vector<size_t> colKeysLength;
2565 size_t rowLineLength = 1;
2566 colKeysStr.reserve(cols);
2567 colKeysLength.reserve(cols);
2568 for (
const auto& colKey : vec.
colKeys())
2570 colKeysStr.push_back(fmt::format(
"{}", colKey));
2571 auto colKeyLength = colKeysStr.back().length();
2572 colKeysLength.push_back(colKeyLength);
2573 rowLineLength += 2 + std::max(colKeysStr.back().length(), colMinLength);
2576 result.reserve(2 * rowLineLength);
2578 for (
size_t c = 0; c < cols; c++)
2580 if (c != 0) { result +=
" "; }
2581 if (colMinLength > colKeysLength.at(c))
2583 result += std::string(colMinLength - colKeysLength.at(c),
' ');
2585 result += colKeysStr.at(c);
2590 for (
size_t c = 0; c < cols; c++)
2592 auto colLength = std::max(colKeysStr.at(c).length(), colMinLength);
2593 if (c != 0) { result +=
" "; }
2594 std::string tmp = fmt::format(
"{:> {}.{}g}", vec(
NAV::all)(
static_cast<int>(c)), colLength, colLength - 2);
2595 if (tmp.length() > colLength)
2597 tmp = fmt::format(
"{:> {}.{}g}", vec(
NAV::all)(
static_cast<int>(c)), colLength, colLength - 6);
2603 return fmt::formatter<std::string>::format(result, ctx);
2613template<
typename Scalar,
typename RowKeyType,
typename ColKeyType,
int Rows,
int Cols>
2616 return os << fmt::format(
"{}", obj);
2622template<
typename Scalar,
typename RowKeyType,
int Rows>
2625 return os << fmt::format(
"{}", obj);
2631template<
typename Scalar,
typename ColKeyType,
int Cols>
2634 return os << fmt::format(
"{}", obj);
#define INS_ASSERT_USER_ERROR(_EXP, _MSG)
Assert function with message.
ankerl::unordered_dense::map< Key, T > unordered_map
Unordered map type.
Vector Utility functions.
Static sized KeyedMatrix.
KeyedMatrix(const KeyedMatrix< Scalar, RowKeyType, ColKeyType, Eigen::Dynamic, Eigen::Dynamic > &other)
Copy constructor.
KeyedMatrix(const KeyedMatrix &other)
Copy constructor.
KeyedMatrix & operator=(const KeyedMatrix &other)
Copy assignment operator.
~KeyedMatrix()=default
Destructor.
KeyedMatrix< Scalar, RowKeyType, ColKeyType, Rows, Cols > transposed() const
Calculates the transposed matrix.
KeyedMatrix< Scalar, RowKeyType, ColKeyType, Eigen::Dynamic, Eigen::Dynamic > getSubMatrix(std::span< const RowKeyType > rowKeys, std::span< const ColKeyType > colKeys) const
Returns a submatrix specified by the row and col keys.
KeyedMatrix & operator=(const KeyedMatrix< Scalar, RowKeyType, ColKeyType, Eigen::Dynamic, Eigen::Dynamic > &other)
Copy assignment operator.
KeyedMatrix & operator=(KeyedMatrix &&other) noexcept
Move assignment operator.
KeyedMatrix(const Eigen::MatrixBase< Derived > &matrix, std::span< const RowKeyType > rowKeys, std::span< const ColKeyType > colKeys)
Non-symmetric matrix constructor.
KeyedMatrix< Scalar, RowKeyType, ColKeyType, Rows, Cols > inverse() const
Calculates the inverse matrix.
KeyedMatrix(const Eigen::MatrixBase< Derived > &matrix, std::span< const RowKeyType > keys)
Symmetric matrix constructor.
KeyedMatrix(KeyedMatrix &&other) noexcept
Move constructor.
KeyedMatrix & operator=(KeyedMatrix< Scalar, RowKeyType, ColKeyType, Eigen::Dynamic, Eigen::Dynamic > &&other) noexcept
Move assignment operator.
KeyedMatrix(KeyedMatrix< Scalar, RowKeyType, ColKeyType, Eigen::Dynamic, Eigen::Dynamic > &&other) noexcept
Move constructor.
Static sized KeyedRowVector.
KeyedRowVector(KeyedRowVector &&other) noexcept
Move constructor.
~KeyedRowVector()=default
Destructor.
KeyedRowVector & operator=(KeyedRowVector &&other) noexcept
Move assignment operator.
KeyedRowVector(KeyedRowVector< Scalar, ColKeyType, Eigen::Dynamic > &&other) noexcept
Move constructor.
KeyedRowVector(const KeyedRowVector &other)
Copy constructor.
KeyedVector< Scalar, ColKeyType, Cols > transposed() const
Calculates the transposed vector.
KeyedRowVector(const Eigen::MatrixBase< Derived > &vector, std::span< const ColKeyType > colKeys)
RowVector constructor.
KeyedRowVector(const KeyedRowVector< Scalar, ColKeyType, Eigen::Dynamic > &other)
Copy constructor.
KeyedRowVector & operator=(const KeyedRowVector< Scalar, ColKeyType, Eigen::Dynamic > &other)
Copy assignment operator.
KeyedRowVector & operator=(const KeyedRowVector &other)
Copy assignment operator.
KeyedRowVector & operator=(KeyedRowVector< Scalar, ColKeyType, Eigen::Dynamic > &&other) noexcept
Move assignment operator.
Static sized KeyedVector.
KeyedVector(KeyedVector< Scalar, RowKeyType, Eigen::Dynamic > &&other) noexcept
Move constructor.
KeyedVector(const KeyedVector &other)
Copy constructor.
KeyedVector & operator=(KeyedVector &&other) noexcept
Move assignment operator.
KeyedVector(KeyedVector &&other) noexcept
Move constructor.
KeyedVector & operator=(KeyedVector< Scalar, RowKeyType, Eigen::Dynamic > &&other) noexcept
Move assignment operator.
KeyedVector(const KeyedVector< Scalar, RowKeyType, Eigen::Dynamic > &other)
Copy constructor.
KeyedVector & operator=(const KeyedVector &other)
Copy assignment operator.
KeyedRowVector< Scalar, RowKeyType, Rows > transposed() const
Calculates the transposed vector.
KeyedVector & operator=(const KeyedVector< Scalar, RowKeyType, Eigen::Dynamic > &other)
Copy assignment operator.
~KeyedVector()=default
Destructor.
KeyedVector(const Eigen::MatrixBase< Derived > &vector, std::span< const RowKeyType > rowKeys)
Vector constructor.
Class to inherit common methods for static and dynamic sized matrices.
decltype(auto) middleCols(std::span< const ColKeyType > colKeys)
Gets the values for the col keys.
decltype(auto) row(const RowKeyType &rowKey) const
Gets the values for the row key.
decltype(auto) middleRows(std::span< const RowKeyType > rowKeys) const
Gets the values for the row keys.
KeyedMatrixBase< Scalar, ColKeyType, RowKeyType, Cols, Rows > transposed() const
Calculates the transposed matrix.
decltype(auto) middleCols(std::span< const ColKeyType > colKeys)
Gets the values for the col keys.
decltype(auto) block(std::span< const RowKeyType > rowKeys, std::span< const ColKeyType > colKeys)
Gets the values for the row and col keys.
void checkContinuousBlock(std::span< const RowKeyType > rowKeys, std::span< const ColKeyType > colKeys, size_t P, size_t Q) const
Checks if the row and col keys are describing a continuous block.
KeyedMatrixBase(KeyedMatrixBase &&other) noexcept
Move constructor.
Scalar & operator()(const RowKeyType &rowKey, const ColKeyType &colKey)
Gets the value for the row and col key.
decltype(auto) block(std::span< const RowKeyType > rowKeys, std::span< const ColKeyType > colKeys)
Gets the values for the row and col keys.
KeyedMatrixBase(const Eigen::MatrixBase< Derived > &matrix)
Constructor.
const Eigen::Matrix< Scalar, Rows, Cols > & block(all_t, all_t) const
Requests the full matrix.
decltype(auto) block(std::span< const RowKeyType > rowKeys, const ColKeyType &colKey)
Gets the values for the row and col keys.
decltype(auto) row(const RowKeyType &rowKey)
Gets the values for the row key.
decltype(auto) middleRows(std::span< const RowKeyType > rowKeys)
Gets the values for the row keys.
KeyedMatrixBase(const KeyedMatrixBase &other)
Copy constructor.
Eigen::Matrix< Scalar, Rows, Cols > & operator()(all_t, all_t)
Requests the full matrix.
decltype(auto) middleCols(std::span< const ColKeyType > colKeys) const
Gets the values for the col keys.
KeyedMatrixBase(KeyedMatrixBase< Scalar, RowKeyType, ColKeyType, oRows, oCols > &&other) noexcept
Move constructor.
decltype(auto) block(std::span< const RowKeyType > rowKeys, const ColKeyType &colKey) const
Gets the values for the row and col keys.
decltype(auto) block(std::span< const RowKeyType > rowKeys, std::span< const ColKeyType > colKeys) const
Gets the values for the row and col keys.
decltype(auto) middleCols(std::span< const ColKeyType > colKeys) const
Gets the values for the col keys.
decltype(auto) middleRows(std::span< const RowKeyType > rowKeys)
Gets the values for the row keys.
KeyedMatrixBase & operator=(const KeyedMatrixBase &other)
Copy assignment operator.
~KeyedMatrixBase()=default
Destructor.
decltype(auto) block(const RowKeyType &rowKey, std::span< const ColKeyType > colKeys)
Gets the values for the row and col keys.
KeyedMatrixBase & operator=(KeyedMatrixBase< Scalar, RowKeyType, ColKeyType, oRows, oCols > &&other) noexcept
Move assignment operator.
decltype(auto) block(std::span< const RowKeyType > rowKeys, std::span< const ColKeyType > colKeys) const
Gets the values for the row and col keys.
const Scalar & operator()(const RowKeyType &rowKey, const ColKeyType &colKey) const
Gets the value for the row and col key.
decltype(auto) block(const RowKeyType &rowKey, std::span< const ColKeyType > colKeys) const
Gets the values for the row and col keys.
decltype(auto) block(std::span< const RowKeyType > rowKeys, const ColKeyType &colKey)
Gets the values for the row and col keys.
decltype(auto) block(const RowKeyType &rowKey, std::span< const ColKeyType > colKeys) const
Gets the values for the row and col keys.
decltype(auto) block(std::span< const RowKeyType > rowKeys, const ColKeyType &colKey) const
Gets the values for the row and col keys.
Eigen::Matrix< Scalar, Rows, Cols > & block(all_t, all_t)
Requests the full matrix.
decltype(auto) col(const ColKeyType &colKey) const
Gets the values for the col key.
decltype(auto) block(const RowKeyType &rowKey, std::span< const ColKeyType > colKeys)
Gets the values for the row and col keys.
KeyedMatrixBase & operator=(const KeyedMatrixBase< Scalar, RowKeyType, ColKeyType, oRows, oCols > &other)
Copy assignment operator.
decltype(auto) middleRows(std::span< const RowKeyType > rowKeys) const
Gets the values for the row keys.
KeyedMatrixBase(const Eigen::MatrixBase< Derived > &matrix, std::span< const RowKeyType > rowKeys, std::span< const ColKeyType > colKeys)
Non-symmetric matrix constructor.
decltype(auto) col(const ColKeyType &colKey)
Gets the values for the col key.
KeyedMatrixBase & operator=(KeyedMatrixBase &&other) noexcept
Move assignment operator.
KeyedMatrixBase< Scalar, RowKeyType, ColKeyType, Rows, Cols > inverse() const
Calculates the inverse matrix.
KeyedMatrixBase(const KeyedMatrixBase< Scalar, RowKeyType, ColKeyType, oRows, oCols > &other)
Copy constructor.
const Eigen::Matrix< Scalar, Rows, Cols > & operator()(all_t, all_t) const
Requests the full matrix.
Base class for Keyed matrices with multiple columns.
void replaceColKey(const ColKeyType &oldKey, const ColKeyType &newKey)
Replace the old with the new key.
bool hasCols(std::span< const ColKeyType > keys) const
Checks if the matrix has multiple keys.
std::vector< ColKeyType > colKeysVector
Col Keys.
friend class KeyedMatrixBase
std::vector< Eigen::Index > colSlice
Col Slice used for accessing.
const std::vector< ColKeyType > & colKeys() const
Returns the col keys.
unordered_map< ColKeyType, Eigen::Index > colIndices
ColKey to Col Index mapping.
decltype(auto) cols() const
Return the cols of the underlying Eigen matrix.
bool hasCol(const ColKeyType &key) const
Checks if the matrix has the key.
friend class KeyedRowVectorBase
bool hasAnyCols(std::span< const ColKeyType > keys) const
Checks if the matrix has any keys.
void removeCol(const ColKeyType &colKey)
Removes the col from the matrix.
void removeCols(std::span< const ColKeyType > colKeys)
Removes the cols from the matrix.
void addCols(std::span< const ColKeyType > colKeys)
Adds new cols to the matrix.
void addCol(const ColKeyType &colKey)
Adds a new col to the matrix.
Base class for Keyed matrices with multiple columns of static size.
Base class for Keyed matrices with multiple rows.
bool hasRows(std::span< const RowKeyType > keys) const
Checks if the matrix has multiple keys.
std::vector< Eigen::Index > rowSlice
Row Slice used for accessing.
unordered_map< RowKeyType, Eigen::Index > rowIndices
RowKey to Row Index mapping.
friend class KeyedMatrixBase
decltype(auto) rows() const
Return the rows of the underlying Eigen matrix.
bool hasRow(const RowKeyType &key) const
Checks if the matrix has the key.
friend class KeyedVectorBase
const std::vector< RowKeyType > & rowKeys() const
Returns the row keys.
bool hasAnyRows(std::span< const RowKeyType > keys) const
Checks if the matrix has any key.
std::vector< RowKeyType > rowKeysVector
Row Keys.
void replaceRowKey(const RowKeyType &oldKey, const RowKeyType &newKey)
Replace the old with the new key.
void removeRows(std::span< const RowKeyType > rowKeys)
Removes the rows from the matrix.
void addRow(const RowKeyType &rowKey)
Adds a new row to the matrix.
void addRows(std::span< const RowKeyType > rowKeys)
Adds new rows to the matrix.
void removeRow(const RowKeyType &rowKey)
Removes the row from the matrix.
Base class for Keyed matrices with multiple rows of static size.
KeyedMatrix storage class.
Eigen::Matrix< Scalar, Rows, Cols > matrix
Data storage of the type.
friend class KeyedMatrixBase
std::mutex _sliceMutex
Mutex for accessing the slices.
friend class KeyedVectorBase
friend class KeyedRowVectorBase
Class to inherit common methods for static and dynamic sized row vectors.
decltype(auto) segment(std::span< const ColKeyType > colKeys) const
Gets the values for the col keys.
KeyedRowVectorBase(const Eigen::MatrixBase< Derived > &vector)
Constructor.
Eigen::Matrix< Scalar, 1, Cols > & operator()(all_t)
Requests the full vector.
const Scalar & operator()(const ColKeyType &colKey) const
Gets the value for the col key.
decltype(auto) segment(std::span< const ColKeyType > colKeys)
Gets the values for the col keys.
decltype(auto) segment(std::span< const ColKeyType > colKeys) const
Gets the values for the col keys.
const Eigen::Matrix< Scalar, 1, Cols > & operator()(all_t) const
Requests the full vector.
KeyedRowVectorBase(KeyedRowVectorBase &&other) noexcept
Move constructor.
KeyedRowVectorBase(const KeyedRowVectorBase< Scalar, ColKeyType, oCols > &other)
Copy constructor.
KeyedRowVectorBase & operator=(KeyedRowVectorBase< Scalar, ColKeyType, oCols > &&other) noexcept
Move assignment operator.
KeyedRowVectorBase & operator=(const KeyedRowVectorBase &other)
Copy assignment operator.
void checkContinuousSegment(std::span< const ColKeyType > colKeys, size_t Q) const
Checks if the col keys are describing a continuous block.
KeyedRowVectorBase & operator=(const KeyedRowVectorBase< Scalar, ColKeyType, oCols > &other)
Copy assignment operator.
~KeyedRowVectorBase()=default
Destructor.
Scalar & operator()(const ColKeyType &colKey)
Gets the value for the col key.
decltype(auto) segment(std::span< const ColKeyType > colKeys)
Gets the values for the col keys.
KeyedRowVectorBase(const Eigen::MatrixBase< Derived > &vector, std::span< const ColKeyType > colKeys)
Constructor.
KeyedRowVectorBase & operator=(KeyedRowVectorBase &&other) noexcept
Move assignment operator.
KeyedRowVectorBase(const KeyedRowVectorBase &other)
Copy constructor.
KeyedRowVectorBase(KeyedRowVectorBase< Scalar, ColKeyType, oCols > &&other) noexcept
Move constructor.
KeyedVectorBase< Scalar, ColKeyType, Cols > transposed() const
Calculates the transposed vector.
Class to inherit common methods for static and dynamic sized vectors.
decltype(auto) segment(std::span< const RowKeyType > rowKeys) const
Gets the values for the row keys.
decltype(auto) segment(std::span< const RowKeyType > rowKeys) const
Gets the values for the row keys.
void checkContinuousSegment(std::span< const RowKeyType > rowKeys, size_t P) const
Checks if the row keys are describing a continuous block.
KeyedVectorBase & operator=(KeyedVectorBase &&other) noexcept
Move assignment operator.
decltype(auto) segment(std::span< const RowKeyType > rowKeys)
Gets the values for the row keys.
decltype(auto) segment(std::span< const RowKeyType > rowKeys)
Gets the values for the row keys.
~KeyedVectorBase()=default
Destructor.
Scalar & operator()(const RowKeyType &rowKey)
Gets the value for the row key.
Eigen::Matrix< Scalar, Rows, 1 > & operator()(all_t)
Requests the full vector.
KeyedVectorBase & operator=(const KeyedVectorBase< Scalar, RowKeyType, oRows > &other)
Copy assignment operator.
KeyedVectorBase & operator=(KeyedVectorBase< Scalar, RowKeyType, oRows > &&other) noexcept
Move assignment operator.
KeyedVectorBase(const Eigen::MatrixBase< Derived > &vector)
Constructor.
KeyedVectorBase(KeyedVectorBase &&other) noexcept
Move constructor.
const Eigen::Matrix< Scalar, Rows, 1 > & operator()(all_t) const
Requests the full vector.
KeyedVectorBase(const Eigen::MatrixBase< Derived > &vector, std::span< const RowKeyType > rowKeys)
Constructor.
const Scalar & operator()(const RowKeyType &rowKey) const
Gets the value for the row key.
KeyedVectorBase(KeyedVectorBase< Scalar, RowKeyType, oRows > &&other) noexcept
Move constructor.
KeyedVectorBase & operator=(const KeyedVectorBase &other)
Copy assignment operator.
KeyedVectorBase(const KeyedVectorBase< Scalar, RowKeyType, oRows > &other)
Copy constructor.
KeyedVectorBase(const KeyedVectorBase &other)
Copy constructor.
KeyedRowVectorBase< Scalar, RowKeyType, Rows > transposed() const
Calculates the transposed vector.
KeyedVector< double, RowKeyType, 2 > KeyedVector2d
Static 2 row KeyedVector with double types.
KeyedRowVectorX< double, ColKeyType > KeyedRowVectorXd
Dynamic size KeyedRowVector with double types.
KeyedRowVector< double, ColKeyType, 6 > KeyedRowVector6d
Static 6 col KeyedRowVector with double types.
KeyedRowVector< double, ColKeyType, 2 > KeyedRowVector2d
Static 2 col KeyedRowVector with double types.
void removeRows(Eigen::DenseBase< Derived > &matrix, size_t index, size_t length)
Removes rows from a matrix or vector.
KeyedMatrix< double, RowKeyType, ColKeyType, 3, 3 > KeyedMatrix3d
Static 3x3 squared size KeyedMatrix with double types.
KeyedMatrix< Scalar, RowKeyType, ColKeyType, Eigen::Dynamic, Eigen::Dynamic > KeyedMatrixX
Dynamic size KeyedMatrix.
KeyedVectorX< double, RowKeyType > KeyedVectorXd
Dynamic size KeyedVector with double types.
KeyedMatrix< double, RowKeyType, ColKeyType, 4, 4 > KeyedMatrix4d
Static 4x4 squared size KeyedMatrix with double types.
KeyedMatrix< double, RowKeyType, ColKeyType, 5, 5 > KeyedMatrix5d
Static 5x5 squared size KeyedMatrix with double types.
KeyedVector< double, RowKeyType, 6 > KeyedVector6d
Static 6 row KeyedVector with double types.
KeyedVector< double, RowKeyType, 5 > KeyedVector5d
Static 5 row KeyedVector with double types.
KeyedRowVector< Scalar, ColKeyType, Eigen::Dynamic > KeyedRowVectorX
Dynamic size KeyedRowVector.
KeyedVector< double, RowKeyType, 4 > KeyedVector4d
Static 4 row KeyedVector with double types.
KeyedMatrix< double, RowKeyType, ColKeyType, 2, 2 > KeyedMatrix2d
Static 2x2 squared size KeyedMatrix with double types.
KeyedVector< Scalar, RowKeyType, Eigen::Dynamic > KeyedVectorX
Dynamic size KeyedVector.
KeyedRowVector< double, ColKeyType, 3 > KeyedRowVector3d
Static 3 col KeyedRowVector with double types.
static const internal::all_t all
Used to request all rows or columns in KeyedMatrices.
void removeCols(Eigen::DenseBase< Derived > &matrix, size_t index, size_t length)
Removes columns from a matrix or vector.
KeyedVector< double, RowKeyType, 3 > KeyedVector3d
Static 3 row KeyedVector with double types.
KeyedRowVector< double, ColKeyType, 4 > KeyedRowVector4d
Static 4 col KeyedRowVector with double types.
KeyedMatrixX< double, RowKeyType, ColKeyType > KeyedMatrixXd
Dynamic size KeyedMatrix with double types.
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.
KeyedRowVector< double, ColKeyType, 5 > KeyedRowVector5d
Static 5 col KeyedRowVector with double types.
KeyedMatrix< double, RowKeyType, ColKeyType, 6, 6 > KeyedMatrix6d
Static 6x6 squared size KeyedMatrix with double types.
All type to request all rows or columns in KeyedMatrices.
all_t()=default
Default Constructor.
std::ostream & operator<<(std::ostream &os, const NAV::KeyedMatrix< Scalar, RowKeyType, ColKeyType, Rows, Cols > &obj)
Stream insertion operator overload.