<div dir="auto">Hi Víthor,<div dir="auto"><br></div><div dir="auto">My simulation package makes heavy use of calls to R user functions from a C++ simulation loop, and therefore greatly benefits from this feature too, which I think we should promote to default. Meanwhile, take a look at this Makevars file to see how to activate it: <a href="https://github.com/r-simmer/simmer/blob/master/src/Makevars">https://github.com/r-simmer/simmer/blob/master/src/Makevars</a></div><div dir="auto"><br></div><div dir="auto">Iñaki</div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">El jue., 2 dic. 2021 17:32, Víthor Rosa <<a href="mailto:vrosafranco@gmail.com">vrosafranco@gmail.com</a>> escribió:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Hi everyone,<div><br></div><div>I am using Rcpp to develop my own package and one of my functions calls back into R for a given amount of iterations. To speed up the process, I wanted to use Rcpp::unwindProtect. However, I couldn't find on Rcpp's documentation what is the correct way to use this plugin. Therefore, I would like to ask you for some guidance, if possible.</div><div dir="ltr" data-smartmail="gmail_signature"><div dir="ltr"><div><div dir="ltr"><span><div><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><i></i><br></div></div><div>Reproducible toy example:</div><div><br></div><div>````````````````</div><div>require(Rcpp)<br>Rcpp::cppFunction("<br>  NumericVector test_f(NumericMatrix x, Function f) {<br>    NumericVector out(x.ncol());<br>  <br>    for (int iter = 0; iter < x.ncol(); iter++) {<br>      out[iter] = as<double>(f(x(_ , iter)));<br>    }<br>    <br>    return out;<br>  }<br>")<br><br>x <- matrix(1.2:9.2, 3, 3)<br><br>colSums(x)<br>f <- function(x) sum(x)<br>test_f(x, f)<br><br>require(rbenchmark)<br>rbenchmark::benchmark("R1"=colSums(x),<br>                                        "R2"=test_f(x, f),<br>                                        replications=10000)<br></div><div>````````````````<br></div><div dir="ltr"><br></div><div>Best,</div><div>Vithor</div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></span></div></div></div></div></div>
_______________________________________________<br>
Rcpp-devel mailing list<br>
<a href="mailto:Rcpp-devel@lists.r-forge.r-project.org" target="_blank" rel="noreferrer">Rcpp-devel@lists.r-forge.r-project.org</a><br>
<a href="https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel" rel="noreferrer noreferrer" target="_blank">https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel</a></blockquote></div>