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
6a3fc36c
Commit
6a3fc36c
authored
Jul 06, 2018
by
scoder
Committed by
GitHub
Jul 06, 2018
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #2429 from gabrieldemarmiesse/test_memoryviews_2
Added tests for "typed memoryviews" part 2
parents
b260846e
693be012
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
14 additions
and
5 deletions
+14
-5
docs/examples/userguide/memoryviews/add_one.pyx
docs/examples/userguide/memoryviews/add_one.pyx
+12
-0
docs/src/userguide/memoryviews.rst
docs/src/userguide/memoryviews.rst
+2
-5
No files found.
docs/examples/userguide/memoryviews/add_one.pyx
0 → 100644
View file @
6a3fc36c
import
numpy
as
np
def
add_one
(
int
[:,:]
buf
):
for
x
in
range
(
buf
.
shape
[
0
]):
for
y
in
range
(
buf
.
shape
[
1
]):
buf
[
x
,
y
]
+=
1
# exporting_object must be a Python object
# implementing the buffer interface, e.g. a numpy array.
exporting_object
=
np
.
zeros
((
10
,
20
),
dtype
=
np
.
intc
)
add_one
(
exporting_object
)
docs/src/userguide/memoryviews.rst
View file @
6a3fc36c
...
...
@@ -97,12 +97,9 @@ dimension::
print(buf[-1,-2])
The following function loops over each dimension of a 2D array and
adds 1 to each item:
:
adds 1 to each item:
def add_one(int[:,:] buf):
for x in xrange(buf.shape[0]):
for y in xrange(buf.shape[1]):
buf[x,y] += 1
.. literalinclude:: ../../examples/userguide/memoryviews/add_one.pyx
Indexing and slicing can be done with or without the GIL. It basically works
like NumPy. If indices are specified for every dimension you will get an element
...
...
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