I need use a vector of Eigen matrices in my program. The size of the vector is known. However the matrix size corresponding to each member of the vector can have different size and need to be dynamically allocated. Based on https://eigen.tuxfamily.org/dox/group__TopicStlContainers.html I guess I can declare my matrix as
#define EIGEN_USE_MKL_ALL
#define EIGEN_USE_LAPACKE
// Additional libraries
#include <iomanip>
#include <iostream>
#include <sstream>
#include <fstream>
#include <cstdlib>
#include <algorithm>
#include "Eigen/Core"
#include "Eigen/LU"
#include "Eigen/StdVector"
int A = 4;
int B = 5;
std::vector<Eigen::MatrixXd > inv_K_mat2(A,B);
This results in the following error during compilation
error C2664: 'std::vector<Eigen::MatrixXd,std::allocator<_Ty>>::vector(std::vector<_Ty,std::allocator<_Ty>> &&,const _Alloc &) noexcept(<expr>)': cannot convert argument 2 from 'int' to 'const _Alloc &'
1> with
1> [
1> _Ty=Eigen::MatrixXd,
1> _Alloc=std::allocator<Eigen::MatrixXd>
1> ]
1> and
1> [
1> _Alloc=std::allocator<Eigen::MatrixXd>
1> ]
1>e:\users\pkuma\work\edem_flex_tire\edem-deformable-tire-develop\compiler\pme_flextire_interface.cpp(107): note: Reason: cannot convert from 'int' to 'const _Alloc'
1> with
1> [
1> _Alloc=std::allocator<Eigen::MatrixXd>
1> ]
The compilation is successful if I change the declartion as
std::vector<Eigen::Matrix<double, 4, 5 > > inv_K_mat2;
Is there a different way to initialize a vector of Eigen matrices where the size can be dynamically allocated?