Registered Member
|
I am currently porting some matlab code to C++ and trying to use the Eigen library.And when I compile this block error c2338 had appeared.
int maxD; maxD = tempD.col(2).maxCoeff(); Matrix<int, 50000, 1> md; //MatrixXi md(50000, 1); md = MatrixXi::Constant(maxD);//------error C2338 YOU_CALLED_A_FIXED_SIZE_METHOD_ON_A_DYNAMIC_SIZE MatrixXd tempF(50000,1); tempF = md + tempD.col(3); tempF= md.cwiseQuotient(tempF); If someone know how to solve this problem? |
Moderator
|
You need to specify the size because MatrixXi is a dynamic sized matrix type:
md = VectorXi::Constant(maxD, 50000); Alternatively, since md has already been resized, you can do: md.setConstant(maxD); or md.fill(maxD); Then do not create big fixed size matrices, better replace Matrix<int, 50000, 1> by VectorXi. Moreover, for performance reasons, better use VectorXd than MatrixXd to store vectors. |
Registered Member
|
Thank you for your kind reply! Actually I learn to use this lib recently, and the reason why I use Matrix but Vector is because of the transfer between them is not easy.However, Some method in this library is specify to fixed matrix ,and I have met with the problem of error c2338 about a dynamic Matrix, so I use fixed matrix and define the EIGEN_STACK_ALLOCATION_LIMIT to make it adapt for big matrix. And use method take both fixed and dynamic matrix as parameter will also cause an error.So I just want to make them keep consistent. If the the running efficiency of project will be slow down because of these big fixed matrices?And if dynamic matrices can improve this problem? Would you please modify this block of code as an example? |
Registered users: bartoloni, Bing [Bot], Evergrowing, Google [Bot], ourcraft