[Rcpp-devel] Example of rcpp usage with Rmpfr, mpfr, gmp.

Thell Fowler tbfowler4 at gmail.com
Sun Apr 22 18:41:16 CEST 2012


---------- Forwarded message ----------
From: Thell Fowler <tbfowler4 at gmail.com>
Date: Sun, Apr 22, 2012 at 11:18 AM
Subject: Re: [Rcpp-devel] Example of rcpp usage with Rmpfr, mpfr, gmp.
To: Dirk Eddelbuettel <edd at debian.org>




On Sun, Apr 22, 2012 at 10:49 AM, Dirk Eddelbuettel <edd at debian.org> wrote:

>
> Hi Thell,
>
> On 22 April 2012 at 10:17, Thell Fowler wrote:
>
> --- >8 ---


>  | Simple and straight forward...
> |
> | My two use cases are:
> |
> | 1)  Pass input as 'numeric', convert to multiprecision 160-bit, do
> | calculations using multiprecision lgamma values, and return an mpfr array
> | object.
> | 2)  Pass input as mpfr objects (list or array), do calculations, and
> return
> | the modified values.
> |
> | 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.

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 ?

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.

[ 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. ]
>
> Cheers, Dirk
>
>
The Rcpp-extending vignette is what I originally thought would be the
answer.
Good thing I asked first! ;)

-- 
Sincerely,
Thell



-- 
Sincerely,
Thell
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.r-forge.r-project.org/pipermail/rcpp-devel/attachments/20120422/bb66a386/attachment.html>


More information about the Rcpp-devel mailing list