[SciPy-User] Examples how to call NumPy from C++

Nathaniel Smith njs at pobox.com
Thu Aug 13 07:45:05 EDT 2015


On Aug 13, 2015 1:44 AM, "Alexander Kalinin" <alec.kalinin at gmail.com> wrote:
>
> Thank you very much for answers!
>
> I have a little bit more complicated algorithm in NumPy than simple
matrix multiplication. I have a big software in C++ and want to integrate
some new math. First idea was to prototype algorithm in NumPy and next
rewrite it on C++. But in NumPy implementation suddenly becomes very clear
and it works pretty fast! So my idea now to embed this algorithm in C++
directly.
>
> Yes, I known Swig, Cython and other tools. But all of them mostly do the
reverse task: embed C++ into Python. I did now found any detailed examples
how to solve my task: embed Python into C++.

In general, embedding python in c/c++ is very similar to going the other
way. Basically you just have to call a few functions to set up the python
interpreter and then it's just the usual problems of calling python from C
or vice versa, and you can use all the usual tools like cython or
boost.python or whatever you like:
  https://docs.python.org/2/extending/embedding.html

You might also want to seriously think turning things around and embedding
your C++ library in python instead. It's a bit more work of you're starting
from an existing C++ program, but there are a lot of advantages as well.
This essay is very opinionated but does do a good job of explaining why
this is worth considering:
  https://twistedmatrix.com/users/glyph/rant/extendit.html

-n
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.scipy.org/pipermail/scipy-user/attachments/20150813/44deb946/attachment.html>


More information about the SciPy-User mailing list