An example of a hybrid cython library based on numpy that allows C++ or Python applications to interact directly, without the need of rewriting separate functions for C++/Python programs individually
The library is written in the file numpylib.pyx, containing two simple functions:
- sum3d - calculates the sum of all elements in a 3d array
- tozeros - set all elements of a 3d array to zero
To cythonize the library, run make setup
To run the python program that uses the library, run make run_py
To run the C++ program that uses the library:
- export the env variable PYINCLUDE_PATH (the Python.h file should be under this path, usually should be usr/include/python{version}/)
- run
make run_cc
Note: the example requires installation of Cython and numpy
if you cannot find the Python.h file, please kindly refer to this link https://stackoverflow.com/questions/21530577/fatal-error-python-h-no-such-file-or-directory