[eigen] Conflict between coeffRef and CppAD
• To: eigen@xxxxxxxxxxxxxxxxxxx
• Subject: [eigen] Conflict between coeffRef and CppAD
• From: Hilario Tomé <tome.hilario@xxxxxxxxx>
• Date: Fri, 10 Apr 2015 13:47:18 +0200
• Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:from:date:message-id:subject:to:content-type; bh=gzeKWfjXSFyPoEN0lgUHSO5QcOYy6TosXOYtso4n1MU=; b=beWgnlDIR662ZH2PYjhOe8Ej8Hetkl02mV1SQo9F0GsipetvBcrAA7V1/rFm8D7bxe hDrxSLI6tNwu2VV+Xh5fKVQgZ2rju85Sqwl//0KrFrpsWbuyMsGcYdrLe+zN/jzwtGHN /Rqil2G1TuHS1IeD8D1Qksq+/2TkmSQ1UYooemgz7g6V4Q0+C5BC7NVFVm1JrKxPABaA g21LtBUwH1shL0WKIFbh47h2yUFIj3w3ZUUkurgL3SZKuVS7XWmAes/N1hGpJAY+yp0c 5/So8HJx5HOiodHy4dNGligo/cOa6Sl/U7LcNUTrDCAlio7t1+W/JILRRSBkepd+oQWI ss+A==

Dear all,

I have a problem when using CppAD for auto differentiation and sparse matrices from Eigen. I get a compilation error when trying to use coeffRef, the following example reproduces the problem

#include <Eigen/Sparse>

int main(){

Eigen::SparseMatrix<double> mat(3, 3);

for(size_t i=0; i<3; ++i){
mat.coeffRef(i,i) = 1.0;
}

}

In file included from ../include/Eigen/Eigen/SparseCore:40:0,
from ../include/Eigen/Eigen/Sparse:19,
../include/Eigen/Eigen/src/SparseCore/SparseMatrix.h: In member function ‘Eigen::SparseMatrix<_Scalar, _Flags, _Index>::Scalar& Eigen::SparseMatrix<_Scalar, _Flags, _Index>::insert(Eigen::SparseMatrix<_Scalar, _Flags, _Index>::Index, Eigen::SparseMatrix<_Scalar, _Flags, _Index>::Index) [with _Scalar = double, int _Options = 0, _Index = int, Eigen::SparseMatrix<_Scalar, _Flags, _Index>::Scalar = double, Eigen::SparseMatrix<_Scalar, _Flags, _Index>::Index = int]’:
../include/Eigen/Eigen/src/SparseCore/SparseMatrix.h:200:30:   instantiated from ‘Eigen::SparseMatrix<_Scalar, _Flags, _Index>::Scalar& Eigen::SparseMatrix<_Scalar, _Flags, _Index>::coeffRef(Eigen::SparseMatrix<_Scalar, _Flags, _Index>::Index, Eigen::SparseMatrix<_Scalar, _Flags, _Index>::Index) [with _Scalar = double, int _Options = 0, _Index = int, Eigen::SparseMatrix<_Scalar, _Flags, _Index>::Scalar = double, Eigen::SparseMatrix<_Scalar, _Flags, _Index>::Index = int]’
../include/Eigen/Eigen/src/SparseCore/SparseMatrix.h:226:9: error: call of overloaded ‘reserve(const ConstantReturnType)’ is ambiguous
.../include/Eigen/Eigen/src/SparseCore/SparseMatrix.h:226:9: note: candidates are:
../include/Eigen/Eigen/src/SparseCore/SparseMatrix.h:270:17: note: void Eigen::SparseMatrix<_Scalar, _Flags, _Index>::reserve(const SizesType&, const typename SizesType::value_type&) [with SizesType = Eigen::CwiseNullaryOp<Eigen::internal::scalar_constant_op<int>, Eigen::Matrix<int, -0x00000000000000001, 1> >, _Scalar = double, int _Options = 0, _Index = int, typename SizesType::value_type = int]
../include/Eigen/Eigen/src/SparseCore/SparseMatrix.h:276:17: note: void Eigen::SparseMatrix<_Scalar, _Flags, _Index>::reserve(const SizesType&, const typename SizesType::Scalar&) [with SizesType = Eigen::CwiseNullaryOp<Eigen::internal::scalar_constant_op<int>, Eigen::Matrix<int, -0x00000000000000001, 1> >, _Scalar = double, int _Options = 0, _Index = int, typename SizesType::Scalar = int]

There is already a similar forum post that has been solved:
https://forum.kde.org/viewtopic.php?f=74&t=124099

The eigen sparse plugin that Gael suggests fixes the problem with setFromTriplets, but the problem appears again when using coeffRef.