Commit d43ec746 authored by Stefan Behnel's avatar Stefan Behnel

Add minimal documentation for const memory views.

parent 7d9fa927
...@@ -8,10 +8,6 @@ Cython Changelog ...@@ -8,10 +8,6 @@ Cython Changelog
Features added Features added
-------------- --------------
* When compiling with gcc, the module init function is now tuned for small
code size instead of whatever compile flags were provided externally.
(Github issue #2102)
* Cdef classes can now multiply inherit from ordinary Python classes. * Cdef classes can now multiply inherit from ordinary Python classes.
(The primary base must still be a c class, possibly ``object``, and (The primary base must still be a c class, possibly ``object``, and
the other bases must *not* be cdef classes.) the other bases must *not* be cdef classes.)
...@@ -19,6 +15,15 @@ Features added ...@@ -19,6 +15,15 @@ Features added
* Type inference is now supported for Pythran compiled NumPy expressions. * Type inference is now supported for Pythran compiled NumPy expressions.
Patch by Nils Braun. (Github issue #1954) Patch by Nils Braun. (Github issue #1954)
* Read-only buffers are automatically supported for memoryviews if it can be
determined at compile time that the code does not need write access.
They can also be allowed explicitly by adding the ``const`` modifier to their
declaration. (Github issues #1605, #1869)
* When compiling with gcc, the module init function is now tuned for small
code size instead of whatever compile flags were provided externally.
(Github issue #2102)
* C file includes are moved behind the module declarations if possible, to allow * C file includes are moved behind the module declarations if possible, to allow
them to depend on module declarations themselves. them to depend on module declarations themselves.
Patch by Jeroen Demeyer. (Github issue #1896) Patch by Jeroen Demeyer. (Github issue #1896)
......
...@@ -227,6 +227,33 @@ As for NumPy, new axes can be introduced by indexing an array with ``None`` :: ...@@ -227,6 +227,33 @@ As for NumPy, new axes can be introduced by indexing an array with ``None`` ::
One may mix new axis indexing with all other forms of indexing and slicing. One may mix new axis indexing with all other forms of indexing and slicing.
See also an example_. See also an example_.
Const buffers
-------------
Since Cython 0.28, memoryviews can be declared as ``const`` to allow
read-only buffers as input::
cdef const double[:] myslice
a = np.linspace(0, 10, num=50)
a.setflags(write=False)
myslice = a
Note that this does not *require* the input to be read-only::
a = np.linspace(0, 10, num=50)
myslice = a
Writable buffers will still be accepted by ``const`` views, but read-only
buffers are not accepted for non-const, writable views.
Cython will also request a read-only view automatically if it can determine
at compile time that a writable buffer is not required. The support for
automatically distinguishing between buffer usage types, and the compile
time correctness checks for read-only views are expected to further improve
over time.
Comparison to the old buffer support Comparison to the old buffer support
==================================== ====================================
......
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