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

Stefan Seefeld stefan at seefeld.name
Thu Aug 13 04:54:08 EDT 2015


On 13/08/15 04:40 AM, Alexander Kalinin 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++.
>
> So I found only two candidates: Python C API and boost.python with
> pretty new addon boot.numpy. But also there is a lack of examples how
> to pass and return complex numpy structures to C++.
>
> But I believe I am not a first one who what to call NumPy from C++.
> May be somebody already played with such tasks.

Alexander,

I have been using Boost.Python to bridge C++ and Python successfully.
(I'm actually the maintainer of Boost.Python, and I have mentored some
GSoC work on Boost.NumPy in the past.) I do know from my own experience
that it's possible to share arrays between the C++ and Python runtimes
(in both directions) without copies, so creating a C++ array and then
expose that as a NumPy array to the Python runtime definitely works.

For a more in-depth technical discussion I suggest the Boost.Python
mailing list.

Regards,
        Stefan

-- 

      ...ich hab' noch einen Koffer in Berlin...




More information about the SciPy-User mailing list