[Numpy-discussion] creating/working NumPy-ndarrays in C++

Zachary Pincus zachary.pincus@yale....
Mon Apr 9 13:38:10 CDT 2012

> That all sounds like no option -- sad.
> Cython is no solution cause, all I want is to leave Python Syntax in
> favor for strong OOP design patterns.

What about ctypes?

For straight numerical work where sometimes all one needs to hand across the python-to-C/C++/Fortran boundary is a pointer to some memory and the size of the memory region. So I will often just write a very thin C interface to whatever I'm using and then call into it with ctypes.

So you could just design your algorithm in C++ with all the "strong OOP design patterns" you want, and then just write a minimal C interface on top with one or two functions that receive pointers to memory. Then allocate numpy arrays in python with whatever memory layout you need, and use the a "ctypes" attribute to find the pointer data etc. that you need to pass over. 


More information about the NumPy-Discussion mailing list