I'm trying to use Eigen to solve a sparse linear system in c++, also I'm using Microsoft Visual Studio 2017.
The lines of the code that is using Eigen are bellow:
Eigen::VectorXd x(sizeM), b(sizeM);
Eigen::SparseMatrix<double> A(sizeM, sizeM);
Eigen::SparseLU<Eigen::SparseMatrix<double, Eigen::ColMajor>, Eigen::COLAMDOrdering<Eigen::Index> > solver;
// M is my coefficient array and B is my independent vector.
for (int i = 0; i < sizeM; i++)
{
b(i) = B[i];
}
A.reserve(Eigen::VectorXi::Constant(sizeM, 6));
for (int i = 0; i < sizeM; i++)
{
for (int j = 0; j < sizeM; j++)
{
if (M[i][j] != 0)
{
A.insert(i,j) = M[i][j];
}
}
}
A.makeCompressed();
// Compute the ordering permutation vector from the structural pattern of A.
solver.analyzePattern(A);
// Compute the numerical factorization .
solver.factorize(A);
//Use the factors to solve the linear system .
x = solver.solve(b);
The code error is this:
c:\users\bruno\desktop\c++ apps\eigen\eigen\src\sparselu\sparselu.h(421): error C2664: 'void Eigen::COLAMDOrdering<Eigen::Index>::operator ()<Eigen::SparseMatrix<double,0,int>>(const MatrixType &,Eigen::PermutationMatrix<-1,-1,StorageIndex> &)': cannot convert argument 2 from 'Eigen::PermutationMatrix<-1,-1,int>' to 'Eigen::PermutationMatrix<-1,-1,StorageIndex> &'
1> with
1> [
1> MatrixType=Eigen::SparseMatrix<double,0,int>,
1> StorageIndex=Eigen::Index
1> ]
1> and
1> [
1> StorageIndex=Eigen::Index
1> ]
1>c:\users\bruno\desktop\c++ apps\eigen\eigen\src\sparselu\sparselu.h(412): note: while compiling class template member function 'void Eigen::SparseLU<Eigen::SparseMatrix<double,0,int>,Eigen::COLAMDOrdering<Eigen::Index>>::analyzePattern(const Eigen::SparseMatrix<double,0,int> &)'
1>c:\users\bruno\desktop\c++ apps\project1\project1\main.cpp(386): note: see reference to function template instantiation 'void Eigen::SparseLU<Eigen::SparseMatrix<double,0,int>,Eigen::COLAMDOrdering<Eigen::Index>>::analyzePattern(const Eigen::SparseMatrix<double,0,int> &)' being compiled
1>c:\users\bruno\desktop\c++ apps\project1\project1\main.cpp(367): note: see reference to class template instantiation 'Eigen::SparseLU<Eigen::SparseMatrix<double,0,int>,Eigen::COLAMDOrdering<Eigen::Index>>' being compiled
1>Done building project "Project1.vcxproj" -- FAILED.
I'm new both to Eigen and C++, so I'm not completely sure where is the problem.
Aucun commentaire:
Enregistrer un commentaire