Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding tests for "Basic tutorial" #2371

Merged
merged 1 commit into from
Jun 20, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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