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