<div dir="ltr"><div class="gmail_default" style="font-family:arial,helvetica,sans-serif;font-size:small">In my experience, it's usually much easier to have a stand-alone C++ library and add the Rcpp and Boost.Python layer on top of it. As you said, NumericVector and other classes are not known in the Python world.</div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif;font-size:small"><br></div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif;font-size:small">You can always hook in into them from Boost.Python to expose them to Python but a clear and simple design is to have an independent C++ library and then you wrap it into all the languages you want.</div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif;font-size:small">I found Boost.Python quite similar to Rcpp (I think the second one got inspiration from the first one ?). So it shouldn't be too hard...</div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif;font-size:small"><br></div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif;font-size:small">Cheers,</div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif;font-size:small">David</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Apr 27, 2018 at 8:43 AM, Simon Barthelmé <span dir="ltr"><<a href="mailto:simon.barthelme@gipsa-lab.fr" target="_blank">simon.barthelme@gipsa-lab.fr</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Dear list,<br>
<br>
I have an R package that's mostly C++ code (using Eigen, but no other dependencies) and some glue. We wish to re-use the C++ code for a Python package. Most of the external-facing C++ functions are pretty simple: essentially they're all variants of:<br>
<br>
NumericVector some_matrix_calculation(Numeri<wbr>cMatrix a_matrix);<br>
<br>
and all the stuff coming in or out are dense vectors and matrices. Note that I wrote all this with the idea that the C++ would only be called from R, so the C++ bits don't amount to a proper library.<br>
<br>
I haven't used Python in years but from what I read there's about a dozen different ways now of interfacing Python and C/C++. Obviously none of them know about Rcpp objects like NumericVector so I'm guessing it'll have to be std::vector<double> in and out, unless there's a better way?<br>
<br>
So: does anyone have any experience or advice on sharing C++ code between R and Python, short of spinning off the C++ as a stand-alone library and writing entirely separate interfaces?<br>
<br>
Also, I know you can call R from Python and vice-versa, but we don't want to require Python users to install R+dependencies and vice-versa.<br>
<br>
Many thanks for any advice!<br>
<br>
Best regards<br>
<br>
Simon Barthelme<br>
______________________________<wbr>_________________<br>
Rcpp-devel mailing list<br>
<a href="mailto:Rcpp-devel@lists.r-forge.r-project.org" target="_blank">Rcpp-devel@lists.r-forge.r-pro<wbr>ject.org</a><br>
<a href="https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel" rel="noreferrer" target="_blank">https://lists.r-forge.r-projec<wbr>t.org/cgi-bin/mailman/listinfo<wbr>/rcpp-devel</a><br>
</blockquote></div><br></div>