<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40"><head><meta http-equiv=Content-Type content="text/html; charset=us-ascii"><meta name=Generator content="Microsoft Word 12 (filtered medium)"><style><!--
/* Font Definitions */
@font-face
        {font-family:"Cambria Math";
        panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
        {font-family:Tahoma;
        panose-1:2 11 6 4 3 5 4 4 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0in;
        margin-bottom:.0001pt;
        font-size:12.0pt;
        font-family:"Times New Roman","serif";}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:blue;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:purple;
        text-decoration:underline;}
span.hoenzb
        {mso-style-name:hoenzb;}
span.EmailStyle18
        {mso-style-type:personal-reply;
        font-family:"Calibri","sans-serif";
        color:#1F497D;}
.MsoChpDefault
        {mso-style-type:export-only;}
@page WordSection1
        {size:8.5in 11.0in;
        margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
        {page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]--></head><body lang=EN-US link=blue vlink=purple><div class=WordSection1><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>Write it up for Rcpp Gallery.<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'><o:p> </o:p></span></p><p class=MsoNormal><b><span style='font-size:10.0pt;font-family:"Arial","sans-serif";color:#1F497D'>Dale Smith, Ph.D.<o:p></o:p></span></b></p><p class=MsoNormal><span style='font-size:10.0pt;font-family:"Arial","sans-serif";color:#1F497D'>Senior Financial Quantitative Analyst<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:10.0pt;font-family:"Arial","sans-serif";color:#1F497D'>Risk & Compliance<o:p></o:p></span></p><p class=MsoNormal><b><span style='font-size:10.0pt;font-family:"Arial","sans-serif";color:#1F497D'>Fiserv<o:p></o:p></span></b></p><p class=MsoNormal><span style='font-size:10.0pt;font-family:"Arial","sans-serif";color:#1F497D'>Office: 678-375-5315<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'><a href="http://www.fiserv.com/">www.fiserv.com</a></span><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'><o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'><o:p> </o:p></span></p><div style='border:none;border-top:solid #B5C4DF 1.0pt;padding:3.0pt 0in 0in 0in'><p class=MsoNormal><b><span style='font-size:10.0pt;font-family:"Tahoma","sans-serif"'>From:</span></b><span style='font-size:10.0pt;font-family:"Tahoma","sans-serif"'> rcpp-devel-bounces@r-forge.wu-wien.ac.at [mailto:rcpp-devel-bounces@r-forge.wu-wien.ac.at] <b>On Behalf Of </b>Michael Kane<br><b>Sent:</b> Thursday, March 14, 2013 1:19 PM<br><b>To:</b> Dirk Eddelbuettel<br><b>Cc:</b> rcpp-devel@lists.r-forge.r-project.org<br><b>Subject:</b> Re: [Rcpp-devel] Filling a big.matrix in Rcpp<o:p></o:p></span></p></div><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal style='margin-bottom:12.0pt'>OK, I've got it working.<br><br>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.<br><br>require(Rcpp)<br>require(inline)<br>require(bigmemory)<br><br>Sys.setenv(PKG_CPPFLAGS=paste(<br>  paste("-I", system.file(package="bigmemory"), "/include/bigmemory", sep=""),<br>  Sys.getenv("PKG_CPPFLAGS")))<br><br>matFn <- '<br>Rcpp::XPtr<BigMatrix> bigMat(A);<br>MatrixAccessor<int> Am(*bigMat);<br><br>int nrows = bigMat->nrow();<br>int ncolumns = bigMat->ncol();<br>for (int j = 0; j < ncolumns; j++){<br>        for (int i = 1; i < nrows; i++){<br>                Am[j][i] = Am[j][i] + Am[j][i-1];<br>        }<br>}<br>';<br># same function declaration as in example 2.<br>funx <- cxxfunction(signature(A="externalptr"), body=matFn,   plugin = "Rcpp", includes='#include "MatrixAccessor.hpp"')<br><br># set up big.matrix<br>nrows <- 10000<br>bkFile <- "bigmat.bk"<br>descFile <- "bigmatk.desc"<br>suppressMessages(library(bigmemory))<br>bigmat <- filebacked.big.matrix(nrow=nrows, ncol=3,type="integer", init=1,<br>        backingfile=bkFile, backingpath=".",descriptorfile=descFile,<br>        dimnames=c(NULL,NULL))<br>matDesc <- bigmemory::describe(bigmat)<br><br>funx(bigmat@address)<br><br><o:p></o:p></p><div><p class=MsoNormal>On Thu, Mar 14, 2013 at 12:40 PM, Dirk Eddelbuettel <<a href="mailto:edd@debian.org" target="_blank">edd@debian.org</a>> wrote:<o:p></o:p></p><p class=MsoNormal><br>I do not think we have support for bigmemory's big.matrix objects. So you<br>can't just assum it works.<br><br>Contributions welcome.  This is both 'an obvious one' as it would make sense<br>at the C++ and R levels, and something that should not be so hard as we<br>support XPtr.<br><span style='color:#888888'><br><span class=hoenzb>Dirk</span><br><br><span class=hoenzb>--</span><br><span class=hoenzb>Dirk Eddelbuettel | <a href="mailto:edd@debian.org">edd@debian.org</a> | <a href="http://dirk.eddelbuettel.com" target="_blank">http://dirk.eddelbuettel.com</a></span></span><o:p></o:p></p><div><div><p class=MsoNormal>_______________________________________________<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><o:p></o:p></p></div></div></div><p class=MsoNormal><o:p> </o:p></p></div></body></html>