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
Kirill Smelkov
cython
Commits
679551b3
Commit
679551b3
authored
Jun 26, 2018
by
gabrieldemarmiesse
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added an example of using python strings with const memoryviews.
parent
084a25f5
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
14 additions
and
0 deletions
+14
-0
docs/examples/userguide/memoryviews/view_string.pyx
docs/examples/userguide/memoryviews/view_string.pyx
+9
-0
docs/src/userguide/memoryviews.rst
docs/src/userguide/memoryviews.rst
+5
-0
No files found.
docs/examples/userguide/memoryviews/view_string.pyx
0 → 100644
View file @
679551b3
cdef
bint
is_y_in
(
const
unsigned
char
[:]
string_view
):
cdef
int
i
for
i
in
range
(
string_view
.
shape
[
0
]):
if
string_view
[
i
]
==
b'y'
:
return
True
return
False
print
(
is_y_in
(
b'hello world'
))
# False
print
(
is_y_in
(
b'hello Cython'
))
# True
docs/src/userguide/memoryviews.rst
View file @
679551b3
...
@@ -186,6 +186,11 @@ support read-only buffers as input::
...
@@ -186,6 +186,11 @@ support read-only buffers as input::
a.setflags(write=False)
a.setflags(write=False)
myslice = a
myslice = a
Using a non-const memoryview with a binary Python string produces a runtime error.
You can solve this issue with a ``const`` memoryview:
.. literalinclude:: ../../examples/userguide/memoryviews/view_string.pyx
Note that this does not *require* the input buffer to be read-only::
Note that this does not *require* the input buffer to be read-only::
a = np.linspace(0, 10, num=50)
a = np.linspace(0, 10, num=50)
...
...
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