diff options
| author | gabrieldemarmiesse <gabriel.demarmiesse@teraki.com> | 2018-06-15 16:04:52 +0200 |
|---|---|---|
| committer | gabrieldemarmiesse <gabriel.demarmiesse@teraki.com> | 2018-06-15 16:04:52 +0200 |
| commit | 068e381668348994534551081a3b4a7451c8a8f0 (patch) | |
| tree | 5d5aec3861088ca4b619ac82e8984f4550496d13 | |
| parent | ff577a2baf4aebacd1a2f9bebd769e05e5d05ae1 (diff) | |
| download | cython-068e381668348994534551081a3b4a7451c8a8f0.tar.gz | |
Moved the second snippet from working with python arrays to the example directory for testing.
| -rw-r--r-- | docs/examples/tutorial/array/overhead.pyx | 15 | ||||
| -rw-r--r-- | docs/src/tutorial/array.rst | 16 |
2 files changed, 17 insertions, 14 deletions
diff --git a/docs/examples/tutorial/array/overhead.pyx b/docs/examples/tutorial/array/overhead.pyx new file mode 100644 index 000000000..e385bff3f --- /dev/null +++ b/docs/examples/tutorial/array/overhead.pyx @@ -0,0 +1,15 @@ +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
diff --git a/docs/src/tutorial/array.rst b/docs/src/tutorial/array.rst index 1edb540be..2d1faf5d1 100644 --- a/docs/src/tutorial/array.rst +++ b/docs/src/tutorial/array.rst @@ -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 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 -functions without overhead, so long as it is typed:: +functions without overhead, so long as it is typed: - 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] +.. literalinclude:: ../../examples/tutorial/array/overhead.pyx - 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 --------------------------------------------- |
