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
Labels
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
nexedi
cython
Commits
068e3816
Commit
068e3816
authored
Jun 15, 2018
by
gabrieldemarmiesse
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Moved the second snippet from working with python arrays to the example directory for testing.
parent
ff577a2b
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
17 additions
and
14 deletions
+17
-14
docs/examples/tutorial/array/overhead.pyx
docs/examples/tutorial/array/overhead.pyx
+15
-0
docs/src/tutorial/array.rst
docs/src/tutorial/array.rst
+2
-14
No files found.
docs/examples/tutorial/array/overhead.pyx
0 → 100644
View file @
068e3816
from
cpython
cimport
array
import
array
cdef
array
.
array
a
=
array
.
array
(
'i'
,
[
1
,
2
,
3
])
cdef
int
[:]
ca
=
a
cdef
int
overhead
(
object
a
):
cdef
int
[:]
ca
=
a
return
ca
[
0
]
cdef
int
no_overhead
(
int
[:]
ca
):
return
ca
[
0
]
print
(
overhead
(
a
))
# new memory view will be constructed, overhead
print
(
no_overhead
(
ca
))
# ca is already a memory view, so no overhead
docs/src/tutorial/array.rst
View file @
068e3816
...
@@ -30,22 +30,10 @@ documentation for the `array module <http://docs.python.org/library/array.html>`
...
@@ -30,22 +30,10 @@ documentation for the `array module <http://docs.python.org/library/array.html>`
Notice that when a Python array is assigned to a variable typed as
Notice that when a Python array is assigned to a variable typed as
memory view, there will be a slight overhead to construct the memory
memory view, there will be a slight overhead to construct the memory
view. However, from that point on the variable can be passed to other
view. However, from that point on the variable can be passed to other
functions without overhead, so long as it is typed:
:
functions without overhead, so long as it is typed:
from cpython cimport array
.. literalinclude:: ../../examples/tutorial/array/overhead.pyx
import array
cdef array.array a = array.array('i', [1, 2, 3])
cdef int[:] ca = a
cdef int overhead(object a):
cdef int[:] ca = a
return ca[0]
cdef int no_overhead(int[:] ca):
return ca[0]
print(overhead(a)) # new memory view will be constructed, overhead
print(no_overhead(ca)) # ca is already a memory view, so no overhead
Zero-overhead, unsafe access to raw C pointer
Zero-overhead, unsafe access to raw C pointer
---------------------------------------------
---------------------------------------------
...
...
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