[CppAD] filling Eigen sparse matrix in presence of CppAD
Braun, Michael
braunm at mail.smu.edu
Wed Dec 17 13:33:37 EST 2014
I posted this same question on the Eigen forum because I do not know if it is really an Eigen issue or a CppAD issue.
As part of a larger application that uses CppAD, I am trying to fill an Eigen sparse matrix. The following MWE does not use CppAD, and when the first line (#define EIGEN_MATRIX_PLUGIN ... ) is commented out, this code runs fine.
#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;
}
But when left in, I get the following compile error:
$ clang++ -I/opt/cppad/include -I$R_HOME/library/RcppEigen/include trips.cpp -o trips.so
In file included from trips.cpp:4:
In file included from .../Eigen/Sparse:19:
In file included from .../Eigen/SparseCore:40:
/Library/Frameworks/R.framework/Resources/library/RcppEigen/include/Eigen/src/SparseCore/SparseMatrix.h:957:11: error:
call to member function 'reserve' is ambiguous
trMat.reserve(wi);
~~~~~~^~~~~~~
.../Eigen/src/SparseCore/SparseMatrix.h:1013:13: note:
in instantiation of function template specialization
'Eigen::internal::set_from_triplets<std::__1::__wrap_iter<Eigen::Triplet<double, int> *>,
Eigen::SparseMatrix<double, 0, int> >' requested here
internal::set_from_triplets(begin, end, *this);
^
trips.cpp:18:5: note: in instantiation of function template specialization 'Eigen::SparseMatrix<double, 0,
int>::setFromTriplets<std::__1::__wrap_iter<Eigen::Triplet<double, int> *> >' requested here
M.setFromTriplets(trips.begin(), trips.end());
^
.../Eigen/src/SparseCore/SparseMatrix.h:270:17: note:
candidate function [with SizesType = Eigen::Matrix<int, -1, 1, 0, -1, 1>]
inline void reserve(const SizesType& reserveSizes, const typename SizesType::value_type& enableif = typenam...
^
.../Eigen/src/SparseCore/SparseMatrix.h:276:17: note:
candidate function [with SizesType = Eigen::Matrix<int, -1, 1, 0, -1, 1>]
inline void reserve(const SizesType& reserveSizes, const typename SizesType::Scalar& enableif =
^
.../Eigen/src/SparseCore/SparseMatrix.h:256:17: note:
candidate function not viable: no known conversion from 'Matrix<Index, Dynamic, 1>' to 'Index' (aka 'int') for 1st
argument
inline void reserve(Index reserveSize)
^
Any idea what's going on? I have been able to narrow the problem directly to that first #define. Also, this appears to happen only with EIGEN_MATRIX_PLUGIN, and not ARRAY or SPARSEMATRIX.
Thanks,
Michael
--------------------------
Michael Braun
Associate Professor of Marketing
Cox School of Business
Southern Methodist University
Dallas, TX 75275
braunm at smu.edu<mailto:braunm at smu.edu>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://list.coin-or.org/pipermail/cppad/attachments/20141217/697a8947/attachment.html>
More information about the CppAD
mailing list