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
Boxiang Sun
cython
Commits
121bd6d6
Commit
121bd6d6
authored
Jul 08, 2015
by
Stefan Behnel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
avoid using Py2 syntax in memoryview doc examples
parent
78ddf82f
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
14 additions
and
9 deletions
+14
-9
docs/src/userguide/memoryviews.rst
docs/src/userguide/memoryviews.rst
+14
-9
No files found.
docs/src/userguide/memoryviews.rst
View file @
121bd6d6
...
@@ -46,7 +46,7 @@ started with Cython memory views.
...
@@ -46,7 +46,7 @@ started with Cython memory views.
cdef int [:, :, :] 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: %s" % narr.sum()
)
# We can copy the values from one memoryview into another using a single
# We can copy the values from one memoryview into another using a single
# statement, by either indexing with ... or (NumPy-style) with a colon.
# statement, by either indexing with ... or (NumPy-style) with a colon.
...
@@ -60,7 +60,7 @@ started with Cython memory views.
...
@@ -60,7 +60,7 @@ started with Cython memory views.
cyarr_view[0, 0, 0] = 1000
cyarr_view[0, 0, 0] = 1000
# Assigning into the memoryview on the NumPy array alters the latter
# Assigning into the memoryview on the NumPy array alters the latter
print
"NumPy sum of NumPy array after assignments:", narr.sum(
)
print
("NumPy sum of NumPy array after assignments: %s" % 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 sum3d(int[:, :, :] arr) nogil:
cpdef int sum3d(int[:, :, :] arr) nogil:
...
@@ -76,11 +76,11 @@ started with Cython memory views.
...
@@ -76,11 +76,11 @@ started with Cython memory views.
# A function accepting a memoryview knows how to use a NumPy array,
# A function accepting a memoryview knows how to use a NumPy array,
# a C array, a Cython array...
# a C array, a Cython array...
print
"Memoryview sum of NumPy array is", sum3d(narr
)
print
("Memoryview sum of NumPy array is %s" % sum3d(narr)
)
print
"Memoryview sum of C array is", sum3d(carr
)
print
("Memoryview sum of C array is %s" % sum3d(carr)
)
print
"Memoryview sum of Cython array is",
sum3d(cyarr)
print
("Memoryview sum of Cython array is %s" %
sum3d(cyarr)
# ... and of course, a memoryview.
# ... and of course, a memoryview.
print
"Memoryview sum of C memoryview is", sum3d(carr_view
)
print
("Memoryview sum of C memoryview is %s" % sum3d(carr_view)
)
This code should give the following output::
This code should give the following output::
...
@@ -546,9 +546,14 @@ retrieve the original object::
...
@@ -546,9 +546,14 @@ retrieve the original object::
cdef cnp.int32_t[:] a = numpy.arange(10, dtype=numpy.int32)
cdef cnp.int32_t[:] a = numpy.arange(10, dtype=numpy.int32)
a = a[::2]
a = a[::2]
print a, numpy.asarray(a), a.base
print(a)
print(numpy.asarray(a))
print(a.base)
# this prints: <MemoryView of 'ndarray' object> [0 2 4 6 8] [0 1 2 3 4 5 6 7 8 9]
# this prints:
# <MemoryView of 'ndarray' object>
# [0 2 4 6 8]
# [0 1 2 3 4 5 6 7 8 9]
Note that this example returns the original object from which the view was
Note that this example returns the original object from which the view was
obtained, and that the view was resliced in the meantime.
obtained, and that the view was resliced in the meantime.
...
@@ -646,7 +651,7 @@ Although memoryview slices are not objects they can be set to None and they can
...
@@ -646,7 +651,7 @@ Although memoryview slices are not objects they can be set to None and they can
be be checked for being None as well::
be be checked for being None as well::
def func(double[:] myarray = None):
def func(double[:] myarray = None):
print
myarray is None
print
(myarray is None)
If the function requires real memory views as input, it is therefore best to
If the function requires real memory views as input, it is therefore best to
reject None input straight away in the signature, which is supported in Cython
reject None input straight away in the signature, which is supported in Cython
...
...
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