1
votes

For a robotics project I need a 3D matrix of a pre-defined size. Using the Eigen library, I don't see how: 1.) to create a large pre-defined matrix, seems like I have to use matrixXd but that's for a dynamic matrix. 2.) create a 3D matrix, i. e. size = (int from 200 to 1000) and matrix (size, size, size)

2
There is an unsupported tensor class, see here.davidhigh
Also, note that a pre-defined sized Matrix is allocated on the stack, whereas the dynamic MatrixXd is allocated on the heap.Avi Ginsburg

2 Answers

1
votes
  1. Creating a large matrix using static allocation is not advised as it will degrade the performance.
  2. Instead of a 3D matrix, you can create a Vector of 2D matrices.

    eg: Eigen::MatrixX< Eigen::MatrixXf, DIMENSION, 1> tmp;

0
votes

Well, I find a way to build a 3d matrix in my project. Use the vector:

typedef vector<Matrix<double, Dynamic, Dynamic>> M3;

If you want to initialize a pre-defined matrix with dimension (k,m,n), just use:

M3 W(k, M2(m, n));

This way is easy to store Eigen Matrix. But if you want to calculate 3d matrix, you should slice it to many 2d Matrix and use a loop to get the 3d result.