<br><br><div class="gmail_quote">---------- Forwarded message ----------<br>From: <b class="gmail_sendername">Thell Fowler</b> <span dir="ltr"><<a href="mailto:tbfowler4@gmail.com">tbfowler4@gmail.com</a>></span><br>
Date: Sun, Nov 18, 2012 at 3:03 PM<br>Subject: Re: [Rcpp-devel] Rcpp RMpfr mpreal to mpfr wrapping<br>To: Dirk Eddelbuettel <<a href="mailto:edd@debian.org">edd@debian.org</a>><br><br><br><br><div class="gmail_extra">
<br><br><div class="gmail_quote"><div class="im">On Sun, Nov 18, 2012 at 1:59 PM, Dirk Eddelbuettel <span dir="ltr"><<a href="mailto:edd@debian.org" target="_blank">edd@debian.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
<br>
Hi Thell,<br>
<div><br>
On 18 November 2012 at 13:03, Thell Fowler wrote:<br>
| Hi all.<br>
|<br>
| I've been doing some testing on how to get arbitrary precision numbers out of<br>
| c++ and into R. The following example inline Rcpp code generates an RcppMpfr<br>
| cxxfunction plugin for wrapping <mpreal> to the Rmpfr S4 "mpfr1" object.<br>
<br>
</div>Nice.<br>
<div><br>
| There are local include paths that need adjusting (for now) to your<br>
| environment, and the mpreal header only c++ wrapper for mpfr ( http://<br>
| <a href="http://www.holoborodko.com/pavel/mpfr/" target="_blank">www.holoborodko.com/pavel/mpfr/</a> ). I'll be making this into a package but<br>
| wanted to ask about how to do something first...<br>
<br>
</div>Just so that I understand: that is another C++ layer on top of GNU mpfr ?<br>
Yet you do link with -lmpfr below...<br>
<div><br></div></blockquote></div><div>Yes, mpreal is a nice c++ class wrapper for working with mpfr, so all the c++ goodness can simply be used.</div><div class="im"><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
<div>
| Rmpfr defines 'mpfr1' and 'mpfr' where 'mpfr' is usable within R and is a list<br>
| type containing 'mpfr1' objects. So the Rcpp::wrap is setup to get and<br>
| populate an S4 "mpfr1" object, but to be usable on the R side the S4 "mpfr"<br>
| needs to be used. I can get and populate the ".Data" field in the<br>
| mpfr::mpreal wrapper using Rcpp::List but was wondering if the Rcpp::wrap could<br>
| be setup to capture an S4 class type.<br>
<br>
</div>"I guess so".<br>
<br>
I haven't tried. We do get the whole SEXP, and we have some code to access<br>
and set S4 slots.<br>
<div><div><br></div></div></blockquote></div><div>When you say we get the whole SEXP and can 'access' it, that doesn't mean we can setup a template type against it for 'wrap' and 'as' though; right? If so, can you think of a reference for me?</div>
<div><br></div><div>--- >8 ---</div><div class="im"><div> <br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
<div>
<div>
| I'd like to have wrap<mpfr::mpreal> wrap to an 'mpfr1' and wrap<S4<mpfr1>><br>
| (imagined def) wrap to an mpfr list.<br>
|<br></div></div></blockquote><div> </div></div><div> --- >8 ---</div><div class="im"><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
<div><div>
| #### Plugin Definition ####<br>
| RcppMpfr <- function()<br>
| {<br>
| plugin <- Rcpp:::Rcpp.plugin.maker(<br>
| include.before= include.before,<br>
| include.after= include.after,<br>
| LinkingTo=c('Rmpfr',"Rcpp"),<br>
<br>
</div></div>I don't see Rmpfr exporting header files, so not sure if you need Rmpfr here?<br>
<div><br></div></blockquote></div><div>Yes, not needed... a remnant from attempting to use Rmpfr's MPFR_as_R routine.</div><div class="im"><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
<div>
| libs="-Lc:/RtoolsLocal/R-2.15.0/lib/i386 -lmpfr -lgmp" )<br>
| settings <- plugin()<br>
| settings$env$PKG_CPPFLAGS=paste(<br>
| "-std=c++0x",<br>
| "-Ic:/users/almostautomated/src/RcppMpfr++/mpreal/inst/include",<br>
<br>
</div>You can probably make that local to your package if you keep it in RcppMpfr++/inst/include/...<br>
<br>
Or is this another package? I'm lost here....<br>
<br></blockquote></div><div>Yeah, it's a bit of a mish-mash right now, but the aim is an RcppMpfr++ package so it'll be local to the package when in installed and not declared here. I'm getting into gmp a bit too, so passing those types might end up being nice too. Then there is iRRAM which I am itching to try. :) The list goes on.</div>
<div class="im">
<div><br></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
| "-Ic:/RtoolsLocal/R-2.15.0/include" )<br>
<br>
R will already provide this.<br>
<br></blockquote></div><div>Nice! Odd that the -L path isn't provided as well...</div><div class="im"><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
Looks good. I am not quite sure what your question is, though. Your proof of<br>
concept seems to working, so why not build a package ?<br>
<br>
Dirk<br>
<br></blockquote></div><div>Yep the POC looks good so far, I'm _very_ pleased with the timing results. The actual question is _how_ to template the wrapping of an <mpfr1> to <mpfr>. Right now each individial <mpfr1> is wrapped to an individual <mpfr> which is wrong as an <mpfr> is an actual list of <mpfr1> objects in "R", yet as soon as the Rcpp::wrap<mpreal> is called I don't see how to state the <T> of the SEXP.</div>
<div class="im">
<div> <br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
|<br>
| Sincerely,<br>
| Thell<br>
|<br>
| ----------------------------------------------------------------------<br>
| _______________________________________________<br>
| Rcpp-devel mailing list<br>
| <a href="mailto:Rcpp-devel@lists.r-forge.r-project.org" target="_blank">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><font color="#888888">--<br>
Dirk Eddelbuettel | <a href="mailto:edd@debian.org" target="_blank">edd@debian.org</a> | <a href="http://dirk.eddelbuettel.com" target="_blank">http://dirk.eddelbuettel.com</a><br>
</font></span></blockquote></div></div><span class="HOEnZb"><font color="#888888"><br><br clear="all"><div><br></div>-- <br>Sincerely,<br>Thell<br>
</font></span></div>
</div><br><br clear="all"><div><br></div>-- <br>Sincerely,<br>Thell<br>