<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=Windows-1252">
</head>
<body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">
<br class="">
<div>
<div class="">On Dec 19, 2014, at 1:17 AM, Braun, Michael &lt;<a href="mailto:braunm@mail.smu.edu" class="">braunm@mail.smu.edu</a>&gt; wrote:</div>
<br class="Apple-interchange-newline">
<div class="">
<div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">
<div class="">Following a suggestion in the Eigen support forum, I created a file eigen_sparse_plugin.h that contains the following:</div>
<div class=""><br class="">
</div>
<div class="">typedef Scalar value_type;</div>
<div class=""><br class="">
</div>
<div class="">
<div class="">template&lt;typename S, int R, int Opt, int MR, int MC&gt;</div>
<div class="">inline void reserve(const Matrix&lt;S,R,Opt,MR,MC&gt; &amp;reserveSizes)</div>
<div class="">{</div>
<div class="">&nbsp; reserveInnerVectors(reserveSizes);</div>
<div class="">}</div>
</div>
<div class=""><br class="">
</div>
<div class="">This now appears to work after adding</div>
<div class=""><br class="">
</div>
<div class="">#define EIGEN_SPARSEMATRIX_PLUGIN &lt;eigen_sparse_plugin.h&gt;&nbsp;</div>
<div class=""><br class="">
</div>
<div class="">before including the Eigen headers.</div>
<div class=""><br class="">
</div>
<div class="">I did see another post on the Eigen mailing list (not the support forum) that suggests a traits-type approach. &nbsp;But maybe the best option would be to convince the Eigen folks to add the template specialization of reserve to the SparseMatrix class.
 &nbsp;That decision is above my level of expertise.</div>
<div class=""><br class="">
</div>
</div>
</div>
<blockquote type="cite" class="">
<div class="">
<div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">
<div class=""><br class="">
</div>
<div class=""><br class="">
</div>
<div class=""><br class="">
<blockquote type="cite" class="">
<div class="">
<div bgcolor="#FFFFFF" text="#000000" class=""><br class="">
<div class="moz-forward-container">-------- Forwarded Message --------
<table class="moz-email-headers-table" border="0" cellpadding="0" cellspacing="0">
<tbody class="">
<tr class="">
<th align="RIGHT" nowrap="nowrap" valign="BASELINE" class="">Subject: </th>
<td class="">Re: [CppAD] filling Eigen sparse matrix in presence of CppAD</td>
</tr>
<tr class="">
<th align="RIGHT" nowrap="nowrap" valign="BASELINE" class="">Date: </th>
<td class="">Thu, 18 Dec 2014 05:25:54 -0700</td>
</tr>
<tr class="">
<th align="RIGHT" nowrap="nowrap" valign="BASELINE" class="">From: </th>
<td class="">Brad Bell <a class="moz-txt-link-rfc2396E" href="mailto:bradbell@seanet.com">
&lt;bradbell@seanet.com&gt;</a></td>
</tr>
<tr class="">
<th align="RIGHT" nowrap="nowrap" valign="BASELINE" class="">To: </th>
<td class=""><a class="moz-txt-link-abbreviated" href="mailto:cppad@list.coin-or.org">cppad@list.coin-or.org</a>, Mic &gt;&gt; Braun, Michael
<a class="moz-txt-link-rfc2396E" href="mailto:braunm@mail.smu.edu">&lt;braunm@mail.smu.edu&gt;</a></td>
</tr>
</tbody>
</table>
<br class="">
<br class="">
<div class="moz-cite-prefix">Using&nbsp; g&#43;&#43; 4.8.3,&nbsp; if you delete<br class="">
&nbsp;&nbsp;&nbsp; typedef Scalar value_type;<br class="">
at line 24 of<br class="">
&nbsp;&nbsp;&nbsp; <a moz-do-not-send="true" class="moz-txt-link-freetext" href="https://projects.coin-or.org/CppAD/browser/trunk/cppad/example/eigen_plugin.hpp">
https://projects.coin-or.org/CppAD/browser/trunk/cppad/example/eigen_plugin.hpp</a><br class="">
the error in compiling the example below goes away.<br class="">
<br class="">
CppAD expects <br class="">
&nbsp;&nbsp;&nbsp; Vector::value_type<br class="">
to be the type of the elements of a vector; see<br class="">
&nbsp;&nbsp;&nbsp; <a moz-do-not-send="true" class="moz-txt-link-freetext" href="http://www.coin-or.org/CppAD/Doc/simplevector.xml#Value%20Type">
http://www.coin-or.org/CppAD/Doc/simplevector.xml#Value%20Type</a><br class="">
<br class="">
This is the same as for the C&#43;&#43; standard vector; as can be seen by searching for value_type on<br class="">
&nbsp;&nbsp;&nbsp; <a moz-do-not-send="true" class="moz-txt-link-freetext" href="http://www.cplusplus.com/reference/vector/vector/">
http://www.cplusplus.com/reference/vector/vector/</a><br class="">
<br class="">
I wanted to ask about this on the eigen user's list<br class="">
&nbsp;&nbsp;&nbsp; <a moz-do-not-send="true" class="moz-txt-link-freetext" href="http://listengine.tuxfamily.org/lists.tuxfamily.org/eigen/2014/12/maillist.html">
http://listengine.tuxfamily.org/lists.tuxfamily.org/eigen/2014/12/maillist.html</a><br class="">
but I did not see your posting there.<br class="">
<br class="">
Brad<br class="">
<br class="">
<br class="">
On 12/17/2014 11:33 AM, Braun, Michael wrote:<br class="">
</div>
<blockquote cite="mid:C1E0B23C-F1A1-4C5B-9647-1FEBDEE26E44@smu.edu" type="cite" class="">
<meta http-equiv="Context-Type" content="text/html;
          charset=us-ascii" class="">
<div class="">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.</div>
<div class=""><br class="">
</div>
<div class="">As part of a larger application that uses CppAD, I am trying to fill an Eigen sparse matrix. &nbsp;The following MWE does not use CppAD, and when the first line (#define EIGEN_MATRIX_PLUGIN ... ) is commented out, this code runs fine. &nbsp;</div>
<div class=""><br class="">
</div>
<div class="">
<div class="">
<div class="">#define EIGEN_MATRIX_PLUGIN &lt;cppad/example/eigen_plugin.hpp&gt;</div>
<div class=""><br class="">
</div>
<div class="">#include &lt;Eigen/Eigen&gt;</div>
<div class="">#include &lt;Eigen/Sparse&gt;</div>
<div class="">#include &lt;cppad/cppad.hpp&gt;</div>
<div class="">#include &lt;cppad/example/cppad_eigen.hpp&gt;</div>
<div class=""><br class="">
</div>
<div class="">void triptest () {</div>
<div class="">&nbsp; typedef Eigen::Triplet&lt;double&gt; TT;</div>
<div class=""><br class="">
</div>
<div class="">&nbsp; int n = 5;</div>
<div class="">&nbsp; std::vector&lt;TT&gt; trips;&nbsp;</div>
<div class="">&nbsp; Eigen::SparseMatrix&lt;double&gt; M(n,n);</div>
<div class="">&nbsp;&nbsp;</div>
<div class="">&nbsp; for (int i=0; i&lt;n; i&#43;&#43;) { &nbsp;&nbsp;</div>
<div class="">&nbsp; &nbsp; trips.push_back (TT(i,i,i*i));</div>
<div class="">&nbsp; }</div>
<div class="">&nbsp; M.setFromTriplets(trips.begin(), trips.end());</div>
<div class="">&nbsp; std::cout &lt;&lt; M &lt;&lt; &quot;\n&quot;;</div>
<div class="">&nbsp;&nbsp;</div>
<div class="">}</div>
<div class=""><br class="">
</div>
<div class="">int main (void)</div>
<div class="">{ &nbsp;&nbsp;</div>
<div class="">&nbsp; triptest();</div>
<div class="">&nbsp; return 0;</div>
<div class="">}</div>
</div>
</div>
<div class=""><br class="">
</div>
<div class=""><br class="">
</div>
<div class="">But when left in, I get the following compile error:</div>
<div class=""><br class="">
</div>
<div class="">
<div class="">&nbsp;$ clang&#43;&#43; -I/opt/cppad/include -I$R_HOME/library/RcppEigen/include trips.cpp -o trips.so</div>
<div class="">In file included from trips.cpp:4:</div>
<div class="">In file included from .../Eigen/Sparse:19:</div>
<div class="">In file included from .../Eigen/SparseCore:40:</div>
<div class=""><b class="">/Library/Frameworks/R.framework/Resources/library/RcppEigen/include/Eigen/src/SparseCore/SparseMatrix.h:957:11:
</b><span class=""><b class="">error:&nbsp;</b></span></div>
<div class=""><b class="">&nbsp; &nbsp; &nbsp; call to member function 'reserve' is ambiguous</b></div>
<div class="">&nbsp; &nbsp; trMat.reserve(wi);</div>
<div class=""><b class="">&nbsp; &nbsp; ~~~~~~^~~~~~~</b></div>
<div class=""><b class="">.../Eigen/src/SparseCore/SparseMatrix.h:1013:13: note:&nbsp;</b></div>
<div class="">&nbsp; &nbsp; &nbsp; in instantiation of function template specialization</div>
<div class="">&nbsp; &nbsp; &nbsp; 'Eigen::internal::set_from_triplets&lt;std::__1::__wrap_iter&lt;Eigen::Triplet&lt;double, int&gt; *&gt;,</div>
<div class="">&nbsp; &nbsp; &nbsp; Eigen::SparseMatrix&lt;double, 0, int&gt; &gt;' requested here</div>
<div class="">&nbsp; internal::set_from_triplets(begin, end, *this);</div>
<div class=""><b class="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ^</b></div>
<div class=""><b class="">trips.cpp:18:5: note: </b>in instantiation of function template specialization 'Eigen::SparseMatrix&lt;double, 0,</div>
<div class="">&nbsp; &nbsp; &nbsp; int&gt;::setFromTriplets&lt;std::__1::__wrap_iter&lt;Eigen::Triplet&lt;double, int&gt; *&gt; &gt;' requested here</div>
<div class="">&nbsp; M.setFromTriplets(trips.begin(), trips.end());</div>
<div class=""><b class="">&nbsp; &nbsp; ^</b></div>
<div class=""><b class="">.../Eigen/src/SparseCore/SparseMatrix.h:270:17: note:&nbsp;</b></div>
<div class="">&nbsp; &nbsp; &nbsp; candidate function [with SizesType = Eigen::Matrix&lt;int, -1, 1, 0, -1, 1&gt;]</div>
<div class="">&nbsp; &nbsp; inline void reserve(const SizesType&amp; reserveSizes, const typename SizesType::value_type&amp; enableif = typenam...</div>
<div class=""><b class="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ^</b></div>
<div class=""><b class="">.../Eigen/src/SparseCore/SparseMatrix.h:276:17: note:&nbsp;</b></div>
<div class="">&nbsp; &nbsp; &nbsp; candidate function [with SizesType = Eigen::Matrix&lt;int, -1, 1, 0, -1, 1&gt;]</div>
<div class="">&nbsp; &nbsp; inline void reserve(const SizesType&amp; reserveSizes, const typename SizesType::Scalar&amp; enableif =</div>
<div class=""><b class="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ^</b></div>
<div class=""><b class="">.../Eigen/src/SparseCore/SparseMatrix.h:256:17: note:&nbsp;</b></div>
<div class="">&nbsp; &nbsp; &nbsp; candidate function not viable: no known conversion from 'Matrix&lt;Index, Dynamic, 1&gt;' to 'Index' (aka 'int') for 1st</div>
<div class="">&nbsp; &nbsp; &nbsp; argument</div>
<div class="">&nbsp; &nbsp; inline void reserve(Index reserveSize)</div>
<div class=""><b class="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ^</b></div>
</div>
<div class=""><b class=""><br class="">
</b></div>
<div class=""><br class="">
</div>
<div class="">Any idea what's going on? &nbsp;I have been able to narrow the problem directly to that first #define. &nbsp;Also, this appears to happen only with EIGEN_MATRIX_PLUGIN, and not ARRAY or SPARSEMATRIX.</div>
<div class=""><br class="">
</div>
<div class="">Thanks,</div>
<div class=""><br class="">
</div>
<div class="">Michael</div>
<div class=""><br class="">
</div>
<div class=""><br class="">
</div>
<div class=""><br class="">
</div>
<br class="">
<div class="">
<div class="">--------------------------</div>
<div class="">Michael Braun</div>
<div class="">Associate Professor of Marketing</div>
<div class="">Cox School of Business</div>
<div class="">Southern Methodist University</div>
<div class="">Dallas, TX 75275</div>
<div class=""><a moz-do-not-send="true" href="mailto:braunm@smu.edu" class="">braunm@smu.edu</a></div>
<div class=""><br class="">
</div>
<br class="Apple-interchange-newline">
</div>
<br class="">
<br class="">
<fieldset class="mimeAttachmentHeader"></fieldset> <br class="">
<pre wrap="" class="">_______________________________________________
CppAD mailing list
<a moz-do-not-send="true" class="moz-txt-link-abbreviated" href="mailto:CppAD@list.coin-or.org">CppAD@list.coin-or.org</a>
<a moz-do-not-send="true" class="moz-txt-link-freetext" href="http://list.coin-or.org/mailman/listinfo/cppad">http://list.coin-or.org/mailman/listinfo/cppad</a>
</pre>
</blockquote>
<br class="">
<br class="">
</div>
<br class="">
</div>
</div>
</blockquote>
</div>
<br class="">
<div apple-content-edited="true" class="">--------------------------------------------<br class="">
Michael Braun, Ph.D.<br class="">
Associate Professor of Marketing<br class="">
Cox School of Business<br class="">
Southern Methodist University<br class="">
<a href="mailto:braunm@smu.edu" class="">braunm@smu.edu</a><br class="">
<br class="">
</div>
<br class="">
</div>
</div>
</blockquote>
</div>
<br class="">
<div apple-content-edited="true" class="">
<div class="">--------------------------</div>
<div class="">Michael Braun</div>
<div class="">Associate Professor of Marketing</div>
<div class="">Cox School of Business</div>
<div class="">Southern Methodist University</div>
<div class="">Dallas, TX 75275</div>
<div class=""><a href="mailto:braunm@smu.edu" class="">braunm@smu.edu</a></div>
<div class=""><br class="">
</div>
<br class="Apple-interchange-newline">
</div>
<br class="">
</body>
</html>