[Numpy-discussion] State-of-the-art to use a C/C++ library from Python

Chris Barker chris.barker at noaa.gov
Tue Sep 6 18:42:03 EDT 2016


On Fri, Sep 2, 2016 at 1:16 AM, Peter Creasey <p.e.creasey.00 at googlemail.com
> wrote:

> > I'm not quite sure which approach is state-of-the-art as of 2016. How
> would
> > you do it if you had to make a C/C++ library available in Python right
> now?
> >
> > In my case, I have a C library with some scientific functions on matrices
> > and vectors. You will typically call a few functions to configure the
> > computation, then hand over some pointers to existing buffers containing
> > vector data, then start the computation, and finally read back the data.
> > The library also can use MPI to parallelize.
>

Cython works really well for this.

ctypes is a better option if you have a "black box" shared lib you want a
call a couple functions in.

Cython works better if you want to write a little "thicker" wrapper around
youe C code -- i.e. it may do a scalar computation, and you want to apply
it to an entire numpy array, at C speed.

Either would work in this case, But I like Cyton better, as long as I don't
have compilation issues.

-Chris




-- 

Christopher Barker, Ph.D.
Oceanographer

Emergency Response Division
NOAA/NOS/OR&R            (206) 526-6959   voice
7600 Sand Point Way NE   (206) 526-6329   fax
Seattle, WA  98115       (206) 526-6317   main reception

Chris.Barker at noaa.gov
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20160906/ef53b069/attachment.html>


More information about the NumPy-Discussion mailing list