Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Most efficient option for build 3D structures using Eigen matrices

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 new:

MatrixXd* cube= new MatrixXd[60];
for (int i; i<60; i++) cube[i]=MatrixXd(60,60);

and for acessing the values:

double val;
MatrixXd pos;
for (int i; i<60; i++){
    pos=cube[i];
    for (int j; j<60; j++){
        for (int k; k<60; k++){
            val=pos(j,k);
            //...
        }
    }
}

However, right now it is very slow in this part of the code, which makes me beleive that this might not be the most efficient way. Are there any alternatives?

like image 993
joaocandre Avatar asked Jun 13 '13 22:06

joaocandre


2 Answers

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.

like image 126
chtz Avatar answered Oct 29 '22 12:10

chtz


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);
like image 35
FlavioG Avatar answered Oct 29 '22 10:10

FlavioG