Write it up for Rcpp Gallery.

 

Dale Smith, Ph.D.

Senior Financial Quantitative Analyst

Risk & Compliance

Fiserv

Office: 678-375-5315

www.fiserv.com <http://www.fiserv.com/> 

 

From: [email protected]
[mailto:[email protected]] On Behalf Of Michael
Kane
Sent: Thursday, March 14, 2013 1:19 PM
To: Dirk Eddelbuettel
Cc: [email protected]
Subject: Re: [Rcpp-devel] Filling a big.matrix in Rcpp

 

OK, I've got it working.

You need to add the bigmemory inst directory to the PKG_CPPFLAGS,
include MatrixAccessor.hpp, and pass the pointer to the BigMatrix object
to your function. The following code should do the trick but note that
it does not create a new big.matrix object it simply modifies the
big.matrix object that is passed to your function.

require(Rcpp)
require(inline)
require(bigmemory)

Sys.setenv(PKG_CPPFLAGS=paste(
  paste("-I", system.file(package="bigmemory"), "/include/bigmemory",
sep=""),
  Sys.getenv("PKG_CPPFLAGS")))

matFn <- '
Rcpp::XPtr<BigMatrix> bigMat(A);
MatrixAccessor<int> 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[j][i] = Am[j][i] + Am[j][i-1];
        }
}
';
# same function declaration as in example 2.
funx <- cxxfunction(signature(A="externalptr"), body=matFn,   plugin =
"Rcpp", includes='#include "MatrixAccessor.hpp"')

# 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)

funx(bigmat@address)



On Thu, Mar 14, 2013 at 12:40 PM, Dirk Eddelbuettel <[email protected]>
wrote:


I do not think we have support for bigmemory's big.matrix objects. So
you
can't just assum it works.

Contributions welcome.  This is both 'an obvious one' as it would make
sense
at the C++ and R levels, and something that should not be so hard as we
support XPtr.

Dirk

--
Dirk Eddelbuettel | [email protected] | http://dirk.eddelbuettel.com

_______________________________________________
Rcpp-devel mailing list
[email protected]
https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel

 

_______________________________________________
Rcpp-devel mailing list
[email protected]
https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel

Reply via email to