Skip to content

Commit

Permalink
Merge pull request #2371 from gabrieldemarmiesse/test_cython_tutorial
Browse files Browse the repository at this point in the history
Adding tests for "Basic tutorial"
  • Loading branch information
scoder committed Jun 20, 2018
2 parents 0d222d9 + 0856330 commit 5ccb742
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 35 deletions.
19 changes: 0 additions & 19 deletions docs/examples/tutorial/cython_tutorial/primes.py

This file was deleted.

14 changes: 14 additions & 0 deletions docs/examples/tutorial/cython_tutorial/primes_python.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
def primes_python(nb_primes):
p = []
n = 2
while len(p) < nb_primes:
# Is n prime?
for i in p:
if n % i == 0:
break

# If no break occurred in the loop
else:
p.append(n)
n += 1
return p
18 changes: 2 additions & 16 deletions docs/src/tutorial/cython_tutorial.rst
Original file line number Diff line number Diff line change
Expand Up @@ -263,23 +263,9 @@ just like Python does. You can deactivate those checks by using the
:ref:`compiler directives<compiler-directives>`.

Now let's see if, even if we have division checks, we obtained a boost in speed.
Let's write the same program, but Python-style::

def primes_python(nb_primes):
p = []
n = 2
while len(p) < nb_primes:
# Is n prime?
for i in p:
if n % i == 0:
break

# If no break occurred in the loop
else:
p.append(n)
n += 1
return p
Let's write the same program, but Python-style:

.. literalinclude:: ../../examples/tutorial/cython_tutorial/primes_python.py

It is also possible to take a plain ``.py`` file and to compile it with Cython.
Let's take ``primes_python``, change the function name to ``primes_python_compiled`` and
Expand Down

0 comments on commit 5ccb742

Please sign in to comment.