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
604b3135
Commit
604b3135
authored
Nov 19, 2014
by
nooper
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Cython array import naming conflict
It’s not clear to know which is used Cython array or Python array.
parent
ea071f25
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
17 additions
and
17 deletions
+17
-17
docs/src/tutorial/array.rst
docs/src/tutorial/array.rst
+17
-17
No files found.
docs/src/tutorial/array.rst
View file @
604b3135
.. _array-array:
.. _array-array:
==========================
==
==========================
Working with Python arrays
Working with Python arrays
==========================
==
==========================
Python has a builtin array module supporting dynamic 1-dimensional arrays of
Python has a builtin array module supporting dynamic 1-dimensional arrays of
primitive types. It is possible to access the underlying C array of a Python
primitive types. It is possible to access the underlying C array of a Python
...
@@ -20,9 +20,9 @@ Safe usage with memory views
...
@@ -20,9 +20,9 @@ Safe usage with memory views
::
::
from cpython cimport array
from cpython cimport array
as c_array
from array import array
from array import array
cdef array.array a = array('i', [1, 2, 3])
cdef
c_
array.array a = array('i', [1, 2, 3])
cdef int[:] ca = a
cdef int[:] ca = a
print ca[0]
print ca[0]
...
@@ -36,9 +36,9 @@ memory view, there will be a slight overhead to construct the memory
...
@@ -36,9 +36,9 @@ 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
from cpython cimport array
as c_array
from array import array
from array import array
cdef array.array a = array('i', [1, 2, 3])
cdef
c_
array.array a = array('i', [1, 2, 3])
cdef int[:] ca = a
cdef int[:] ca = a
cdef int overhead(object a):
cdef int overhead(object a):
...
@@ -60,10 +60,10 @@ right type and signedness.
...
@@ -60,10 +60,10 @@ right type and signedness.
::
::
from cpython cimport array
from cpython cimport array
as c_array
from array import array
from array import array
cdef array.array a = array('i', [1, 2, 3])
cdef
c_
array.array a = array('i', [1, 2, 3])
# access underlying pointer:
# access underlying pointer:
print a.data.as_ints[0]
print a.data.as_ints[0]
...
@@ -80,14 +80,14 @@ zero when requested.
...
@@ -80,14 +80,14 @@ zero when requested.
::
::
from cpython cimport array
from cpython cimport array
as c_array
from array import array
from array import array
cdef array.array int_array_template = array('i', [])
cdef
c_
array.array int_array_template = array('i', [])
cdef array.array newarray
cdef
c_
array.array newarray
# create an array with 3 elements with same type as template
# create an array with 3 elements with same type as template
newarray = array.clone(int_array_template, 3, zero=False)
newarray =
c_
array.clone(int_array_template, 3, zero=False)
An array can also be extended and resized; this avoids repeated memory
An array can also be extended and resized; this avoids repeated memory
reallocation which would occur if elements would be appended or removed
reallocation which would occur if elements would be appended or removed
...
@@ -95,13 +95,13 @@ one by one.
...
@@ -95,13 +95,13 @@ one by one.
::
::
from cpython cimport array
from cpython cimport array
as c_array
from array import array
from array import array
cdef array.array a = array('i', [1, 2, 3])
cdef
c_
array.array a = array('i', [1, 2, 3])
cdef array.array b = array('i', [4, 5, 6])
cdef
c_
array.array b = array('i', [4, 5, 6])
# extend a with b, resize as needed
# extend a with b, resize as needed
array.extend(a, b)
c_
array.extend(a, b)
# resize a, leaving just original three elements
# resize a, leaving just original three elements
array.resize(a, len(a) - len(b))
c_
array.resize(a, len(a) - len(b))
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