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
Boxiang Sun
cython
Commits
1d450aaa
Commit
1d450aaa
authored
Jun 14, 2018
by
gabrieldemarmiesse
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Moved a code snippet from pure.rst to the examples directory to enable testing.
parent
5fadf79e
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
17 additions
and
15 deletions
+17
-15
docs/examples/tutorial/pure/c_arrays.py
docs/examples/tutorial/pure/c_arrays.py
+15
-0
docs/src/tutorial/pure.rst
docs/src/tutorial/pure.rst
+2
-15
No files found.
docs/examples/tutorial/pure/c_arrays.py
0 → 100644
View file @
1d450aaa
import
cython
@
cython
.
locals
(
counts
=
cython
.
int
[
10
],
digit
=
cython
.
int
)
def
count_digits
(
digits
):
"""
>>> digits = '01112222333334445667788899'
>>> count_digits(map(int, digits))
[1, 3, 4, 5, 3, 1, 2, 2, 3, 2]
"""
counts
=
[
0
]
*
10
for
digit
in
digits
:
assert
0
<=
digit
<=
9
counts
[
digit
]
+=
1
return
counts
docs/src/tutorial/pure.rst
View file @
1d450aaa
...
...
@@ -416,22 +416,9 @@ Using C arrays for fixed size lists
Since Cython 0.22, C arrays can automatically coerce to Python lists or tuples.
This can be exploited to replace fixed size Python lists in Python code by C
arrays when compiled. An example:
:
arrays when compiled. An example:
import cython
@cython.locals(counts=cython.int[10], digit=cython.int)
def count_digits(digits):
"""
>>> digits = '01112222333334445667788899'
>>> count_digits(map(int, digits))
[1, 3, 4, 5, 3, 1, 2, 2, 3, 2]
"""
counts = [0] * 10
for digit in digits:
assert 0 <= digit <= 9
counts[digit] += 1
return counts
.. literalinclude:: ../../examples/tutorial/pure/c_arrays.py
In normal Python, this will use a Python list to collect the counts, whereas
Cython will generate C code that uses a C array of C ints.
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