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_>
58 friend class KeyedMatrixBase;
59 template<
typename Scalar_,
typename RowKeyType_,
int Rows_>
60 friend class KeyedVectorBase;
61 template<
typename Scalar_,
typename ColKeyType_,
int Cols_>
62 friend class KeyedRowVectorBase;
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_>
124 friend class KeyedMatrixBase;
125 template<
typename Scalar_,
typename RowKeyType_,
int Rows_>
126 friend class KeyedVectorBase;
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_>
269 friend class KeyedMatrixBase;
270 template<
typename Scalar_,
typename ColKeyType_,
int Cols_>
271 friend class KeyedRowVectorBase;
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>
1584 : internal::KeyedVectorBase<Scalar, RowKeyType, Eigen::Dynamic>(Eigen::VectorX<Scalar>()) {}
1590 template<
typename Derived>
1591 KeyedVector(
const Eigen::MatrixBase<Derived>& vector, std::span<const RowKeyType>
rowKeys)
1592 : internal::KeyedVectorBase<Scalar, RowKeyType, Eigen::Dynamic>(vector,
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>
1810 : internal::KeyedRowVectorBase<Scalar, ColKeyType, Eigen::Dynamic>(Eigen::RowVectorX<Scalar>()) {}
1816 template<
typename Derived>
1818 : internal::KeyedRowVectorBase<Scalar, ColKeyType, Eigen::Dynamic>(vector,
colKeys)
1830 : internal::KeyedRowVectorBase<Scalar, ColKeyType, Eigen::Dynamic>(other)
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));
1868 : 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>
2070 : internal::KeyedMatrixBase<Scalar, RowKeyType, ColKeyType, Eigen::Dynamic, Eigen::Dynamic>(Eigen::MatrixX<Scalar>()) {}
2077 template<
typename Derived>
2079 : internal::KeyedMatrixBase<Scalar, RowKeyType, ColKeyType, Eigen::Dynamic, Eigen::Dynamic>(
matrix,
rowKeys,
colKeys)
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.
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:149
void removeCols(Eigen::DenseBase< Derived > &matrix, size_t index, size_t length)
Removes columns from a matrix or vector.
Definition Eigen.hpp:185
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:223
ankerl::unordered_dense::map< Key, T > unordered_map
Unordered map type.
Definition Unordered_map.hpp:34
Vector Utility functions.
Static sized KeyedMatrix.
Definition KeyedMatrix.hpp:1921
KeyedMatrix(const KeyedMatrix< Scalar, RowKeyType, ColKeyType, Eigen::Dynamic, Eigen::Dynamic > &other)
Copy constructor.
Definition KeyedMatrix.hpp:1987
KeyedMatrix(const KeyedMatrix &other)
Copy constructor.
Definition KeyedMatrix.hpp:1950
KeyedMatrix & operator=(const KeyedMatrix &other)
Copy assignment operator.
Definition KeyedMatrix.hpp:1955
~KeyedMatrix()=default
Destructor.
KeyedMatrix< Scalar, RowKeyType, ColKeyType, Rows, Cols > transposed() const
Calculates the transposed matrix.
Definition KeyedMatrix.hpp:2045
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.
Definition KeyedMatrix.hpp:2034
KeyedMatrix & operator=(const KeyedMatrix< Scalar, RowKeyType, ColKeyType, Eigen::Dynamic, Eigen::Dynamic > &other)
Copy assignment operator.
Definition KeyedMatrix.hpp:1994
KeyedMatrix & operator=(KeyedMatrix &&other) noexcept
Move assignment operator.
Definition KeyedMatrix.hpp:1971
KeyedMatrix(const Eigen::MatrixBase< Derived > &matrix, std::span< const RowKeyType > rowKeys, std::span< const ColKeyType > colKeys)
Non-symmetric matrix constructor.
Definition KeyedMatrix.hpp:1929
KeyedMatrix< Scalar, RowKeyType, ColKeyType, Rows, Cols > inverse() const
Calculates the inverse matrix.
Definition KeyedMatrix.hpp:2052
KeyedMatrix(const Eigen::MatrixBase< Derived > &matrix, std::span< const RowKeyType > keys)
Symmetric matrix constructor.
Definition KeyedMatrix.hpp:1938
KeyedMatrix(KeyedMatrix &&other) noexcept
Move constructor.
Definition KeyedMatrix.hpp:1966
KeyedMatrix & operator=(KeyedMatrix< Scalar, RowKeyType, ColKeyType, Eigen::Dynamic, Eigen::Dynamic > &&other) noexcept
Move assignment operator.
Definition KeyedMatrix.hpp:2014
KeyedMatrix(KeyedMatrix< Scalar, RowKeyType, ColKeyType, Eigen::Dynamic, Eigen::Dynamic > &&other) noexcept
Move constructor.
Definition KeyedMatrix.hpp:2007
Static sized KeyedRowVector.
Definition KeyedMatrix.hpp:1693
KeyedRowVector(KeyedRowVector &&other) noexcept
Move constructor.
Definition KeyedMatrix.hpp:1728
~KeyedRowVector()=default
Destructor.
KeyedRowVector & operator=(KeyedRowVector &&other) noexcept
Move assignment operator.
Definition KeyedMatrix.hpp:1733
KeyedRowVector(KeyedRowVector< Scalar, ColKeyType, Eigen::Dynamic > &&other) noexcept
Move constructor.
Definition KeyedMatrix.hpp:1769
KeyedRowVector(const KeyedRowVector &other)
Copy constructor.
Definition KeyedMatrix.hpp:1712
KeyedVector< Scalar, ColKeyType, Cols > transposed() const
Calculates the transposed vector.
Definition KeyedMatrix.hpp:1793
KeyedRowVector(const Eigen::MatrixBase< Derived > &vector, std::span< const ColKeyType > colKeys)
RowVector constructor.
Definition KeyedMatrix.hpp:1700
KeyedRowVector(const KeyedRowVector< Scalar, ColKeyType, Eigen::Dynamic > &other)
Copy constructor.
Definition KeyedMatrix.hpp:1749
KeyedRowVector & operator=(const KeyedRowVector< Scalar, ColKeyType, Eigen::Dynamic > &other)
Copy assignment operator.
Definition KeyedMatrix.hpp:1756
KeyedRowVector & operator=(const KeyedRowVector &other)
Copy assignment operator.
Definition KeyedMatrix.hpp:1717
KeyedRowVector & operator=(KeyedRowVector< Scalar, ColKeyType, Eigen::Dynamic > &&other) noexcept
Move assignment operator.
Definition KeyedMatrix.hpp:1776
Static sized KeyedVector.
Definition KeyedMatrix.hpp:1468
KeyedVector(KeyedVector< Scalar, RowKeyType, Eigen::Dynamic > &&other) noexcept
Move constructor.
Definition KeyedMatrix.hpp:1544
KeyedVector(const KeyedVector &other)
Copy constructor.
Definition KeyedMatrix.hpp:1487
KeyedVector & operator=(KeyedVector &&other) noexcept
Move assignment operator.
Definition KeyedMatrix.hpp:1508
KeyedVector(KeyedVector &&other) noexcept
Move constructor.
Definition KeyedMatrix.hpp:1503
KeyedVector & operator=(KeyedVector< Scalar, RowKeyType, Eigen::Dynamic > &&other) noexcept
Move assignment operator.
Definition KeyedMatrix.hpp:1551
KeyedVector(const KeyedVector< Scalar, RowKeyType, Eigen::Dynamic > &other)
Copy constructor.
Definition KeyedMatrix.hpp:1524
KeyedVector & operator=(const KeyedVector &other)
Copy assignment operator.
Definition KeyedMatrix.hpp:1492
KeyedRowVector< Scalar, RowKeyType, Rows > transposed() const
Calculates the transposed vector.
Definition KeyedMatrix.hpp:1568
KeyedVector & operator=(const KeyedVector< Scalar, RowKeyType, Eigen::Dynamic > &other)
Copy assignment operator.
Definition KeyedMatrix.hpp:1531
~KeyedVector()=default
Destructor.
KeyedVector(const Eigen::MatrixBase< Derived > &vector, std::span< const RowKeyType > rowKeys)
Vector constructor.
Definition KeyedMatrix.hpp:1475
Class to inherit common methods for static and dynamic sized matrices.
Definition KeyedMatrix.hpp:902
decltype(auto) middleCols(std::span< const ColKeyType > colKeys)
Gets the values for the col keys.
Definition KeyedMatrix.hpp:1286
decltype(auto) row(const RowKeyType &rowKey) const
Gets the values for the row key.
Definition KeyedMatrix.hpp:1295
decltype(auto) middleRows(std::span< const RowKeyType > rowKeys) const
Gets the values for the row keys.
Definition KeyedMatrix.hpp:1374
KeyedMatrixBase< Scalar, ColKeyType, RowKeyType, Cols, Rows > transposed() const
Calculates the transposed matrix.
Definition KeyedMatrix.hpp:1413
decltype(auto) middleCols(std::span< const ColKeyType > colKeys)
Gets the values for the col keys.
Definition KeyedMatrix.hpp:1401
decltype(auto) block(std::span< const RowKeyType > rowKeys, std::span< const ColKeyType > colKeys)
Gets the values for the row and col keys.
Definition KeyedMatrix.hpp:1209
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.
Definition KeyedMatrix.hpp:1430
KeyedMatrixBase(KeyedMatrixBase &&other) noexcept
Move constructor.
Definition KeyedMatrix.hpp:973
Scalar & operator()(const RowKeyType &rowKey, const ColKeyType &colKey)
Gets the value for the row and col key.
Definition KeyedMatrix.hpp:1093
decltype(auto) block(std::span< const RowKeyType > rowKeys, std::span< const ColKeyType > colKeys)
Gets the values for the row and col keys.
Definition KeyedMatrix.hpp:1332
KeyedMatrixBase(const Eigen::MatrixBase< Derived > &matrix)
Constructor.
Definition KeyedMatrix.hpp:907
const Eigen::Matrix< Scalar, Rows, Cols > & block(all_t, all_t) const
Requests the full matrix.
Definition KeyedMatrix.hpp:1310
decltype(auto) block(std::span< const RowKeyType > rowKeys, const ColKeyType &colKey)
Gets the values for the row and col keys.
Definition KeyedMatrix.hpp:1229
decltype(auto) row(const RowKeyType &rowKey)
Gets the values for the row key.
Definition KeyedMatrix.hpp:1299
decltype(auto) middleRows(std::span< const RowKeyType > rowKeys)
Gets the values for the row keys.
Definition KeyedMatrix.hpp:1383
KeyedMatrixBase(const KeyedMatrixBase &other)
Copy constructor.
Definition KeyedMatrix.hpp:945
Eigen::Matrix< Scalar, Rows, Cols > & operator()(all_t, all_t)
Requests the full matrix.
Definition KeyedMatrix.hpp:1185
decltype(auto) middleCols(std::span< const ColKeyType > colKeys) const
Gets the values for the col keys.
Definition KeyedMatrix.hpp:1392
KeyedMatrixBase(KeyedMatrixBase< Scalar, RowKeyType, ColKeyType, oRows, oCols > &&other) noexcept
Move constructor.
Definition KeyedMatrix.hpp:1043
decltype(auto) block(std::span< const RowKeyType > rowKeys, const ColKeyType &colKey) const
Gets the values for the row and col keys.
Definition KeyedMatrix.hpp:1220
decltype(auto) block(std::span< const RowKeyType > rowKeys, std::span< const ColKeyType > colKeys) const
Gets the values for the row and col keys.
Definition KeyedMatrix.hpp:1322
decltype(auto) middleCols(std::span< const ColKeyType > colKeys) const
Gets the values for the col keys.
Definition KeyedMatrix.hpp:1276
decltype(auto) middleRows(std::span< const RowKeyType > rowKeys)
Gets the values for the row keys.
Definition KeyedMatrix.hpp:1266
KeyedMatrixBase & operator=(const KeyedMatrixBase &other)
Copy assignment operator.
Definition KeyedMatrix.hpp:957
~KeyedMatrixBase()=default
Destructor.
decltype(auto) block(const RowKeyType &rowKey, std::span< const ColKeyType > colKeys)
Gets the values for the row and col keys.
Definition KeyedMatrix.hpp:1247
KeyedMatrixBase & operator=(KeyedMatrixBase< Scalar, RowKeyType, ColKeyType, oRows, oCols > &&other) noexcept
Move assignment operator.
Definition KeyedMatrix.hpp:1059
decltype(auto) block(std::span< const RowKeyType > rowKeys, std::span< const ColKeyType > colKeys) const
Gets the values for the row and col keys.
Definition KeyedMatrix.hpp:1198
const Scalar & operator()(const RowKeyType &rowKey, const ColKeyType &colKey) const
Gets the value for the row and col key.
Definition KeyedMatrix.hpp:1085
decltype(auto) block(const RowKeyType &rowKey, std::span< const ColKeyType > colKeys) const
Gets the values for the row and col keys.
Definition KeyedMatrix.hpp:1238
decltype(auto) block(std::span< const RowKeyType > rowKeys, const ColKeyType &colKey)
Gets the values for the row and col keys.
Definition KeyedMatrix.hpp:1350
decltype(auto) block(const RowKeyType &rowKey, std::span< const ColKeyType > colKeys) const
Gets the values for the row and col keys.
Definition KeyedMatrix.hpp:1358
decltype(auto) block(std::span< const RowKeyType > rowKeys, const ColKeyType &colKey) const
Gets the values for the row and col keys.
Definition KeyedMatrix.hpp:1342
Eigen::Matrix< Scalar, Rows, Cols > & block(all_t, all_t)
Requests the full matrix.
Definition KeyedMatrix.hpp:1312
decltype(auto) col(const ColKeyType &colKey) const
Gets the values for the col key.
Definition KeyedMatrix.hpp:1303
decltype(auto) block(const RowKeyType &rowKey, std::span< const ColKeyType > colKeys)
Gets the values for the row and col keys.
Definition KeyedMatrix.hpp:1366
KeyedMatrixBase & operator=(const KeyedMatrixBase< Scalar, RowKeyType, ColKeyType, oRows, oCols > &other)
Copy assignment operator.
Definition KeyedMatrix.hpp:1023
decltype(auto) middleRows(std::span< const RowKeyType > rowKeys) const
Gets the values for the row keys.
Definition KeyedMatrix.hpp:1256
KeyedMatrixBase(const Eigen::MatrixBase< Derived > &matrix, std::span< const RowKeyType > rowKeys, std::span< const ColKeyType > colKeys)
Non-symmetric matrix constructor.
Definition KeyedMatrix.hpp:916
decltype(auto) col(const ColKeyType &colKey)
Gets the values for the col key.
Definition KeyedMatrix.hpp:1307
KeyedMatrixBase & operator=(KeyedMatrixBase &&other) noexcept
Move assignment operator.
Definition KeyedMatrix.hpp:985
KeyedMatrixBase< Scalar, RowKeyType, ColKeyType, Rows, Cols > inverse() const
Calculates the inverse matrix.
Definition KeyedMatrix.hpp:1419
KeyedMatrixBase(const KeyedMatrixBase< Scalar, RowKeyType, ColKeyType, oRows, oCols > &other)
Copy constructor.
Definition KeyedMatrix.hpp:1007
const Eigen::Matrix< Scalar, Rows, Cols > & operator()(all_t, all_t) const
Requests the full matrix.
Definition KeyedMatrix.hpp:1183
Base class for Keyed matrices with multiple columns.
Definition KeyedMatrix.hpp:219
void replaceColKey(const ColKeyType &oldKey, const ColKeyType &newKey)
Replace the old with the new key.
Definition KeyedMatrix.hpp:248
bool hasCols(std::span< const ColKeyType > keys) const
Checks if the matrix has multiple keys.
Definition KeyedMatrix.hpp:233
std::vector< ColKeyType > colKeysVector
Col Keys.
Definition KeyedMatrix.hpp:262
std::vector< Eigen::Index > colSlice
Col Slice used for accessing.
Definition KeyedMatrix.hpp:265
const std::vector< ColKeyType > & colKeys() const
Returns the col keys.
Definition KeyedMatrix.hpp:225
unordered_map< ColKeyType, Eigen::Index > colIndices
ColKey to Col Index mapping.
Definition KeyedMatrix.hpp:260
decltype(auto) cols() const
Return the cols of the underlying Eigen matrix.
Definition KeyedMatrix.hpp:222
bool hasCol(const ColKeyType &key) const
Checks if the matrix has the key.
Definition KeyedMatrix.hpp:229
bool hasAnyCols(std::span< const ColKeyType > keys) const
Checks if the matrix has any keys.
Definition KeyedMatrix.hpp:240
void removeCol(const ColKeyType &colKey)
Removes the col from the matrix.
Definition KeyedMatrix.hpp:319
void removeCols(std::span< const ColKeyType > colKeys)
Removes the cols from the matrix.
Definition KeyedMatrix.hpp:323
void addCols(std::span< const ColKeyType > colKeys)
Adds new cols to the matrix.
Definition KeyedMatrix.hpp:297
void addCol(const ColKeyType &colKey)
Adds a new col to the matrix.
Definition KeyedMatrix.hpp:293
Base class for Keyed matrices with multiple columns of static size.
Definition KeyedMatrix.hpp:281
Base class for Keyed matrices with multiple rows.
Definition KeyedMatrix.hpp:74
bool hasRows(std::span< const RowKeyType > keys) const
Checks if the matrix has multiple keys.
Definition KeyedMatrix.hpp:88
std::vector< Eigen::Index > rowSlice
Row Slice used for accessing.
Definition KeyedMatrix.hpp:120
unordered_map< RowKeyType, Eigen::Index > rowIndices
RowKey to Row Index mapping.
Definition KeyedMatrix.hpp:115
decltype(auto) rows() const
Return the rows of the underlying Eigen matrix.
Definition KeyedMatrix.hpp:77
bool hasRow(const RowKeyType &key) const
Checks if the matrix has the key.
Definition KeyedMatrix.hpp:84
const std::vector< RowKeyType > & rowKeys() const
Returns the row keys.
Definition KeyedMatrix.hpp:80
bool hasAnyRows(std::span< const RowKeyType > keys) const
Checks if the matrix has any key.
Definition KeyedMatrix.hpp:95
std::vector< RowKeyType > rowKeysVector
Row Keys.
Definition KeyedMatrix.hpp:117
void replaceRowKey(const RowKeyType &oldKey, const RowKeyType &newKey)
Replace the old with the new key.
Definition KeyedMatrix.hpp:103
void removeRows(std::span< const RowKeyType > rowKeys)
Removes the rows from the matrix.
Definition KeyedMatrix.hpp:178
void addRow(const RowKeyType &rowKey)
Adds a new row to the matrix.
Definition KeyedMatrix.hpp:148
void addRows(std::span< const RowKeyType > rowKeys)
Adds new rows to the matrix.
Definition KeyedMatrix.hpp:152
void removeRow(const RowKeyType &rowKey)
Removes the row from the matrix.
Definition KeyedMatrix.hpp:174
Base class for Keyed matrices with multiple rows of static size.
Definition KeyedMatrix.hpp:136
KeyedMatrix storage class.
Definition KeyedMatrix.hpp:51
Eigen::Matrix< Scalar, Rows, Cols > matrix
Data storage of the type.
Definition KeyedMatrix.hpp:53
std::mutex _sliceMutex
Mutex for accessing the slices.
Definition KeyedMatrix.hpp:54
Class to inherit common methods for static and dynamic sized row vectors.
Definition KeyedMatrix.hpp:633
decltype(auto) segment(std::span< const ColKeyType > colKeys) const
Gets the values for the col keys.
Definition KeyedMatrix.hpp:849
KeyedRowVectorBase(const Eigen::MatrixBase< Derived > &vector)
Constructor.
Definition KeyedMatrix.hpp:638
Eigen::Matrix< Scalar, 1, Cols > & operator()(all_t)
Requests the full vector.
Definition KeyedMatrix.hpp:818
const Scalar & operator()(const ColKeyType &colKey) const
Gets the value for the col key.
Definition KeyedMatrix.hpp:780
decltype(auto) segment(std::span< const ColKeyType > colKeys)
Gets the values for the col keys.
Definition KeyedMatrix.hpp:858
decltype(auto) segment(std::span< const ColKeyType > colKeys) const
Gets the values for the col keys.
Definition KeyedMatrix.hpp:830
const Eigen::Matrix< Scalar, 1, Cols > & operator()(all_t) const
Requests the full vector.
Definition KeyedMatrix.hpp:816
KeyedRowVectorBase(KeyedRowVectorBase &&other) noexcept
Move constructor.
Definition KeyedMatrix.hpp:691
KeyedRowVectorBase(const KeyedRowVectorBase< Scalar, ColKeyType, oCols > &other)
Copy constructor.
Definition KeyedMatrix.hpp:719
KeyedRowVectorBase & operator=(KeyedRowVectorBase< Scalar, ColKeyType, oCols > &&other) noexcept
Move assignment operator.
Definition KeyedMatrix.hpp:759
KeyedRowVectorBase & operator=(const KeyedRowVectorBase &other)
Copy assignment operator.
Definition KeyedMatrix.hpp:678
void checkContinuousSegment(std::span< const ColKeyType > colKeys, size_t Q) const
Checks if the col keys are describing a continuous block.
Definition KeyedMatrix.hpp:879
KeyedRowVectorBase & operator=(const KeyedRowVectorBase< Scalar, ColKeyType, oCols > &other)
Copy assignment operator.
Definition KeyedMatrix.hpp:731
~KeyedRowVectorBase()=default
Destructor.
Scalar & operator()(const ColKeyType &colKey)
Gets the value for the col key.
Definition KeyedMatrix.hpp:787
decltype(auto) segment(std::span< const ColKeyType > colKeys)
Gets the values for the col keys.
Definition KeyedMatrix.hpp:840
KeyedRowVectorBase(const Eigen::MatrixBase< Derived > &vector, std::span< const ColKeyType > colKeys)
Constructor.
Definition KeyedMatrix.hpp:647
KeyedRowVectorBase & operator=(KeyedRowVectorBase &&other) noexcept
Move assignment operator.
Definition KeyedMatrix.hpp:700
KeyedRowVectorBase(const KeyedRowVectorBase &other)
Copy constructor.
Definition KeyedMatrix.hpp:669
KeyedRowVectorBase(KeyedRowVectorBase< Scalar, ColKeyType, oCols > &&other) noexcept
Move constructor.
Definition KeyedMatrix.hpp:747
KeyedVectorBase< Scalar, ColKeyType, Cols > transposed() const
Calculates the transposed vector.
Definition KeyedMatrix.hpp:870
Class to inherit common methods for static and dynamic sized vectors.
Definition KeyedMatrix.hpp:366
decltype(auto) segment(std::span< const RowKeyType > rowKeys) const
Gets the values for the row keys.
Definition KeyedMatrix.hpp:563
decltype(auto) segment(std::span< const RowKeyType > rowKeys) const
Gets the values for the row keys.
Definition KeyedMatrix.hpp:582
void checkContinuousSegment(std::span< const RowKeyType > rowKeys, size_t P) const
Checks if the row keys are describing a continuous block.
Definition KeyedMatrix.hpp:612
KeyedVectorBase & operator=(KeyedVectorBase &&other) noexcept
Move assignment operator.
Definition KeyedMatrix.hpp:433
decltype(auto) segment(std::span< const RowKeyType > rowKeys)
Gets the values for the row keys.
Definition KeyedMatrix.hpp:591
decltype(auto) segment(std::span< const RowKeyType > rowKeys)
Gets the values for the row keys.
Definition KeyedMatrix.hpp:573
~KeyedVectorBase()=default
Destructor.
Scalar & operator()(const RowKeyType &rowKey)
Gets the value for the row key.
Definition KeyedMatrix.hpp:520
Eigen::Matrix< Scalar, Rows, 1 > & operator()(all_t)
Requests the full vector.
Definition KeyedMatrix.hpp:551
KeyedVectorBase & operator=(const KeyedVectorBase< Scalar, RowKeyType, oRows > &other)
Copy assignment operator.
Definition KeyedMatrix.hpp:464
KeyedVectorBase & operator=(KeyedVectorBase< Scalar, RowKeyType, oRows > &&other) noexcept
Move assignment operator.
Definition KeyedMatrix.hpp:492
KeyedVectorBase(const Eigen::MatrixBase< Derived > &vector)
Constructor.
Definition KeyedMatrix.hpp:371
KeyedVectorBase(KeyedVectorBase &&other) noexcept
Move constructor.
Definition KeyedMatrix.hpp:424
const Eigen::Matrix< Scalar, Rows, 1 > & operator()(all_t) const
Requests the full vector.
Definition KeyedMatrix.hpp:549
KeyedVectorBase(const Eigen::MatrixBase< Derived > &vector, std::span< const RowKeyType > rowKeys)
Constructor.
Definition KeyedMatrix.hpp:380
const Scalar & operator()(const RowKeyType &rowKey) const
Gets the value for the row key.
Definition KeyedMatrix.hpp:513
KeyedVectorBase(KeyedVectorBase< Scalar, RowKeyType, oRows > &&other) noexcept
Move constructor.
Definition KeyedMatrix.hpp:480
KeyedVectorBase & operator=(const KeyedVectorBase &other)
Copy assignment operator.
Definition KeyedMatrix.hpp:411
KeyedVectorBase(const KeyedVectorBase< Scalar, RowKeyType, oRows > &other)
Copy constructor.
Definition KeyedMatrix.hpp:452
KeyedVectorBase(const KeyedVectorBase &other)
Copy constructor.
Definition KeyedMatrix.hpp:402
KeyedRowVectorBase< Scalar, RowKeyType, Rows > transposed() const
Calculates the transposed vector.
Definition KeyedMatrix.hpp:603
EGM96 coefficients.
Definition GMFCoeffs.hpp:21
All type to request all rows or columns in KeyedMatrices.
Definition KeyedMatrix.hpp:40
all_t()=default
Default Constructor.
KeyedVector< double, RowKeyType, 2 > KeyedVector2d
Static 2 row KeyedVector with double types.
Definition KeyedMatrix.hpp:2352
KeyedRowVectorX< double, ColKeyType > KeyedRowVectorXd
Dynamic size KeyedRowVector with double types.
Definition KeyedMatrix.hpp:2377
KeyedRowVector< double, ColKeyType, 6 > KeyedRowVector6d
Static 6 col KeyedRowVector with double types.
Definition KeyedMatrix.hpp:2397
KeyedRowVector< double, ColKeyType, 2 > KeyedRowVector2d
Static 2 col KeyedRowVector with double types.
Definition KeyedMatrix.hpp:2381
KeyedMatrix< double, RowKeyType, ColKeyType, 3, 3 > KeyedMatrix3d
Static 3x3 squared size KeyedMatrix with double types.
Definition KeyedMatrix.hpp:2323
KeyedMatrix< Scalar, RowKeyType, ColKeyType, Eigen::Dynamic, Eigen::Dynamic > KeyedMatrixX
Dynamic size KeyedMatrix.
Definition KeyedMatrix.hpp:2308
KeyedVectorX< double, RowKeyType > KeyedVectorXd
Dynamic size KeyedVector with double types.
Definition KeyedMatrix.hpp:2348
KeyedMatrix< double, RowKeyType, ColKeyType, 4, 4 > KeyedMatrix4d
Static 4x4 squared size KeyedMatrix with double types.
Definition KeyedMatrix.hpp:2328
KeyedMatrix< double, RowKeyType, ColKeyType, 5, 5 > KeyedMatrix5d
Static 5x5 squared size KeyedMatrix with double types.
Definition KeyedMatrix.hpp:2333
KeyedVector< double, RowKeyType, 6 > KeyedVector6d
Static 6 row KeyedVector with double types.
Definition KeyedMatrix.hpp:2368
KeyedVector< double, RowKeyType, 5 > KeyedVector5d
Static 5 row KeyedVector with double types.
Definition KeyedMatrix.hpp:2364
KeyedRowVector< Scalar, ColKeyType, Eigen::Dynamic > KeyedRowVectorX
Dynamic size KeyedRowVector.
Definition KeyedMatrix.hpp:2373
KeyedVector< double, RowKeyType, 4 > KeyedVector4d
Static 4 row KeyedVector with double types.
Definition KeyedMatrix.hpp:2360
KeyedMatrix< double, RowKeyType, ColKeyType, 2, 2 > KeyedMatrix2d
Static 2x2 squared size KeyedMatrix with double types.
Definition KeyedMatrix.hpp:2318
KeyedVector< Scalar, RowKeyType, Eigen::Dynamic > KeyedVectorX
Dynamic size KeyedVector.
Definition KeyedMatrix.hpp:2344
KeyedRowVector< double, ColKeyType, 3 > KeyedRowVector3d
Static 3 col KeyedRowVector with double types.
Definition KeyedMatrix.hpp:2385
std::ostream & operator<<(std::ostream &os, const NAV::KeyedMatrix< Scalar, RowKeyType, ColKeyType, Rows, Cols > &obj)
Stream insertion operator overload.
Definition KeyedMatrix.hpp:2614
static const internal::all_t all
Used to request all rows or columns in KeyedMatrices.
Definition KeyedMatrix.hpp:1457
KeyedVector< double, RowKeyType, 3 > KeyedVector3d
Static 3 row KeyedVector with double types.
Definition KeyedMatrix.hpp:2356
KeyedRowVector< double, ColKeyType, 4 > KeyedRowVector4d
Static 4 col KeyedRowVector with double types.
Definition KeyedMatrix.hpp:2389
KeyedMatrixX< double, RowKeyType, ColKeyType > KeyedMatrixXd
Dynamic size KeyedMatrix with double types.
Definition KeyedMatrix.hpp:2313
KeyedRowVector< double, ColKeyType, 5 > KeyedRowVector5d
Static 5 col KeyedRowVector with double types.
Definition KeyedMatrix.hpp:2393
KeyedMatrix< double, RowKeyType, ColKeyType, 6, 6 > KeyedMatrix6d
Static 6x6 squared size KeyedMatrix with double types.
Definition KeyedMatrix.hpp:2338