Skip to content

[Rcpp-devel] arma to Rcpp

3 messages · Dirk Eddelbuettel, stefano iacus

#
Hi everybody

this is probably a trivial question,but still something is not clear to me.

Moving from SEXP => Rcpp => arma objects (say a matrix) I could do:

Rcpp::NumericMatrix A(clone(X)); // I want deep copy
arma::mat B = as< mat >(A); // again a copy

...
some code here that modifies B
...

Now, what shall I do if I want to transform B into a Rcpp::NumericMatrix?
Why? For example I might want to add attributes to it.

wrap() is no good, so what else?

Stefano
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.r-forge.r-project.org/pipermail/rcpp-devel/attachments/20111214/46e8c3c2/attachment.htm>
#
On 14 December 2011 at 13:55, Stefano Calza wrote:
| Hi everybody
| 
| this is probably a trivial question,but still something is not clear to me.
| 
| Moving from SEXP => Rcpp => arma objects (say a matrix) I could do:
| 
| Rcpp::NumericMatrix A(clone(X)); // I want deep copy
| arma::mat B = as< mat >(A); // again a copy
| 
| ...
| some code here that modifies B
| ...
| 
| Now, what shall I do if I want to transform B into a Rcpp::NumericMatrix? Why?
| For example I might want to add attributes to it.
| 
| wrap() is no good, so what else?

Well as wrap() returns a SEXP, if you really wanted to, you could then call
as<>() on that SEXP to create a new Rcpp object.  That is perfectly generic.

As for a more direct arma::mat to Rcpp::NumericMatrix: I would study all
available constructors to Rcpp::NumericMatrix. There are forms where you
indicate the beginning of the underlying memory as well as the dimensions.
#
Actually using wrap created my a headache because out of long runs and multicores R was randomly garbage collecting it causing segfaults. 

Ok know I got it. Thanks

Stefano

Inviato da iPhone

Il giorno 14/dic/2011, alle ore 17:12, Dirk Eddelbuettel <edd at debian.org> ha scritto: