<div class="gmail_extra"><br><div class="gmail_quote">On Sun, Apr 22, 2012 at 12:13 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:0pt 0pt 0pt 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<div class="im">
On 22 April 2012 at 11:41, Thell Fowler wrote:<br>
| On Sun, Apr 22, 2012 at 10:49 AM, Dirk Eddelbuettel <<a href="mailto:edd@debian.org">edd@debian.org</a>> wrote:<br>
</div><div class="im">|     On 22 April 2012 at 10:17, Thell Fowler wrote:<br>
<br>
</div><div class="im">|     | Any examples or direction on how (if I can) to get to a Rcpp Rmpfr bridge<br>
|     with<br>
|     | speed would go a long way...<br>
|<br>
|     Sounds fine. Not sure how to return (or pass down) the mpfr arrays. But you<br>
|     may be able to<br>
|     look at the existing CRAN packages wrapping mpfr for ideas.<br>
|  <br>
| I'll try reading through  the Rmpfr source to see how it does its' magic.<br>
| Also, the Bessel package depends on Rmpfr so that might yield some ideas.<br>
<br>
</div>It shouldn't be too hard, apart from the fact that instead of Rcpp niceties<br>
you have to deal with R API which is plain C and macros...<br>
<div class="im"><br></div></blockquote><div>After some trial and error I was able to pass down mpfr values.  You're right though, it wasn't 'nice'.<br><br>--->8 ---<br> <br></div><blockquote class="gmail_quote" style="margin:0pt 0pt 0pt 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
|<br><div class="im">
|     You just need to add the required -I and -L flags to src/Makevars and you<br>
|     should be fine. [ Higher-end solutions use configure, or pkg-config, or<br>
|     ... to find those values. Harcoded may work on standard Linux systems. ]<br>
|  <br>
| That part _should_ be pretty straight forward.<br>
<br>
</div>Yes.<br>
<div class="im"><br></div></blockquote><div>Well, it wasn't really all that straight forward after all as I need to use -std=c++0x.<br>Here's the code and comments used to setup access...<br><I hope gmail doesn't mess this up too much, I haven't setup alpine for this list yet...><br>
<br>suppressMessages( require( Rcpp ) )<br>suppressMessages( require( inline ) )<br><br><br>## Base Access to mpfr<br>#####<br># To have access to mpfr the following was done...<br>#   Extracted Rtools Local215keep3.zip to `c:\RtoolsLocal\R-2.15.0`<br>
#   Created an environment var `RTOOLS_LOCAL` to that path.<br>#   Set LOCAL_SOFT = $(RTOOLS_LOCAL) in $(R_HOME}/etc$(R_ARCH)/Makeconf<br>#   < note: CXXFLAGS =  -O3 -Wall $(DEBUGFLAG) -std=c++0x -mtune=core2 ><br>mpfr.settings <- Rcpp:::Rcpp.plugin.maker( include.before= "#include <mpfr.h>",<br>
                                           libs= "-lgmp -lmpfr" )<br>registerPlugin( "RcppMpfr", mpfr.settings )<br><br><br># Test mpfr .dll access<br>mpfr.Rcpp.source <- '<br>  Rprintf(" MPFR library: %-12s\\n MPFR header:  %s (based on %d.%d.%d)\\n",<br>
          mpfr_get_version(), MPFR_VERSION_STRING, MPFR_VERSION_MAJOR,<br>          MPFR_VERSION_MINOR, MPFR_VERSION_PATCHLEVEL);<br>  return Rcpp::wrap( std::string("OK") ); <br>'<br>mpfr.Rcpp.test <- cxxfunction( signature(),<br>
                               body= mpfr.Rcpp.source,<br>                               plugin= "RcppMpfr",<br>                               verbose= FALSE )<br>cat( mpfr.Rcpp.test(), '\n')<br><br><br>
## Access to Rmpfr<br>#####<br># To utilize the Rmpfr .dll functions for processing the Rmpfr SEXP parameters<br># a junction was made linking the src path of the mpfr to a new `include`<br># path in the Rmpfr package path.<br>
#<br># Inclusion of the Mpfr_utils caused some issues though;<br>#   1) REVprintf is not defined by R_ext/Print.h when __cpluscplus id defined<br>#      unless R_USE_C99_IN_CXX is defined.<br>#   2) allocVector is not decalred unless R_NO_REMAP is not defined.<br>
#   ...<br>#   Yet, with 1 defined and 2 not defined and passing -std=c++0x to GCC there is<br>#   a macro argument length error in codecvt.h included by Rostream.h's inclusion<br>#   of iomanip and __GXX_EXPERIMENTAL_CXX0X.<br>
#<br># Not passing -std=c++0x allowed successful compilation, but I'll need it.<br>#<br><br>suppressMessages( require( Rmpfr ) )<br><br>Rmpfr.Rcpp.include.before <-'<br><br>  #define R_USE_C99_IN_CXX<br>  #undef R_NO_REMAP<br>
  #include <Rmpfr_utils.h><br>  #include <Syms.h><br><br>'<br><br>Rmpfr.Rcpp.include.after <-'<br><br>  #include <R_ext/Rdynload.h><br>  <br>'<br><br>Rmpfr.settings <- Rcpp:::Rcpp.plugin.maker( include.before= Rmpfr.Rcpp.include.before,<br>
                                            include.after= Rmpfr.Rcpp.include.after,<br>                                            LinkingTo=c('Rmpfr',"Rcpp"),<br>                                            libs="-lgmp -lmpfr" )<br>
registerPlugin( "RcppRmpfr", Rmpfr.settings )<br><br>Rmpfr.Rcpp.include <- '<br><br>  // Typedefs...<br>  // Doing this for each signature in Rmpfr that is used should not be too bad,<br>  // but it would be nice not to have to.<br>
  <br>  typedef SEXP (*FUNC)(void);<br>  FUNC p_R_mpfr_get_version = (FUNC) R_GetCCallable("Rmpfr", "R_mpfr_get_version");<br><br>'<br><br>Rmpfr.Rcpp.source <- '<br><br>  Rprintf(" MPFR library: %-12s\\n MPFR header:  %s (based on %d.%d.%d)\\n",<br>
          mpfr_get_version(), MPFR_VERSION_STRING, MPFR_VERSION_MAJOR,<br>          MPFR_VERSION_MINOR, MPFR_VERSION_PATCHLEVEL);<br><br>  return p_R_mpfr_get_version();<br><br>'<br>Rmpfr.Rcpp.test <- cxxfunction( signature(),<br>
                                includes= Rmpfr.Rcpp.include,<br>                                body= Rmpfr.Rcpp.source,<br>                                plugin= "RcppRmpfr",<br>                                verbose= FALSE )<br>
<br>cat( Rmpfr.Rcpp.test(), '\n')<br><br><br></div><blockquote class="gmail_quote" style="margin:0pt 0pt 0pt 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div class="im">
|     [ And if you want to look into doing more of an integration (a la<br>
|     RcppArmadillo,<br>
|     RcppGSL, RcppEigen, ...), then the Rcpp-extending vignette shows you how to<br>
|     modify as<>() and wrap() to get automatic converters going.  But you<br>
|     surely<br>
|     don't need to do this for a first attempt to compute your stuff. I just<br>
|     mention it as you say 'R mpfr bridge' -- this would be the Rcpp way of<br>
|     doing<br>
|     it. ]<br>
|  <br>
</div><div class="im">| The Rcpp-extending vignette is what I originally thought would be the answer.<br>
| Good thing I asked first! ;)<br>
<br>
</div>It's somewhat scarier reading material but it nudges ever so gently into<br>
Template Programming...  You do *not* need to go there just to call mpfr.<br>
<div class="HOEnZb"><div class="h5"><br></div></div></blockquote><div><br>Well, in the end it looks like this is essentially what I'll need to do...<br>After looking around at the options I think what I need to do is use the mpfrc++ library.<br>
Only two headers and works on top of gmp and mpfr, but I do wonder one thing about using it as an extension...<br><br>It includes its own dlmalloc, is this a death blow for using it as either an extension/package, RcppMpfr++ package?<br>
</div></div><br>-- <br>Sincerely,<br>Thell<br>
</div>