- Memory Alignment
- Passing Eigen objects by value to functions
- Aliasing
- Memory Mapping
- Unary Expression
- Eigen Functor
Refs: 1
In many applications, your data has been stored in different data structures and you need to perform some operations on the data. Suppose you have the following class for presenting your points and you have shape which is std::vector
of such point and now you need to perform an affine matrix transformation on your shape.
struct point {
double a;
double b;
};
One costly approach would be to iterate over your container and copy your data to some Eigen matrix. But there is a better approach. Eigen enables you to map the memory (of your existing data) into your matrices without copying.
std::vector<float> data = {1, 2, 3, 4, 5, 6, 7, 8, 9};
The default alignment is column major:
auto einMatColMajor = Eigen::Map<Eigen::Matrix<float, 3, 3>>(data.data());
auto einMatRowMajor = Eigen::Map<Eigen::Matrix<float, 3, 3, Eigen::RowMajor>>(data.data());