- ``10**-2 == 0``, instead of ``0.01`` like in Python.
- Given two typed ``int`` variables ``a`` and ``b``, ``a % b`` has the
same sign as the second argument (following Python semantics) rather than
- having the same sign as the first (as in C). The C behavior can be
- obtained, at some speed gain, by enabling the division directive.
- (Versions prior to Cython 0.12. always followed C semantics.)
+ having the same sign as the first (as in C). The C behavior can be
+ obtained, at some speed gain, by enabling the division directive
+ (versions prior to Cython 0.12 always followed C semantics).
- Care is needed with unsigned types. ``cdef unsigned n = 10;
print(range(-n, n))`` will print an empty list, since ``-n`` wraps
around to a large positive integer prior to being passed to the
``range`` function.
- Python's ``float`` type actually wraps C ``double`` values, and
- Python's ``int`` type wraps C ``long`` values.
+ Python's ``int`` type wraps C ``long`` values.
There is some speed penalty to this though (as one makes more assumptions
compile-time if the type is set to :obj:`np.ndarray`, specifically it is
-assumed that the data is stored in pure strided more and not in indirect
+assumed that the data is stored in pure strided mode and not in indirect
mode).
=======================
Profiling in Cython is controlled by a compiler directive.
-It can either be set either for an entire file or on a per function
+It can be set either for an entire file or on a per function basis
via a Cython decorator.
-Enable profiling for a complete source file
--------------------------------------------
+Enabling profiling for a complete source file
+---------------------------------------------
-Profiling is enable for a complete source file via a global directive to the
+Profiling is enabled for a complete source file via a global directive to the
Cython compiler at the top of a file::
# cython: profile=True
and complete as Python as reasonable.
-Python 3.0 Support
-==================
+Python 3 Support
+================
-Cython creates ``.c`` files that can be built and used with both
-Python 2.x and Python 3.x. In fact, compiling your module with
-Cython may very well be the easiest way to port code to Python 3.0.
-We are also working to make the compiler run in both Python 2.x and 3.0.
+Cython creates ``.c`` files that can be built and used with both
+Python 2.x and Python 3.x. In fact, compiling your module with
+Cython may very well be the easiest way to port code to Python 3.
+We are also working to make the compiler run in both Python 2.x and 3.x.
-Many Python 3 constructs are already supported by Cython.
+Many Python 3 constructs are already supported by Cython.
List/Set/Dict Comprehensions
----------------------------
-Cython supports the different comprehensions defined by Python 3.0 for
+Cython supports the different comprehensions defined by Python 3 for
lists, sets and dicts::
[expr(x) for x in A] # list
-Conditional expressions "x if b else y" (python 2.5)
+Conditional expressions "x if b else y" (Python 2.5)
=====================================================
Conditional expressions as described in
X if C else Y
-Only one of ``X`` and ``Y`` is evaluated, (depending on the value of C).
+Only one of ``X`` and ``Y`` is evaluated (depending on the value of C).
.. _inline:
>>> import helloworld
Hello World
-Congratulations! You now know how to build a Cython extension. But So Far
+Congratulations! You now know how to build a Cython extension. But so far
this example doesn't really give a feeling why one would ever want to use Cython, so
lets create a more realistic example.