On 11/17/2010 10:47 AM, Christian Gunning wrote: > On Tue, Nov 16, 2010 at 4:00 AM, > <rcpp-devel-requ...@lists.r-forge.r-project.org> wrote: >> for ( y in 1:maxy ) { >> cat(y, " ") >> for (x in 1:maxx) { >> s <- seeds[x:(x+dx2), y:(y+dy2)] >> if (all(is.na(s))) { >> dispSeeds[x,y] <- NA >> } else { >> dispSeeds[x,y] <- fx2(s, s, sd2D) >> } >> } >> } > > If maxy and maxx are large, I'm *guessing* that you could see > significant speed improvements from pushing these inner loops in the > C++ code. Of course, profiling is always a nice way to *see* the > difference!
True - that is what I am duion, and that is the ultimate idea (and I am there): to have all loops in C++. > > Ultimately, you'll want to control the random number seed from within > your C++ function. See previous posts on the mailing list for > examples. Yes - I included that. > > "You attached below a file named disp.cpp, which indicates to me that > your c code is in a separate file - is this the case? And if yes, how > can I do that with the inline command? Or do I have to compile > externally and use Rcpp directly?" > > Honestly, if you plan to develop and use this extensively, make a > package with Rcpp.package.skeleton or RcppArmadillo.package.skeleton, > and drop said file there. Much easier to edit, debug, and ultimately > document. See vignette('Rcpp-package', package='Rcpp') for details. I will - especially as I don't know if there is gcc installed on the cluster - I will see. > > Lastly, > For "s <- seeds[x:(x+dx2), y:(y+dy2)]" : > Look at RcppArmadillo - If you turn seeds into a arma::matrix, you can > use arma's accessors to get native sub-raster access, something like > this, for an Rseeds input matrix to the c++ function: > > NumericMatrix cseeds(Rseeds); > arma::mat aseeds(cseeds.begin(), cseeds.nrow(), cseeds.ncol()); > ... > s = aseeds.submat( x, y, x+dx2, y+dy2 ) > ... > For details, see http://arma.sourceforge.net/docs.html#submat Sounds interesting, and that is exactly what I was looking for initially - but for what I am doing, the code posted by Douglas should be faster, as I have to loop over the matrix anyway, cell by cell. Cheers, Rainer > > best, > Christian, who is finding the Rcpp mailing list this week a > fascinating distraction from comprehensive exams. _______________________________________________ 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