This forum has been archived. All content is frozen. Please use KDE Discuss instead.

Compiler error in setFromTriplets

Tags: None
(comma "," separated)
-Roman-
Registered Member
Posts
16
Karma
0

Compiler error in setFromTriplets

Sat Oct 13, 2012 5:07 pm
Hi,

I get the following compiler error when calling the method setFromTriplets on a sparse matrix:

Code: Select all
error: more than one instance of overloaded function "Eigen::SparseMatrix<_Scalar, _Options, _Index>::reserve [with _Scalar=std::complex<double>, _Options=1, _Index=int]" matches the argument list:
            function template "void Eigen::SparseMatrix<_Scalar, _Options, _Index>::reserve(const SizesType &, const SizesType::value_type &) [with _Scalar=std::complex<double>, _Options=1, _Index=int]"
            function template "void Eigen::SparseMatrix<_Scalar, _Options, _Index>::reserve(const SizesType &, const SizesType::Scalar &) [with _Scalar=std::complex<double>, _Options=1, _Index=int]"
            argument types are: (Eigen::VectorXi)
            object type is: Eigen::SparseMatrix<std::complex<double>, 1, int>
    trMat.reserve(wi);
          ^
          detected during:
            instantiation of "void Eigen::internal::set_from_triplets(const InputIterator &, const InputIterator &, SparseMatrixType &, int) [with InputIterator=__gnu_cxx::__normal_iterator<Eigen::Triplet<std::complex<double>, unsigned int> *, std::vector<Eigen::Triplet<std::complex<double>, unsigned int>, std::allocator<Eigen::Triplet<std::complex<double>, unsigned int>>>>, SparseMatrixType=Eigen::SparseMatrix<std::complex<double>, 0, int>]" at line 1071
            instantiation of "void Eigen::SparseMatrix<_Scalar, _Options, _Index>::setFromTriplets(const InputIterators &, const InputIterators &) [with _Scalar=std::complex<double>, _Options=0, _Index=int, InputIterators=__gnu_cxx::__normal_iterator<Eigen::Triplet<std::complex<double>, unsigned int> *, std::vector<Eigen::Triplet<std::complex<double>, unsigned int>, std::allocator<Eigen::Triplet<std::complex<double>, unsigned int>>>>]" at line 2525


Unfortunately I could not reproduce the above error with a small example.
What might be causing this compiler error?

Regards
Roman
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS
strange, can you show the code calling setFromTriplet?
-Roman-
Registered Member
Posts
16
Karma
0
I finally found the problem: When I include the header file cppad.hpp (I tested the CppAD library a bit) before including the necessary header files of Eigen, then I get the above error. Changing the order solves the problem. Now the question is whether its a bug in Eigen or CppAD...
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS
hm, cannot reproduce, what's your compiler version?
-Roman-
Registered Member
Posts
16
Karma
0
The following code produces the above error (tested with icc 12.0 and gcc 4.2):

Code: Select all
#include <cppad/cppad.hpp>
#include <Eigen/Eigen>
#include <Eigen/Sparse>

void test1 () {
  typedef Eigen::Triplet <double> TripletS;
  typedef Eigen::SparseMatrix <double> SparseMatrixType;
 
  SparseMatrixType spMat;
 
  int n = 100;
  std::vector<TripletS> coefficients;
 
  spMat.resize (n,n);
  for (int i=0; i<n; ++i) {   
      coefficients.push_back (TripletS (i,i,i*i));
  }
  spMat.setFromTriplets(coefficients.begin(), coefficients.end());
 
}

int main (void)
{   
  test1();
 
  return 0;
}



If I include cppad.hpp after the Eigen headers this compiler error disappears. However, if I then try to use the CppAD library I suddenly get compiler errors, which are not there with the original include order.
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS
cannot reproduce, I have the latest version of cppad (20121016)


Bookmarks



Who is online

Registered users: Bing [Bot], Google [Bot], Yahoo [Bot]