From bd2a3d439fcb3832e417e9663bb11997bc32cce5 Mon Sep 17 00:00:00 2001 From: "ggellner@encolpuis" Date: Sat, 27 Sep 2008 14:35:16 -0400 Subject: [PATCH] Made cython highlighting the default in all files. --- docs/early_binding_for_speed.rst | 16 ++++++++++++---- docs/extension_types.rst | 5 +++-- docs/external_C_code.rst | 2 ++ docs/language_basics.rst | 2 ++ docs/limitations.rst | 2 ++ docs/numpy_tutorial.rst | 22 +++++++--------------- docs/overview.rst | 2 ++ docs/pyrex_differences.rst | 2 ++ docs/sharing_declarations.rst | 2 ++ docs/source_files_and_compilation.rst | 2 ++ docs/tutorial.rst | 7 ++++++- docs/wrapping_CPlusPlus.rst | 2 ++ 12 files changed, 44 insertions(+), 22 deletions(-) diff --git a/docs/early_binding_for_speed.rst b/docs/early_binding_for_speed.rst index c9db8c23..53a00a07 100644 --- a/docs/early_binding_for_speed.rst +++ b/docs/early_binding_for_speed.rst @@ -1,3 +1,5 @@ +.. highlight:: cython + .. _early-binding-speed-label: Early Binding for Speed @@ -17,7 +19,9 @@ slowness compared to 'early binding' languages such as C++. However with Cython it is possible to gain significant speed-ups through the use of 'early binding' programming techniques. -For example, consider the following (silly) code example:: +For example, consider the following (silly) code example: + +.. sourcecode:: cython cdef class Rectangle: cdef int x0, y0 @@ -38,7 +42,9 @@ In the :func:`rectArea` method, the call to :meth:`rect.area` and the :meth:`.area` method contain a lot of Python overhead. However, in Cython, it is possible to eliminate a lot of this overhead in cases -where calls occur within Cython code. For example:: +where calls occur within Cython code. For example: + +.. sourcecode:: cython cdef class Rectangle: cdef int x0, y0 @@ -71,7 +77,9 @@ Rectangle. By using this declaration, instead of just dynamically assigning to But Cython offers us more simplicity again, by allowing us to declare dual-access methods - methods that can be efficiently called at C level, but can also be accessed from pure Python code at the cost of the Python access -overheads. Consider this code:: +overheads. Consider this code: + +.. sourcecode:: cython cdef class Rectangle: cdef int x0, y0 @@ -90,7 +98,7 @@ overheads. Consider this code:: rect = Rectangle(x0, y0, x1, y1) return rect.area() -.. note:: +.. Note:: in earlier versions of Cython, the :keyword:`cpdef` keyword is :keyword:`rdef` - but has the same effect). diff --git a/docs/extension_types.rst b/docs/extension_types.rst index 95c8cb24..75ee4427 100644 --- a/docs/extension_types.rst +++ b/docs/extension_types.rst @@ -1,9 +1,10 @@ +.. highlight:: cython Extension Types =============== Introduction ------------- +------------- As well as creating normal user-defined classes with the Python class statement, Cython also lets you create new built-in Python types, known as @@ -34,7 +35,7 @@ extension types to wrap arbitrary C data structures and provide a Python-like interface to them. Attributes ----------- +----------- Attributes of an extension type are stored directly in the object's C struct. The set of attributes is fixed at compile time; you can't add attributes to an diff --git a/docs/external_C_code.rst b/docs/external_C_code.rst index d9eb91d6..fdfdaeef 100644 --- a/docs/external_C_code.rst +++ b/docs/external_C_code.rst @@ -1,3 +1,5 @@ +.. highlight:: cython + Interfacing with External C Code ================================ diff --git a/docs/language_basics.rst b/docs/language_basics.rst index d77cc999..0bbf50ea 100644 --- a/docs/language_basics.rst +++ b/docs/language_basics.rst @@ -1,3 +1,5 @@ +.. highlight:: cython + .. _language-basics-label: Language Basics diff --git a/docs/limitations.rst b/docs/limitations.rst index 8e2fbb67..363528d2 100644 --- a/docs/limitations.rst +++ b/docs/limitations.rst @@ -1,3 +1,5 @@ +.. highlight:: cython + .. _cython-limitations-label: ************* diff --git a/docs/numpy_tutorial.rst b/docs/numpy_tutorial.rst index aadbfb66..02e26d62 100644 --- a/docs/numpy_tutorial.rst +++ b/docs/numpy_tutorial.rst @@ -1,3 +1,5 @@ +.. highlight:: cython + .. _numpy_tute-label: ************************** @@ -220,9 +222,7 @@ Adding types ============= To add types we use custom Cython syntax, so we are now breaking Python source -compatibility. Here's :file:`convolve2.pyx`. *Read the comments!* - -.. code-block:: cython +compatibility. Here's :file:`convolve2.pyx`. *Read the comments!* :: from __future__ import division import numpy as np @@ -339,9 +339,7 @@ not provided then one-dimensional is assumed). More information on this syntax [:enhancements/buffer:can be found here]. -Showing the changes needed to produce :file:`convolve3.pyx` only: - -.. sourcecode:: cython +Showing the changes needed to produce :file:`convolve3.pyx` only:: ... def naive_convolve(np.ndarray[DTYPE_t, ndim=2] f, np.ndarray[DTYPE_t, ndim=2] g): @@ -374,9 +372,7 @@ The array lookups are still slowed down by two factors: 2. Negative indices are checked for and handled correctly. The code above is explicitly coded so that it doesn't use negative indices, and it (hopefully) always access within bounds. We can add a decorator to disable - bounds checking: - - .. sourcecode:: cython + bounds checking:: ... cimport cython @@ -395,9 +391,7 @@ positive, by casting the variables to unsigned integer types (if you do have negative values, then this casting will create a very large positive value instead and you will attempt to access out-of-bounds values). Casting is done with a special ``<>``-syntax. The code below is changed to use either -unsigned ints or casting as appropriate: - -.. sourcecode:: cython +unsigned ints or casting as appropriate:: ... cdef int s, t # changed @@ -456,9 +450,7 @@ function call.) More generic code ================== -It would be possible to do: - -.. sourcecode:: cython +It would be possible to do:: def naive_convolve(object[DTYPE_t, ndim=2] f, ...): diff --git a/docs/overview.rst b/docs/overview.rst index 86ad46b1..53248af8 100644 --- a/docs/overview.rst +++ b/docs/overview.rst @@ -1,3 +1,5 @@ +.. highlight:: cython + .. _overview-label: ******** diff --git a/docs/pyrex_differences.rst b/docs/pyrex_differences.rst index 20cb7371..3009699f 100644 --- a/docs/pyrex_differences.rst +++ b/docs/pyrex_differences.rst @@ -1,3 +1,5 @@ +.. highlight:: cython + Differences between Cython and Pyrex ==================================== diff --git a/docs/sharing_declarations.rst b/docs/sharing_declarations.rst index 61e08ee1..807fcfae 100644 --- a/docs/sharing_declarations.rst +++ b/docs/sharing_declarations.rst @@ -1,3 +1,5 @@ +.. highlight:: cython + .. _sharing-declarations-label: Sharing Declarations Between Cython Modules diff --git a/docs/source_files_and_compilation.rst b/docs/source_files_and_compilation.rst index fff97783..b8c7a5ad 100644 --- a/docs/source_files_and_compilation.rst +++ b/docs/source_files_and_compilation.rst @@ -1,3 +1,5 @@ +.. highlight:: cython + .. _compilation_label: **************************** diff --git a/docs/tutorial.rst b/docs/tutorial.rst index 0f66b85c..42cc9b37 100644 --- a/docs/tutorial.rst +++ b/docs/tutorial.rst @@ -1,3 +1,5 @@ +.. highlight:: cython + .. _tutorial_label: ********* @@ -107,7 +109,10 @@ Here's a small example showing some of what can be done. It's a routine for finding prime numbers. You tell it how many primes you want, and it returns them as a Python list. -:file:`primes.pyx`: :: +:file:`primes.pyx`: + +.. sourcecode:: cython + :linenos: def primes(int kmax): cdef int n, k, i diff --git a/docs/wrapping_CPlusPlus.rst b/docs/wrapping_CPlusPlus.rst index 394eb615..111a31a4 100644 --- a/docs/wrapping_CPlusPlus.rst +++ b/docs/wrapping_CPlusPlus.rst @@ -1,3 +1,5 @@ +.. highlight:: cython + .. _wrapping-cplusplus-label: Wrapping C++ Classes in Cython -- 2.26.2