[Rcpp-devel] Fwd: Rcpp RMpfr mpreal to mpfr wrapping

Thell Fowler tbfowler4 at gmail.com
Sun Nov 18 22:04:34 CET 2012


---------- Forwarded message ----------
From: Thell Fowler <tbfowler4 at gmail.com>
Date: Sun, Nov 18, 2012 at 3:03 PM
Subject: Re: [Rcpp-devel] Rcpp RMpfr mpreal to mpfr wrapping
To: Dirk Eddelbuettel <edd at debian.org>





On Sun, Nov 18, 2012 at 1:59 PM, Dirk Eddelbuettel <edd at debian.org> wrote:

>
> Hi Thell,
>
> On 18 November 2012 at 13:03, Thell Fowler wrote:
> | Hi all.
> |
> | I've been doing some testing on how to get arbitrary precision numbers
> out of
> | c++ and into R.  The following example inline Rcpp code generates an
> RcppMpfr
> | cxxfunction plugin for wrapping <mpreal> to the Rmpfr S4 "mpfr1" object.
>
> Nice.
>
> |  There are local include paths that need adjusting (for now) to your
> | environment, and the mpreal header only c++ wrapper for mpfr ( http://
> | www.holoborodko.com/pavel/mpfr/ ).  I'll be making this into a package
> but
> | wanted to ask about how to do something first...
>
> Just so that I understand: that is another C++ layer on top of GNU mpfr ?
> Yet you do link with -lmpfr below...
>
> Yes, mpreal is a nice c++ class wrapper  for working with mpfr, so all the
c++ goodness can simply be used.

 | Rmpfr defines 'mpfr1' and 'mpfr' where 'mpfr' is usable within R and is
> a list
> | type containing 'mpfr1' objects.  So the Rcpp::wrap is setup to get and
> | populate an S4 "mpfr1" object, but to be usable on the R side the S4
> "mpfr"
> | needs to be used.  I can get and populate the ".Data" field in the
> | mpfr::mpreal wrapper using Rcpp::List but was wondering if the
> Rcpp::wrap could
> | be setup to capture an S4 class type.
>
> "I guess so".
>
> I haven't tried.  We do get the whole SEXP, and we have some code to access
> and set S4 slots.
>
> 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?

--- >8 ---


>  | I'd like to have wrap<mpfr::mpreal> wrap to an 'mpfr1' and
> wrap<S4<mpfr1>>
> | (imagined def) wrap to an mpfr list.
> |
>

 --- >8 ---

 | #### Plugin Definition ####
> | RcppMpfr <- function()
> | {
> |   plugin <- Rcpp:::Rcpp.plugin.maker(
> |     include.before= include.before,
> |     include.after= include.after,
> |     LinkingTo=c('Rmpfr',"Rcpp"),
>
> I don't see Rmpfr exporting header files, so not sure if you need Rmpfr
> here?
>
> Yes, not needed... a remnant from attempting to use Rmpfr's MPFR_as_R
routine.


>  |     libs="-Lc:/RtoolsLocal/R-2.15.0/lib/i386 -lmpfr -lgmp" )
> |   settings <- plugin()
> |   settings$env$PKG_CPPFLAGS=paste(
> |     "-std=c++0x",
> |     "-Ic:/users/almostautomated/src/RcppMpfr++/mpreal/inst/include",
>
> You can probably make that local to your package if you keep it in
> RcppMpfr++/inst/include/...
>
> Or is this another package? I'm lost here....
>
> 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.



> |     "-Ic:/RtoolsLocal/R-2.15.0/include" )
>
> R will already provide this.
>
> Nice!  Odd that the -L path isn't provided as well...


> Looks good. I am not quite sure what your question is, though. Your proof
> of
> concept seems to working, so why not build a package ?
>
> Dirk
>
> 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.


> |
> | Sincerely,
> | Thell
> |
> | ----------------------------------------------------------------------
> | _______________________________________________
> | Rcpp-devel mailing list
> | Rcpp-devel at lists.r-forge.r-project.org
> | https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel
> --
> Dirk Eddelbuettel | edd at debian.org | http://dirk.eddelbuettel.com
>



-- 
Sincerely,
Thell



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


More information about the Rcpp-devel mailing list