[Rcpp-devel] Passing XPtr of Eigen Map object between functions

Charles Determan cdetermanjr at gmail.com
Fri Jun 26 15:54:35 CEST 2015


I apologize if I am not being clear.  I realize that R doesn't have float
data types, however I am able to pass a matrix in as a MatrixXf object.  I
would like to be able to refer to this MatrixXf object persistently.  Some
general code to demonstrate my point.

# pass R matrix in as MatrixXf object and return pointer to that object
SEXP matrixIN(MatrixXf A)
{
    return XPtr<MatrixXf>(A);
}

# pass previously made pointer and return that matrix
SEXP matrixOUT(XPtr<MatrixXfr> ptrA)
{
    MatrixXf A = *ptrA
    return wrap(A)
}

On Fri, Jun 26, 2015 at 8:32 AM, Dirk Eddelbuettel <edd at debian.org> wrote:

>
> On 26 June 2015 at 07:43, Charles Determan wrote:
> | I have tried a few more feeble attempts (explicitly create pointer to
> pass,
> | passing just the MatrixXf object) at getting the Eigen object to persist
> | between functions without the additional Armadillo wrapper but with no
> | success.  Anyone have any additional thoughts?
>
> You are not making it very easy to help you as you do not clearly say what
> you really want.  Some things you talk about don't exist (ie "float matrix
> in
> R"), others make no sense (XPtr of Eigen::Map when the latter already is a
> proxy object).
>
> As for the question of persistence, the single simplest approach I often
> use
> it create a trivial class holding a member variable of the "thing" you want
> to persist (often a database or resource handle, could even be a honking
> bigmemory object and shared handle) whichI create in the constructor, or an
> init() function, and release in the destructor.
>
> Dirk
>
> --
> http://dirk.eddelbuettel.com | @eddelbuettel | edd at debian.org
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.r-forge.r-project.org/pipermail/rcpp-devel/attachments/20150626/576073a5/attachment.html>


More information about the Rcpp-devel mailing list