Most efficient option for build 3D structures using Eigen matrices

前端 未结 3 1001
别那么骄傲
别那么骄傲 2021-01-13 16:31

I need a 3D matrix/array structure on my code, and right now I\'m relying on Eigen for both my matrices and vectors.

Right now I am creating a 3D structure using

相关标签:
3条回答
  • 2021-01-13 17:09

    A solution I used is to form a fat matrix containing all the matrices you need stacked.

    MatrixXd A(60*60,60);
    

    and then access them with block operations

    A0 = A.block<60,60>(0*60,0);
    ...
    A5 = A.block<60,60>(5*60,0);
    
    0 讨论(0)
  • 2021-01-13 17:19

    An alternative is to create a very large chunk of memory ones, and maps Eigen matrices from it:

    double* data = new double(60*60 * 60*60*60);
    
    Map<MatrixXd> Mijk(data+60*(60*(60*k)+j)+i), 60, 60);
    

    At this stage you can use Mijk like a MatrixXd object. However, since this not a MatrixXd type, if you want to pass it to a function, your function must either:

    • be of the form foo(Map<MatrixXd> mat)
    • be a template function: template<typename Der> void foo(const MatrixBase<Der>& mat)
    • take a Ref<MatrixXd> object which can handle both Map<> and Matrix<> objects without being a template function and without copies. (doc)
    0 讨论(0)
  • 2021-01-13 17:20

    While it was not available, when the question was asked, Eigen has been providing a Tensor module for a while now. It is still in an "unsupported" stage (meaning the API may change), but basic functionality should be mostly stable. The documentation is scattered here and here.

    0 讨论(0)
提交回复
热议问题