9template <
typename MatrixType,
int Alignment = Eigen::AlignedMax>
11 Eigen::Index rows, Eigen::Index cols) {
12 using MapType = Eigen::Map<MatrixType, Alignment>;
13 using Scalar =
typename MatrixType::Scalar;
14 size_t size = size_t(rows * cols);
15 Scalar *data = alloc.
allocate<Scalar>(size, Alignment);
16 return MapType{data, rows, cols};
19template <
typename MatrixType,
int Alignment = Eigen::AlignedMax>
22 using MapType = Eigen::Map<MatrixType, Alignment>;
23 using Scalar =
typename MatrixType::Scalar;
24 Scalar *data = alloc.
allocate<Scalar>(size_t(size), Alignment);
25 return MapType{data, size};
30template <
typename MatrixType,
int Alignment>
32 Eigen::Map<MatrixType, Alignment> &other) {
33 EIGEN_STATIC_ASSERT_DYNAMIC_SIZE(MatrixType);
34 using MapType = Eigen::Map<MatrixType, Alignment>;
35 typename MatrixType::Scalar *data = other.data();
37 if constexpr (MatrixType::IsVectorAtCompileTime) {
38 ::new (&map) MapType{data, other.size()};
40 ::new (&map) MapType{data, other.rows(), other.cols()};
48template <
typename MatrixType,
int Alignment>
50 Eigen::Index rows, Eigen::Index cols,
51 typename MatrixType::Scalar *data) {
52 EIGEN_STATIC_ASSERT_DYNAMIC_SIZE(MatrixType);
53 using MapType = Eigen::Map<MatrixType, Alignment>;
54 ::new (&map) MapType{data, rows, cols};
58template <
typename MatrixType,
int Alignment>
61 typename MatrixType::Scalar *data) {
62 EIGEN_STATIC_ASSERT_VECTOR_ONLY(MatrixType);
63 EIGEN_STATIC_ASSERT_DYNAMIC_SIZE(MatrixType);
64 using MapType = Eigen::Map<MatrixType, Alignment>;
65 ::new (&map) MapType{data, size};
70template <
typename MatrixType,
int Alignment>
72 Eigen::Index rows, Eigen::Index cols,
74 using Scalar =
typename MatrixType::Scalar;
75 Scalar *data = alloc.template allocate<Scalar>(
size_t(rows * cols));
80template <
typename MatrixType,
int Alignment>
83 using Scalar =
typename MatrixType::Scalar;
84 Scalar *data = alloc.template allocate<Scalar>(
size_t(size), Alignment);
88template <
typename MatrixType,
int Alignment>
90 Eigen::Index rows, Eigen::Index cols,
92 EIGEN_STATIC_ASSERT_DYNAMIC_SIZE(MatrixType);
93 using MapType = Eigen::Map<MatrixType, Alignment>;
94 using Scalar =
typename MatrixType::Scalar;
95 bool need_reallocate = map.size() != rows * cols;
96 Scalar *data = map.data();
97 if (data && need_reallocate) {
98 alloc.template deallocate<Scalar>(data, map.size(), Alignment);
99 data = alloc.template allocate<Scalar>(
size_t(rows * cols));
102 ::new (&map) MapType{data, rows, cols};
105template <
typename MatrixType,
int Alignment>
108 EIGEN_STATIC_ASSERT_DYNAMIC_SIZE(MatrixType);
109 using Scalar =
typename MatrixType::Scalar;
110 size_t dealloc_size = size_t(map.size());
111 if (map.data() != NULL)
112 alloc.template deallocate<Scalar>(map.data(), dealloc_size, Alignment);
116template <
typename MatrixType,
int Alignment>
118 const Eigen::Map<MatrixType, Alignment> &other,
120 if constexpr (MatrixType::IsVectorAtCompileTime) {
A convenience subclass of std::pmr::polymorphic_allocator for bytes.
T * allocate(size_t n, size_t alignment=EIGEN_DEFAULT_ALIGN_BYTES)
void emplace_map_copy(Eigen::Map< MatrixType, Alignment > &map, const Eigen::Map< MatrixType, Alignment > &other, polymorphic_allocator alloc)
Create a deep copy of a managed Eigen::Map object.
void deallocate_map(Eigen::Map< MatrixType, Alignment > &map, polymorphic_allocator alloc)
auto allocate_eigen_map(polymorphic_allocator alloc, Eigen::Index rows, Eigen::Index cols)
void emplace_map_from_data(Eigen::Map< MatrixType, Alignment > &map, Eigen::Index rows, Eigen::Index cols, typename MatrixType::Scalar *data)
Use placement new to create an Eigen::Map object with given dimensions and data pointer.
void emplace_map_steal(Eigen::Map< MatrixType, Alignment > &map, Eigen::Map< MatrixType, Alignment > &other)
In-place construct a map from another one by stealing the other's data.
void emplace_allocated_map(Eigen::Map< MatrixType, Alignment > &map, Eigen::Index rows, Eigen::Index cols, polymorphic_allocator alloc)
Use placement new and an allocator to create an Eigen::Map object to it.
void emplace_resize_map(Eigen::Map< MatrixType, Alignment > &map, Eigen::Index rows, Eigen::Index cols, polymorphic_allocator alloc)