Skip to content
Prev 5487 / 10988 Next

[Rcpp-devel] Filling a big.matrix in Rcpp

Shradda,

A big.matrix is not a regular R matrix. It is a completely separate type.
The definition can be found in BigMatrix.h. I've rewritten your C++ code
but there is still a problem. To build the function the compiler needs to
know where the bigmemory header files are. Basically, you need to #include
"MatrixAccessor". I'm not sure how to do this but it is almost certainly
somewhere in the documentation or maybe someone else on the list will nice
enough to give you a pointer.

Thanks,
Mike

matFn <- '
Rcpp::XPtr<BigMatrix*> bigMat(A);
MatrixAccessor Am(bigMat);

int nrows = bigMat.nrow();
int ncolumns = bigMat.ncol();
for (int j = 0; j < ncolumns; j++){
        for (int i = 1; i < nrows; i++){
                Am[i,j] = Am[i,j] + Am[i-1,j];
        }
}
return A;
';
# same function declaration as in example 2.
funx <- cxxfunction(signature(A="externalptr"), body=matFn,
  plugin = "Rcpp")

# set up big.matrix
nrows <- 10000
bkFile <- "bigmat.bk"
descFile <- "bigmatk.desc"
suppressMessages(library(bigmemory))
bigmat <- filebacked.big.matrix(nrow=nrows, ncol=3,type="integer", init=1,
        backingfile=bkFile, backingpath=".",descriptorfile=descFile,
        dimnames=c(NULL,NULL))
matDesc <- bigmemory::describe(bigmat)

bigmat2 <- funx(matDesc)
On Thu, Mar 14, 2013 at 11:57 AM, Shraddha Pai <Shraddha.Pai at camh.ca> wrote:

            
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.r-forge.r-project.org/pipermail/rcpp-devel/attachments/20130314/b0e91d57/attachment.html>