Search code examples
c++memory-managementdynamiceigen

Error using large Eigen matrix: " OBJECT_ALLOCATED_ON_STACK_IS_TOO_BIG"


I have been using Eigen matrices to test a new code I wrote, and I just ran into this issue for the first time. I just started reading about "Fixed vs. Dynamic size" in Eigen matrices and I thought I was using "dynamic" matrices for large sizes, but when I try using larger number of grids I get the error:

 static assertion failed: OBJECT_ALLOCATED_ON_STACK_IS_TOO_BIG

Example code:

static const int nx = 128;
static const int ny = 128; 

using namespace std;
using namespace Eigen;

int main(){
Eigen::Matrix<double, (ny+1), nx> X; //ERROR HERE
X.setZero();
//other similar initializations 

}

This code is running fine for smaller sizes of nx; ny; but not the case I am showing. Ideally, I would like to run something as large as nx=1024; and ny=1024; Is this not possible using Eigen matrices? Thanks.


Solution

  • As people pointed out in the comments, using the following fixes the issue:

    Eigen::MatrixXd
    

    or

    Eigen::Matrix<double, Eigen::Dynamic, Eigen::Dynamic>