<div dir="ltr"><div><div><div dir="ltr" class="gmail_signature" data-smartmail="gmail_signature"><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div>On Wed, Jul 25, 2018 at 5:57 PM Dirk Eddelbuettel <<a href="mailto:edd@debian.org">edd@debian.org</a>> wrote:<br></div></div></div></div></div></div></div></div></div><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><br>
On 25 July 2018 at 17:30, julien chiquet wrote:<br>
| Hi,<br>
| <br>
| I am trying to wrap the optim library (<a href="https://github.com/kthohr/optim" rel="noreferrer" target="_blank">https://github.com/kthohr/optim</a>) in<br>
| R via an R package using Rcpp/RcppArmadillo. Indeed, optim relies on<br>
| armadillo itself. The github repository can be found here<br>
| <a href="https://github.com/jchiquet/optimLibR" rel="noreferrer" target="_blank">https://github.com/jchiquet/optimLibR</a><br>
| <br>
| To do that, I put the headers of optim into inst/include/ and the cpp files<br>
| into src/. Then I tried to "heuristically" pull everything together in the<br>
| src/Makevars files, after my (obviously poor) understanding of the R manual<br>
| pages about Makevars and from the various examples that I copied from the<br>
| web (especially from the RcppMLPACK1 which, relies on the C++ library<br>
| MLPACK, itself based on armadillo<br>
| <a href="https://github.com/rcppmlpack/RcppMLPACK1/blob/master/src/Makevars" rel="noreferrer" target="_blank">https://github.com/rcppmlpack/RcppMLPACK1/blob/master/src/Makevars</a>).<br>
| <br>
| The package installation (including compilation of optim) successes (at<br>
| least, the package can be installed). Then I tried to create two small Rcpp<br>
| functions for two examples available in the original optim library,<br>
| starting with the following lines<br>
| <br>
| // [[Rcpp::depends(RcppArmadillo)]]// [[Rcpp::plugins(cpp11)]]<br>
| #define USE_RCPP_ARMADILLO<br>
| #include "optim.hpp"<br>
| <br>
| (The #define command is an option of the optim library.)<br>
| <br>
| However, when I call the corresponding R functions, I get the following<br>
| Armadillo errors in R which I do not have when running them in 'pure' C++<br>
| (I am pretty sure it is not a syntax problem, the Rcpp code and the<br>
| original C++ code are hopefully identical, except for the headers).<br>
| <br>
| > library(optimLibR)> ackley_function()error: arma::memory::acquire(): out of memory<br>
| <br>
| > library(optimLibR)> logit_optimLib()error: Mat::init(): requested size is not compatible with column vector layout<br>
| <br>
| So it seems to me that the header of armadillo are correctly defined but I<br>
| am not sure that I reach the src (cpp) part of armadillo which is required<br>
| at the execution.<br>
| <br>
| If anyone can confirm or help pointing the origin of the error, I would be<br>
| debtful...<br>
| <br>
| Thanks for your time,<br>
<br>
Good news / bad news. I think the good news is that everything builds, so you<br>
have no linking issue. In fact, no RcppArmadillo package links to Armadillo<br>
as we do everything via the headers.<br>
<br>
But you seem to have run-time issues which _could_ stem from the fact that<br>
RcppArmadillo sets a bunch of #define variables and your use may be slightly<br>
different / conflict with these. Maybe you can check with Keith about how<br>
his optim(lib) could / should be called from R.<br></blockquote><div> </div><div><div style="font-size:small;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial"><span style="font-size:small;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">Thanks for your prompt and helpful answer. At least I know I do not have to struggle with the Makevars.</span></div><div style="font-size:small;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial"><span style="font-size:small;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline"><br></span></div><div style="font-size:small;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial"><span style="font-size:small;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">I'll check with Keith.</span><br></div><br class="gmail-Apple-interchange-newline">j</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Dirk<br>
<br>
-- <br>
<a href="http://dirk.eddelbuettel.com" rel="noreferrer" target="_blank">http://dirk.eddelbuettel.com</a> | @eddelbuettel | <a href="mailto:edd@debian.org" target="_blank">edd@debian.org</a><br>
</blockquote></div></div>