Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Gwenaël Samain
cython
Commits
5ccb7421
Commit
5ccb7421
authored
Jun 20, 2018
by
scoder
Committed by
GitHub
Jun 20, 2018
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #2371 from gabrieldemarmiesse/test_cython_tutorial
Adding tests for "Basic tutorial"
parents
0d222d93
08563308
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
16 additions
and
35 deletions
+16
-35
docs/examples/tutorial/cython_tutorial/primes.py
docs/examples/tutorial/cython_tutorial/primes.py
+0
-19
docs/examples/tutorial/cython_tutorial/primes_python.py
docs/examples/tutorial/cython_tutorial/primes_python.py
+14
-0
docs/src/tutorial/cython_tutorial.rst
docs/src/tutorial/cython_tutorial.rst
+2
-16
No files found.
docs/examples/tutorial/cython_tutorial/primes.py
deleted
100644 → 0
View file @
0d222d93
def
primes
(
kmax
):
result
=
[]
if
kmax
>
1000
:
kmax
=
1000
p
=
[
0
]
*
1000
k
=
0
n
=
2
while
k
<
kmax
:
i
=
0
while
i
<
k
and
n
%
p
[
i
]
!=
0
:
i
+=
1
if
i
==
k
:
p
[
k
]
=
n
k
+=
1
result
.
append
(
n
)
n
+=
1
return
result
docs/examples/tutorial/cython_tutorial/primes_python.py
0 → 100644
View file @
5ccb7421
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
docs/src/tutorial/cython_tutorial.rst
View file @
5ccb7421
...
...
@@ -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
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment