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
9359ab3f
Commit
9359ab3f
authored
Jun 27, 2012
by
Stefan Behnel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
updated array.array section in memoryview docs
parent
5a80280d
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
11 additions
and
7 deletions
+11
-7
docs/src/userguide/memoryviews.rst
docs/src/userguide/memoryviews.rst
+11
-7
No files found.
docs/src/userguide/memoryviews.rst
View file @
9359ab3f
...
...
@@ -544,20 +544,24 @@ the buffer interface natively, so memoryviews work on top of it without
additional setup.
Starting with Cython 0.17, however, it is possible to use these arrays
as buffer providers also in Python 2. This is done through explicit
typing (e.g. a cast or assignment)
as follows::
as buffer providers also in Python 2. This is done through explicit
ly
cimporting the ``cpython.array`` module
as follows::
from cpython cimport
array
cimport cpython.
array
def sum_array(array.array arr): # explicit typing required in Python 2
cdef int[:] view = arr
def sum_array(int[:] view):
"""
>>> from array import array
>>> sum_array( array('i', [1,2,3]) )
6
"""
cdef int total
for i in range(view.shape[0]):
total += view[i]
return total
Note that the
explicit typing also enables support for the old buffer
syntax for the array
type. Therefore, the following also works::
Note that the
cimport also enables the old buffer syntax for the array
type. Therefore, the following also works::
from cpython cimport array
...
...
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