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 <[email protected]>
Sent: Wednesday, 18 August 2021 11:40 AM
To: Dillon Hammill <[email protected]>
Cc: Dirk Eddelbuettel <[email protected]>; [email protected]
<[email protected]>
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 | [email protected]
_______________________________________________
Rcpp-devel mailing list
[email protected]
https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel