[Rcpp-devel] Apply Defined Rcpp Functions In Parallel
Dillon Hammill
Dillon.Hammill at anu.edu.au
Sat Aug 21 09:09:10 CEST 2021
Thanks again for your help Dirk.
Hope you don't mind if I ask a couple of follow up questions about as and wrap.
I have made the switch to using thread safe STL objects for use with RcppParallel and writing wrappers for R objects.
I am using std vector of vectors to represent matrices and I would like to be able to convert to and from these objects to R objects.
For example, it seems that there is no inbuilt conversion method from std::vector<std::vector<int>> to IntegerMatrix or vice versa (both as and wrap).
Is there a reason why this conversion has not been implemented? How would I go about implementing such a conversion? Or should I be using a different STL format (e.g. a single vector) and wrap that into an R matrix?
I have had a look at "Rcpp Extending" vignette but I have no idea where to start (this is beyond my current capabilities - I haven't worked with templates before).
In the meantime, I have been allocating the desired object and filling it with data from the original object, but my understanding is that this is creating a copy in memory (I would like to avoid this)?
[[Rcpp::export]]
NumericMatrix RcppIntMatConvert (IntegerMatrix x) {
// convert x to std
std::vector<std::vector<int>> x_std(x.ncol(), std::vector<int>(x.nrow()));
// push x into x_std
for(int i = 0; i < x.ncol(); i++) {
for(int j = 0; j < x.nrow(); j++) {
x_std[i][j] = x(j, i);
}
}
return x_std
}
Appreciate your help!
Dillon
________________________________
From: Dirk Eddelbuettel <edd at debian.org>
Sent: Wednesday, 18 August 2021 11:40 AM
To: Dillon Hammill <Dillon.Hammill at anu.edu.au>
Cc: Dirk Eddelbuettel <edd at debian.org>; rcpp-devel at lists.r-forge.r-project.org <rcpp-devel at lists.r-forge.r-project.org>
Subject: Re: [Rcpp-devel] Apply Defined Rcpp Functions In Parallel
On 18 August 2021 at 01:26, Dillon Hammill wrote:
| Thanks for your help Dirk, I think I have everything I need to get things working now. I just needed a push in the right direction to discover wrap and as from Rcpp - they are awesome!
They are indeed. (And, if I may, feature prominently in the 'Introduction to
Rcpp' and other documents we offer. But I acknowledge that there are lots of
those.)
| I am just beginning to explore the power Rcpp and PcppParallel.
|
| Keep up the great work!
Thanks, we try :)
Dirk
--
https://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/20210821/71f7bd09/attachment.html>
More information about the Rcpp-devel
mailing list