<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<style type="text/css" style="display:none;"> P {margin-top:0;margin-bottom:0;} </style>
</head>
<body dir="ltr">
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
Thanks again for your help Dirk.</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<br>
</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
Hope you don't mind if I ask a couple of follow up questions about as and wrap.</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<br>
</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
I have made the switch to using thread safe STL objects for use with RcppParallel and writing wrappers for R objects. </div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<br>
</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
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.</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<br>
</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
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).</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<br>
</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
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?</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
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). </div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<br>
</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
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)?</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
[[Rcpp::export]]</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
NumericMatrix RcppIntMatConvert (IntegerMatrix x) {
<div> </div>
<div> // convert x to std</div>
<div> std::vector<std::vector<int>> x_std(x.ncol(), std::vector<int>(x.nrow()));</div>
<div><br>
</div>
<div> // push x into x_std</div>
<div> for(int i = 0; i < x.ncol(); i++) {</div>
<div> for(int j = 0; j < x.nrow(); j++) {</div>
<div> x_std[i][j] = x(j, i);</div>
<div> }</div>
}<br>
</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<br>
</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
return x_std</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
}</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<br>
</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
Appreciate your help!</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<br>
</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
Dillon</div>
<div id="appendonsend"></div>
<hr style="display:inline-block;width:98%" tabindex="-1">
<div id="divRplyFwdMsg" dir="ltr"><font face="Calibri, sans-serif" style="font-size:11pt" color="#000000"><b>From:</b> Dirk Eddelbuettel <edd@debian.org><br>
<b>Sent:</b> Wednesday, 18 August 2021 11:40 AM<br>
<b>To:</b> Dillon Hammill <Dillon.Hammill@anu.edu.au><br>
<b>Cc:</b> Dirk Eddelbuettel <edd@debian.org>; rcpp-devel@lists.r-forge.r-project.org <rcpp-devel@lists.r-forge.r-project.org><br>
<b>Subject:</b> Re: [Rcpp-devel] Apply Defined Rcpp Functions In Parallel</font>
<div> </div>
</div>
<div class="BodyFragment"><font size="2"><span style="font-size:11pt;">
<div class="PlainText"><br>
On 18 August 2021 at 01:26, Dillon Hammill wrote:<br>
| 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!<br>
<br>
They are indeed. (And, if I may, feature prominently in the 'Introduction to<br>
Rcpp' and other documents we offer. But I acknowledge that there are lots of<br>
those.)<br>
<br>
| I am just beginning to explore the power Rcpp and PcppParallel.<br>
| <br>
| Keep up the great work!<br>
<br>
Thanks, we try :)<br>
<br>
Dirk<br>
<br>
-- <br>
<a href="https://dirk.eddelbuettel.com">https://dirk.eddelbuettel.com</a> | @eddelbuettel | edd@debian.org<br>
</div>
</span></font></div>
</body>
</html>