From ac8538fb7990fd8f1fb173553b78ccd08e3b8917 Mon Sep 17 00:00:00 2001 From: Stefan Behnel Date: Wed, 19 Jan 2011 15:26:44 +0100 Subject: [PATCH] remove initial 'calling external C functions' tutorial - it's broken beyond repair --- src/tutorial/external.rst | 52 --------------------------------------- src/tutorial/index.rst | 1 - 2 files changed, 53 deletions(-) delete mode 100644 src/tutorial/external.rst diff --git a/src/tutorial/external.rst b/src/tutorial/external.rst deleted file mode 100644 index dc40480e..00000000 --- a/src/tutorial/external.rst +++ /dev/null @@ -1,52 +0,0 @@ -Calling external C functions -============================ - -It is perfectly OK do ``from math import sin`` to use Python's -``sin()`` function. However, calling C's own ``sin()`` function is -substantially faster, especially in tight loops. It can be declared -and used in Cython as follows:: - - cdef extern from "math.h": - double sin(double) - - cdef double f(double x): - return sin(x*x) - -At this point there are no longer any Python wrapper objects around -our values inside of the main for loop, and so we get an impressive -speedup to 219 times the speed of Python. - -Note that the above code re-declares the function from ``math.h`` to -make it available to Cython code. The C compiler will see the -original declaration in ``math.h`` at compile time, but Cython -does not parse "math.h" and requires a separate definition. - -When calling C functions, one must take care to link in the appropriate -libraries. This can be platform-specific; the below example works on Linux -and Mac OS X:: - - from distutils.core import setup - from distutils.extension import Extension - from Cython.Distutils import build_ext - - ext_modules=[ - Extension("demo", - ["demo.pyx"], - libraries=["m"]) # Unix-like specific - ] - - setup( - name = "Demos", - cmdclass = {"build_ext": build_ext}, - ext_modules = ext_modules - ) - -If one uses the Sage notebook to compile Cython code, one can use a special -comment to tell Sage to link in libraries:: - - #clib: m - -Just like the ``sin()`` function from the math library, it is possible -to declare and call into any C library as long as the module that -Cython generates is properly linked against the shared or static -library. diff --git a/src/tutorial/index.rst b/src/tutorial/index.rst index d7972a60..925e46c6 100644 --- a/src/tutorial/index.rst +++ b/src/tutorial/index.rst @@ -4,7 +4,6 @@ Tutorials .. toctree:: :maxdepth: 2 - external clibraries cdef_classes pxd_files -- 2.26.2