Commit 01a31397 authored by Robert Bradshaw's avatar Robert Bradshaw

minor directive edits

parent 84836476
...@@ -13,28 +13,31 @@ Cython code, unlike Python, must be compiled. This happens in two stages: ...@@ -13,28 +13,31 @@ Cython code, unlike Python, must be compiled. This happens in two stages:
* The ``.c`` file is compiled by a C compiler to a ``.so`` file (or a * The ``.c`` file is compiled by a C compiler to a ``.so`` file (or a
``.pyd`` file on Windows) ``.pyd`` file on Windows)
You can tailor the behaviour of the Cython compiler by specifying the You can tailor the behavior of the Cython compiler by specifying the
directives below. directives below.
Compiler directives Compiler directives
==================== ====================
Compiler directives are instructions which affect which sort of code Compiler directives are instructions which affect the behavior of
Cython generates. Here is the list: Cython code. Here is the list of currently supported directives:
``boundscheck`` (True / False) ``boundscheck`` (True / False)
If set to False, Cython is free to assume that indexing operations If set to False, Cython is free to assume that indexing operations
([]-operator) in the code will not cause any IndexErrors to be ([]-operator) in the code will not cause any IndexErrors to be
raised. Currently this is only made use of for buffers, but lists raised. Currently this is only made use of for buffers, lists and
and tuples could be affected in the future. Conditions which would tuples, but could be affected other types in the future. Conditions
normally trigger an IndexError may instead cause segfaults or data which would normally trigger an IndexError may instead cause
corruption if this is set to False. Default is True. segfaults or data corruption if this is set to False.
Default is True.
``wraparound`` (True / False) ``wraparound`` (True / False)
In Python arrays can be indexed relative to the end. For example In Python arrays can be indexed relative to the end. For example
A[-1] indexes the last value of a list. In C negative indexing is A[-1] indexes the last value of a list. In C negative indexing is
not supported. If set to False, Cython will not ensure that python not supported. If set to False, Cython will neither check for nor
indexing is not used. Default is True. correctly handle negative indices, possibly causing segfaults or
data corruption.
Default is True.
``nonecheck`` (True / False) ``nonecheck`` (True / False)
If set to False, Cython is free to assume that native field If set to False, Cython is free to assume that native field
...@@ -55,7 +58,7 @@ Cython generates. Here is the list: ...@@ -55,7 +58,7 @@ Cython generates. Here is the list:
If set to False, Cython will adjust the remainder and quotient If set to False, Cython will adjust the remainder and quotient
operators C types to match those of Python ints (which differ when operators C types to match those of Python ints (which differ when
the operands have opposite signs) and raise a the operands have opposite signs) and raise a
``ZeroDivisionError`` when the right operand is 0. This has about ``ZeroDivisionError`` when the right operand is 0. This has up to
a 35% speed penalty. If set to True, no checks are performed. See a 35% speed penalty. If set to True, no checks are performed. See
`CEP 516 <http://wiki.cython.org/enhancements/division>`_. Default `CEP 516 <http://wiki.cython.org/enhancements/division>`_. Default
is False. is False.
...@@ -79,7 +82,8 @@ Cython generates. Here is the list: ...@@ -79,7 +82,8 @@ Cython generates. Here is the list:
``infer_types`` (True / False) ``infer_types`` (True / False)
Infer types of untyped variables in function bodies. Default is Infer types of untyped variables in function bodies. Default is
False. None, indicating that on safe (semantically-unchanging) inferences
are allowed.
How to set directives How to set directives
--------------------- ---------------------
...@@ -108,7 +112,6 @@ Locally ...@@ -108,7 +112,6 @@ Locally
For local blocks, you need to cimport the special builtin ``cython`` For local blocks, you need to cimport the special builtin ``cython``
module:: module::
#!python
cimport cython cimport cython
Then you can use the directives either as decorators or in a with Then you can use the directives either as decorators or in a with
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment