20template <
typename _Scalar,
int _Rows,
int _Cols,
21 int _Options = Eigen::ColMajor,
int Alignment = Eigen::AlignedMax>
23 using alloc_traits = std::allocator_traits<polymorphic_allocator>;
24 static_assert((_Rows == Eigen::Dynamic) || (_Cols == Eigen::Dynamic));
27 m_data = m_allocator.allocate<_Scalar>(size_t(
size()), Alignment);
28 m_allocated_size =
size();
33 m_allocator.deallocate<_Scalar>(m_data, size_t(m_allocated_size),
39 static constexpr int Rows = _Rows;
40 static constexpr int Cols = _Cols;
42 using MatrixType = Eigen::Matrix<Scalar, Rows, Cols, Options>;
43 using MapType = Eigen::Map<MatrixType, Alignment>;
49 MatrixType::IsVectorAtCompileTime;
56 , m_allocator(allocator) {}
61 , m_allocator(allocator) {
63 if constexpr (
Rows == 1) {
66 }
else if constexpr (
Cols == 1) {
78 , m_allocator(allocator) {
91 m_rows = std::move(other.m_rows);
92 m_cols = std::move(other.m_cols);
99 m_data = other.m_data;
100 other.m_data =
nullptr;
101 }
else if (
size() > 0) {
112 m_allocated_size = other.m_allocated_size;
113 m_rows = other.m_rows;
114 m_cols = other.m_cols;
115 m_data = other.m_data;
117 other.m_data =
nullptr;
118 other.m_allocated_size = 0;
122 template <
typename Derived>
131 m_rows = other.m_rows;
132 m_cols = other.m_cols;
133 if (m_allocated_size < other.
size()) {
137 assert(m_allocated_size ==
size());
144 m_rows = other.m_rows;
145 m_cols = other.m_cols;
152 m_data = other.m_data;
153 other.m_data =
nullptr;
162 template <
typename Derived>
164 this->
resize(mat.rows(), mat.cols());
171 if constexpr (
Rows == 1) {
174 }
else if constexpr (
Cols == 1) {
178 if (m_allocated_size <
size) {
188 if (m_allocated_size < new_size) {
212 return MapType{m_data, m_rows, m_cols};
268 Scalar prec = std::numeric_limits<Scalar>::epsilon())
const {
272 template <
typename Derived>
273 bool isApprox(
const Eigen::DenseBase<Derived> &mat,
274 Scalar prec = std::numeric_limits<Scalar>::epsilon())
const {
285 Index m_allocated_size;
Thin wrapper around Eigen::Map representing a matrix object with memory managed by a C++17 polymorphi...
ManagedMatrix & operator=(const ManagedMatrix &other)
ManagedMatrix(ManagedMatrix &&other, const allocator_type &alloc)
Extended move constructor, will use the provided allocator.
Index cols() const noexcept
Eigen::Matrix< Scalar, Rows, Cols, Options > MatrixType
ManagedMatrix(Index rows, Index cols, const allocator_type &allocator)
ManagedMatrix(const Eigen::MatrixBase< Derived > &mat, const allocator_type &alloc={})
Copy constructor from another Eigen matrix.
ConstMapType to_map() const
Obtain const map since this is const.
ManagedMatrix(const ManagedMatrix &other, const allocator_type &alloc={})
ManagedMatrix(ManagedMatrix &&other) noexcept
Nonextended move constructor, will use moved-from object's allocator.
static constexpr int Options
Scalar * data()
Pointer to stored data.
bool isApprox(const ManagedMatrix &other, Scalar prec=std::numeric_limits< Scalar >::epsilon()) const
ManagedMatrix(const allocator_type &allocator={})
Extended default constructor.
void resize(Index rows, Index cols)
ManagedMatrix(Index size, const allocator_type &allocator)
void setConstant(Scalar s)
static constexpr int Cols
Index rows() const noexcept
bool isApprox(const Eigen::DenseBase< Derived > &mat, Scalar prec=std::numeric_limits< Scalar >::epsilon()) const
const Scalar * data() const
Pointer to stored data.
MapType to_map()
Obtain mutable map.
static constexpr bool IsVectorAtCompileTime
ManagedMatrix & operator=(const Eigen::MatrixBase< Derived > &mat)
Eigen::Map< MatrixType, Eigen::AlignedMax > MapType
polymorphic_allocator allocator_type
ManagedMatrix & operator=(ManagedMatrix &&other)
Index allocated_size() const noexcept
Get current allocated size.
Eigen::Map< const MatrixType, Eigen::AlignedMax > ConstMapType
void setZero(Index rows, Index cols)
ConstMapType to_const_map() const
Obtain a const map.
static constexpr int Rows
auto topRows(Index n) const
allocator_type get_allocator() const noexcept
Accessor to retrieve the allocator used for this matrix.
Index size() const noexcept
A convenience subclass of std::pmr::polymorphic_allocator for bytes.