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

Conflict between setFromTriplets and CppAD

Tags: None
(comma "," separated)
mb92
Registered Member
Posts
2
Karma
0
As part of an application that uses CppAD for automatic differentiation, I am trying to fill a sparse matrix using setFrom Triplets. The example below compiles and runs fine when the first line (#define EIGEN_MATRIX_PLUGIN ...) is removed. But when it's in, I get

.../Eigen/src/SparseCore/SparseMatrix.h:957:11: error:
call to member function 'reserve' is ambiguous
trMat.reserve(wi);

CppAD is not needed for this MWE, but it is for the real application. The thing is that I don't know if this is an Eigen issue or a CppAD issue. So I'm posting to the CppAD mailing list as well.

Any idea of what's going on?

Thanks.

Code: Select all
// compiles and runs when next line is commented out
#define EIGEN_MATRIX_PLUGIN <cppad/example/eigen_plugin.hpp>

#include <Eigen/Eigen>
#include <Eigen/Sparse>
#include <cppad/cppad.hpp>
#include <cppad/example/cppad_eigen.hpp>

void triptest () {
  typedef Eigen::Triplet<double> TT;
  int n = 5;
  std::vector<TT> trips;
  Eigen::SparseMatrix<double> M(n,n);
  for (int i=0; i<n; i++) {   
    trips.push_back (TT(i,i,i*i));
  }
  M.setFromTriplets(trips.begin(), trips.end());
  std::cout << M << "\n";
}

int main (void)
{   
  triptest();
  return 0;
}
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS
You can probably fix it on your side by adding a plugin for SparseMatrix too:

#define EIGEN_SPARSEMATRIX_PLUGIN eigen_sparse_plugin.h

with eigen_sparse_plugin.h as:
Code: Select all
template<typename S, int R, int C, int Opt, int MR, int MC>
void reserve(const Matrix<S,R,Opt,MR,MC> &reserveSizes)
{
    reserveInnerVectors(reserveSizes);
}


(not tested so be careful with possible typos)
mb92
Registered Member
Posts
2
Karma
0
Thanks. There was indeed a typo in that code (too many template arguments). I added the following to eigen_sparse_plugin.h, and everything appears to work.

Any way this could be added to the file in the next release?

Code: Select all
template<typename S, int R, int Opt, int MR, int MC>
inline void reserve(const Matrix<S,R,Opt,MR,MC> &reserveSizes)
{
  reserveInnerVectors(reserveSizes);
}


Bookmarks



Who is online

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