I am not exactly sure why that works, but it does! Why doesn't it directly see the NumericMatrix(SEXP)?<br><br>Thank you, Dirk!<br><br><div class="gmail_quote">On Fri, Feb 10, 2012 at 3:10 PM, Dirk Eddelbuettel <span dir="ltr"><<a href="mailto:edd@debian.org">edd@debian.org</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="HOEnZb"><div class="h5"><br>
On 10 February 2012 at 14:49, Sameer Soi wrote:<br>
| Hello Rcpp'ers,<br>
|<br>
| I want to access a List of matrices in an Rcpp/C++ function that will passed to<br>
| me via R...<br>
|<br>
| src <- "<br>
| using namespace Rcpp ;<br>
| List inputList(L) ;<br>
| NumericMatrix tmpMatrix ;<br>
|<br>
| tmpMatrix = NumericMatrix(inputList[0]) ;<br>
| return(wrap(tmpMatrix.ncol())) ;<br>
| "<br>
| test <- cxxfunction(signature(L="list"), src, plugin = "Rcpp" )<br>
|<br>
| This gives me the following error-<br>
|<br>
| file30b9664194fc.cpp: In function ‘SEXPREC* file30b9664194fc(SEXPREC*)’:<br>
| file30b9664194fc.cpp:34: error: call of overloaded ‘Matrix<br>
| (Rcpp::internal::generic_proxy<19>)’ is ambiguous<br>
| /usr/share/R/include/Rcpp/vector/SubMatrix.h:57: note: candidates are:<br>
| Rcpp::Matrix<RTYPE>::Matrix(const Rcpp::SubMatrix<RTYPE>&) [with int RTYPE =<br>
| 14]<br>
| /usr/share/R/include/Rcpp/vector/Matrix.h:67:<br>
| note: Rcpp::Matrix<RTYPE>::Matrix(const<br>
| Rcpp::Matrix<RTYPE>&) [with int RTYPE = 14]<br>
| /usr/share/R/include/Rcpp/vector/Matrix.h:65:<br>
| note: Rcpp::Matrix<RTYPE>::Matrix(const int&)<br>
| [with int RTYPE = 14]<br>
| /usr/share/R/include/Rcpp/vector/Matrix.h:46:<br>
| note: Rcpp::Matrix<RTYPE>::Matrix(const<br>
| Rcpp::Dimension&) [with int RTYPE = 14]<br>
| /usr/share/R/include/Rcpp/vector/Matrix.h:39:<br>
| note: Rcpp::Matrix<RTYPE>::Matrix(SEXPREC*)<br>
| [with int RTYPE = 14]<br>
| make: *** [file30b9664194fc.o] Error 1<br>
|<br>
| In looking at the error, it's not clear to me how these candidates will help.<br>
| What am I missing in telling Rcpp what class of object it should be expecting<br>
| coming out of inputList?<br>
<br>
</div></div>Template code gets complicate. The subsetting (of the List) confuses here.<br>
And one more statement and all is well -- you were very close!<br>
<br>
R> library(inline)<br>
R> src <- '<br>
+ Rcpp::List inputList(L) ;<br>
+ Rcpp::NumericMatrix tmpMatrix ;<br>
+ SEXP tmp = inputList[0];<br>
+ tmpMatrix = Rcpp::NumericMatrix(tmp) ;<br>
+ return(wrap(tmpMatrix.ncol())) ;<br>
+ '<br>
R> f <- cxxfunction(signature(L="list"), src, plugin = "Rcpp" )<br>
R> f(list(matrix(1:9,3,3)))<br>
[1] 3<br>
R><br>
<br>
<br>
Hope this helps, Dirk<br>
<div class="im"><br>
|<br>
| I know this kind of question (i.e. I want a 3d cube etc) pops up frequently and<br>
| the answer is typically "use arma's 3d cubes" (e.g. <a href="http://stackoverflow.com/" target="_blank">http://stackoverflow.com/</a><br>
| questions/8159872/r-list-of-numeric-vectors-c-2d-array-with-rcpp), but I don't<br>
| intend on doing linear algebra. My data really is just a series of matrices of<br>
| arbitrary sizes.<br>
|<br>
| Also, I looked into multi-dimensional arrays, but how to access them seems<br>
| unclear; I did see a post on this list to that nature but the solution seemed<br>
| inelegant.<br>
|<br>
| Thanks in advance for any help!<br>
|<br>
</div>| ----------------------------------------------------------------------<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>
<span class="HOEnZb"><font color="#888888">--<br>
"Outside of a dog, a book is a man's best friend. Inside of a dog, it is too<br>
dark to read." -- Groucho Marx<br>
</font></span></blockquote></div><br><br clear="all"><br>-- <br>Sameer Soi<br><br>w: 215.746.2683 | c: 814.241.8585<br>