<div dir="ltr">Hi Ale,<div><br></div><div> maybe I'm wrong but <span style="font-family:arial,sans-serif;font-size:13px">mat(0,_) is not a NumericVector, but a </span><span style="font-family:arial,sans-serif;font-size:13px">Rcpp::MatrixRow.</span></div>
<div><span style="font-family:arial,sans-serif;font-size:13px">So your function sum() is being called with arguments of the wront type (the error</span></div><div><span style="font-family:arial,sans-serif;font-size:13px">message is saying that).</span></div>
<div><span style="font-family:arial,sans-serif;font-size:13px"><br></span></div><div><span style="font-size:13px;font-family:arial,sans-serif">If instead you select a column </span><span style="font-size:13px;font-family:arial,sans-serif">mat( _, 0) you have a conversion to a NumericVector.</span></div>
<div><span style="font-size:13px;font-family:arial,sans-serif">I've encountered the same issue a couple of time.</span></div><div><span style="font-size:13px;font-family:arial,sans-serif"><br></span></div><div><span style="font-size:13px;font-family:arial,sans-serif">Matteo</span></div>
</div><div class="gmail_extra"><br><br><div class="gmail_quote">On Mon, Oct 14, 2013 at 8:21 PM, Alessandro Mammana <span dir="ltr"><<a href="mailto:mammana@molgen.mpg.de" target="_blank">mammana@molgen.mpg.de</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi all,<br>
I have very little experience with Rcpp and also with c++, so I am<br>
sorry if my question might be too stupid.<br>
I am trying to use iterators in my code, because I understand them<br>
better than vectors, because they should be efficient, and because I<br>
should be able to combine different implementations of vector and<br>
matrix classes. However the following code does not compile:<br>
<br>
#include <Rcpp.h><br>
using namespace Rcpp;<br>
<br>
typedef NumericVector::iterator DoubleIter;<br>
<br>
double sum(DoubleIter b, DoubleIter e){<br>
double sum = 0;<br>
while (b!=e){<br>
sum += *(b++);<br>
}<br>
return sum;<br>
}<br>
<br>
// [[Rcpp::export]]<br>
double sumFirstRow(NumericMatrix mat){<br>
return sum(mat(0,_).begin(), mat(0,_).end());<br>
}<br>
<br>
The error message is not very useful (or at least I cannot interpret it):<br>
<br>
In function 'double sumFirstRow(Rcpp::NumericMatrix)':<br>
error: no matching function for call to<br>
'sum(Rcpp::MatrixRow<14>::iterator, Rcpp::MatrixRow<14>::iterator)'<br>
note: candidates are:<br>
note: double sum(DoubleIter, DoubleIter)<br>
note: no known conversion for argument 1 from<br>
'Rcpp::MatrixRow<14>::iterator' to 'DoubleIter {aka double*}'<br>
<br>
Am I missing something very basic?<br>
Thanks a lot!<br>
Ale<br>
_______________________________________________<br>
Rcpp-devel mailing list<br>
<a href="mailto:Rcpp-devel@lists.r-forge.r-project.org">Rcpp-devel@lists.r-forge.r-project.org</a><br>
<a href="https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel" target="_blank">https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel</a><br>
</blockquote></div><br></div>