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
31eb1bbb
Commit
31eb1bbb
authored
Nov 26, 2012
by
Lars Buitinck
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
memoryviews example: use native ints, no more libc.stdint
parent
c9e9efff
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
8 additions
and
10 deletions
+8
-10
docs/src/userguide/memoryviews.rst
docs/src/userguide/memoryviews.rst
+8
-10
No files found.
docs/src/userguide/memoryviews.rst
View file @
31eb1bbb
...
@@ -28,21 +28,19 @@ Quickstart
...
@@ -28,21 +28,19 @@ Quickstart
::
::
from cython.view cimport array as cvarray
from cython.view cimport array as cvarray
from libc.stdint cimport int32_t
import numpy as np
import numpy as np
# Memoryview on a NumPy array
# Memoryview on a NumPy array
narr = np.arange(27, dtype=np.
int32
).reshape((3, 3, 3))
narr = np.arange(27, dtype=np.
dtype("i")
).reshape((3, 3, 3))
cdef int
32_t
[:, :, :] narr_view = narr
cdef int [:, :, :] narr_view = narr
# Memoryview on a C array
# Memoryview on a C array
cdef int
32_t
carr[3][3][3]
cdef int carr[3][3][3]
cdef int
32_t
[:, :, :] carr_view = carr
cdef int [:, :, :] carr_view = carr
# Memoryview on a Cython array
# Memoryview on a Cython array
cyarr = cvarray(shape=(3, 3, 3), itemsize=sizeof(int
32_t
), format="i")
cyarr = cvarray(shape=(3, 3, 3), itemsize=sizeof(int), format="i")
cdef int
32_t
[:, :, :] cyarr_view = cyarr
cdef int [:, :, :] cyarr_view = cyarr
# Show the sum of all the arrays before altering it
# Show the sum of all the arrays before altering it
print "Numpy sum of the Numpy array before assignments:", narr.sum()
print "Numpy sum of the Numpy array before assignments:", narr.sum()
...
@@ -62,8 +60,8 @@ Quickstart
...
@@ -62,8 +60,8 @@ Quickstart
print "Numpy sum of Numpy array after assignments:", narr.sum()
print "Numpy sum of Numpy array after assignments:", narr.sum()
# A function using a memoryview does not usually need the GIL
# A function using a memoryview does not usually need the GIL
cpdef int
32_t sum3d(int32_
t[:, :, :] arr) nogil:
cpdef int
sum3d(in
t[:, :, :] arr) nogil:
cdef int
32_t
total = 0
cdef int total = 0
I = arr.shape[0]
I = arr.shape[0]
J = arr.shape[1]
J = arr.shape[1]
K = arr.shape[2]
K = arr.shape[2]
...
...
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