Commit 4171c1c0 authored by scoder's avatar scoder Committed by GitHub

Merge pull request #2434 from gabrieldemarmiesse/test_memoryviews_6

Added tests for "typed memoryviews" part 6
parents e4260c0a 96d5dbc3
import numpy as np
cdef const double[:] myslice # const item type => read-only view
a = np.linspace(0, 10, num=50)
a.setflags(write=False)
myslice = a
...@@ -161,13 +161,9 @@ Read-only views ...@@ -161,13 +161,9 @@ Read-only views
--------------- ---------------
Since Cython 0.28, the memoryview item type can be declared as ``const`` to Since Cython 0.28, the memoryview item type can be declared as ``const`` to
support read-only buffers as input:: support read-only buffers as input:
cdef const double[:] myslice # const item type => read-only view .. literalinclude:: ../../examples/userguide/memoryviews/np_flag_const.pyx
a = np.linspace(0, 10, num=50)
a.setflags(write=False)
myslice = a
Using a non-const memoryview with a binary Python string produces a runtime error. Using a non-const memoryview with a binary Python string produces a runtime error.
You can solve this issue with a ``const`` memoryview: You can solve this issue with a ``const`` memoryview:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment