From b6add9d2fdbf8ee244ceba8b5eb68bbf1dc5328f Mon Sep 17 00:00:00 2001 From: Robert Bradshaw Date: Wed, 11 Nov 2009 23:46:16 -0800 Subject: [PATCH] minor edits --HG-- rename : src/tutorial/sage.png => src/quickstart/sage.png --- src/quickstart/build.rst | 4 ++- src/quickstart/index.rst | 2 -- src/{tutorial => quickstart}/sage.png | Bin src/reference/language_basics.rst | 46 ++++++++++++-------------- src/tutorial/index.rst | 7 ---- 5 files changed, 25 insertions(+), 34 deletions(-) rename src/{tutorial => quickstart}/sage.png (100%) diff --git a/src/quickstart/build.rst b/src/quickstart/build.rst index 783d2987..770c8ed4 100644 --- a/src/quickstart/build.rst +++ b/src/quickstart/build.rst @@ -20,7 +20,7 @@ There are several ways to build Cython code: (This is mostly for debugging and experimentation.) - Use the [Sage]_ notebook which allows Cython code inline. -Currently, distutils is the most common way Cython files are built and distributed. +Currently, distutils is the most common way Cython files are built and distributed. The other methods are described in more detail in the :doc:`../reference/compilation` section of the reference manual. Building a Cython module using distutils ---------------------------------------- @@ -48,6 +48,8 @@ To build, run ``python setup.py build_ext --inplace``. Then simply start a Python session and do ``from hello import say_hello_to`` and use the imported function as you see fit. + + .. figure:: sage.png The Sage notebook allows transparently editing and compiling Cython diff --git a/src/quickstart/index.rst b/src/quickstart/index.rst index 6aaa3d06..3f2c4398 100644 --- a/src/quickstart/index.rst +++ b/src/quickstart/index.rst @@ -7,6 +7,4 @@ Getting Started overview install build - datatypes cythonize - cdef_functions diff --git a/src/tutorial/sage.png b/src/quickstart/sage.png similarity index 100% rename from src/tutorial/sage.png rename to src/quickstart/sage.png diff --git a/src/reference/language_basics.rst b/src/reference/language_basics.rst index e086f48d..d9d2e93f 100644 --- a/src/reference/language_basics.rst +++ b/src/reference/language_basics.rst @@ -14,11 +14,26 @@ Cython File Types There are three file types in cython: -* Definition files carry a ``.pxd`` suffix * Implementation files carry a ``.pyx`` suffix +* Definition files carry a ``.pxd`` suffix * Include files which carry a ``.pxi`` suffix +Implementation File +=================== + +What can it contain? +-------------------- + +* Basically anything Cythonic, but see below. + +What can't it contain? +---------------------- + +* There are some restrictions when it comes to **extension types**, if the extension type is + already defined else where... **more on this later** + + Definition File =============== @@ -52,7 +67,7 @@ cimport * Use the **cimport** statement, as you would Python's import statement, to access these files from other definition or implementation files. * **cimport** does not need to be called in ``.pyx`` file for for ``.pxd`` file that has the - same name. This is automatic. + same name, as they are already in the same namespace. * For cimport to find the stated definition file, the path to the file must be appended to the ``-I`` option of the **cython compile command**. @@ -64,21 +79,6 @@ compilation order -Implementation File -=================== - -What can it contain? --------------------- - -* Basically anything Cythonic, but see below. - -What can't it contain? ----------------------- - -* There are some restrictions when it comes to **extension types**, if the extension type is - already defined else where... **more on this later** - - Include File ============ @@ -101,12 +101,10 @@ How do I use it? Declaring Data Types ==================== -.. note:: - .. todo:: Remove paragragh As a dynamic language, Python encourages a programming style of considering classes and objects in terms of their methods and attributes, more than where they fit into the class hierarchy. -This can make Python a very relaxed and comfortable language for rapid development, but with a price - the ‘red tape’ of managing data types is dumped onto the interpreter. At run time, the interpreter does a lot of work searching namespaces, fetching attributes and parsing argument and keyword tuples. This run-time ‘late binding’ is a major cause of Python’s relative slowness compared to ‘early binding’ languages such as C++. +This can make Python a very relaxed and comfortable language for rapid development, but with a price - the 'red tape' of managing data types is dumped onto the interpreter. At run time, the interpreter does a lot of work searching namespaces, fetching attributes and parsing argument and keyword tuples. This run-time ‘late binding’ is a major cause of Python’s relative 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. @@ -288,14 +286,14 @@ Optional Arguments cpdef foo(self, x=*, int k=*) - * The number of arguments may increase when subclassing, buty the arg types and order must be the same. + * The number of arguments may increase when subclassing, but the arg types and order must be the same. * There may be a slight performance penalty when the optional arg is overridden with one that does not have default values. Keyword-only Arguments ======================= -* ``def`` functions can have keyword-only argurments listed after a ``"*"`` parameter and before a ``"**"`` parameter if any:: +* As in Python 3, ``def`` functions can have keyword-only argurments listed after a ``"*"`` parameter and before a ``"**"`` parameter if any:: def f(a, b, *args, c, d = 42, e, **kwds): ... @@ -317,7 +315,7 @@ Automatic Type Conversion * For basic numeric and string types, in most situations, when a Python object is used in the context of a C value and vice versa. -* The following table summarises the conversion possibilities: +* The following table summarises the conversion possibilities, assuming ``sizeof(int) == sizeof(long)``: +----------------------------+--------------------+------------------+ | C types | From Python types | To Python types | @@ -506,7 +504,7 @@ For-loops ... * The ``break`` and ``continue`` are permissible. -* Can contain an if-else clause. +* Can contain an else clause. ===================== Functions and Methods diff --git a/src/tutorial/index.rst b/src/tutorial/index.rst index b7b8e6e2..a5160115 100644 --- a/src/tutorial/index.rst +++ b/src/tutorial/index.rst @@ -18,10 +18,3 @@ Contents: related_work appendix - -Indices and tables ------------------- - -* :ref:`genindex` -* :ref:`modindex` -* :ref:`search` -- 2.26.2