You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: content/cython.rst
+15-7Lines changed: 15 additions & 7 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -261,6 +261,7 @@ float, double float
261
261
char \* str/bytes
262
262
============= ===============
263
263
264
+
264
265
Using Numpy arrays with Cython
265
266
------------------------------
266
267
@@ -388,10 +389,21 @@ Cython (see also `Cython docs <https://cython.readthedocs.io/en/latest/src/quick
388
389
- Only Cythonize the modules/functions for which performance is *really*
389
390
needed. Profiling tools help at identifying such bottlenecks.
390
391
- Static type declarations work the best for fundamental data types (integers,
391
-
floats, strings) and for contiguous arrays. Operations on lists and
392
-
dictionaries do not usually benefit much from Cython.
392
+
floats, strings) and for contiguous arrays. Operations on heterogeneous lists
393
+
and dictionaries do not usually benefit much from Cython.
394
+
395
+
396
+
Alternatives to Cython
397
+
----------------------
398
+
399
+
There exists a plethora of other tools and libraries for extending Python with
400
+
compiled C code. If you already have a working C/C++ codebase and would like
401
+
to use it from Python, consider using one of the following:
402
+
403
+
- `ctypes <https://docs.python.org/3/library/ctypes.html>`__: part of Python standard library.
404
+
- `CFFI <https://cffi.readthedocs.io/en/stable/index.html>`__: somewhat similar to `ctypes` but with more features and probably better for large projects.
405
+
- `pybind11 <https://pybind11.readthedocs.io/en/stable/index.html>`__: very robust and modern way of creating extension modules. C++ only.
393
406
394
-
TODO: when to use other C extension stuff
395
407
396
408
Further reading
397
409
---------------
@@ -400,10 +412,6 @@ Further reading
400
412
are a newer and more general way of interfacing with Numpy arrays and other buffer-like objects.
401
413
- `Calling C functions from Cython <https://cython.readthedocs.io/en/latest/src/tutorial/external.html>`__
0 commit comments