[Rcpp-devel] Example of rcpp usage with Rmpfr, mpfr, gmp.
Dirk Eddelbuettel
edd at debian.org
Sun Apr 22 19:13:28 CEST 2012
Thanks for recentering this on list...
On 22 April 2012 at 11:41, Thell Fowler wrote:
| On Sun, Apr 22, 2012 at 10:49 AM, Dirk Eddelbuettel <edd at debian.org> wrote:
| On 22 April 2012 at 10:17, Thell Fowler wrote:
| | Any examples or direction on how (if I can) to get to a Rcpp Rmpfr bridge
| with
| | speed would go a long way...
|
| Sounds fine. Not sure how to return (or pass down) the mpfr arrays. But you
| may be able to
| look at the existing CRAN packages wrapping mpfr for ideas.
|
| I'll try reading through the Rmpfr source to see how it does its' magic.
| Also, the Bessel package depends on Rmpfr so that might yield some ideas.
It shouldn't be too hard, apart from the fact that instead of Rcpp niceties
you have to deal with R API which is plain C and macros...
| As a really simple minded idea, you can
|
| 1) use Rcpp to pass values from R down to a C/C++ layer
|
|
| 2) "cast" or copy your values into mpfr et al types, do you computations
| and get the result, cast/copy it back to C/C++
|
| 3) use Rcpp to communicate back up
|
| which is pretty standard use of Rcpp to call external libraries or
| packages. Many of the CRAN packages using Rcpp do something similar.
|
| I'll take a closer look at how this works.
| At first thought I wonder what the function sig would use for the type? Some
| sort of 'raw' type ?
Why raw? I would bring numeric or integer down as such, then cast at the C++
level as per 2) above.
|
| You just need to add the required -I and -L flags to src/Makevars and you
| should be fine. [ Higher-end solutions use configure, or pkg-config, or
| ... to find those values. Harcoded may work on standard Linux systems. ]
|
| That part _should_ be pretty straight forward.
Yes.
| [ And if you want to look into doing more of an integration (a la
| RcppArmadillo,
| RcppGSL, RcppEigen, ...), then the Rcpp-extending vignette shows you how to
| modify as<>() and wrap() to get automatic converters going. But you
| surely
| don't need to do this for a first attempt to compute your stuff. I just
| mention it as you say 'R mpfr bridge' -- this would be the Rcpp way of
| doing
| it. ]
|
| The Rcpp-extending vignette is what I originally thought would be the answer.
| Good thing I asked first! ;)
It's somewhat scarier reading material but it nudges ever so gently into
Template Programming... You do *not* need to go there just to call mpfr.
Dirk
--
R/Finance 2012 Conference on May 11 and 12, 2012 at UIC in Chicago, IL
See agenda, registration details and more at http://www.RinFinance.com
More information about the Rcpp-devel
mailing list