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
a4cac007
Commit
a4cac007
authored
May 28, 2012
by
Mark Florisson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix some last things in the memoryview docs
parent
d4e55710
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
10 additions
and
39 deletions
+10
-39
docs/src/userguide/memoryviews.rst
docs/src/userguide/memoryviews.rst
+10
-39
No files found.
docs/src/userguide/memoryviews.rst
View file @
a4cac007
.. highlight:: cython
.. highlight:: cython
.. Mark:
I noticed you often use ``slices`` to mean memoryview objects in the Cython
world, but I found that confusing, and I've changed that to ``memoryview``
or sometimes ``Cython memoryview`` or ``Cython-space memoryview``. Can you
think of something better to distiguish a Python ``memoryview`` from a
``cython.view.memoryview`` object from a ``Cython-space memoryview`` as I
have called them?
.. _memoryviews:
.. _memoryviews:
*****************
*****************
...
@@ -17,7 +8,7 @@ Typed Memoryviews
...
@@ -17,7 +8,7 @@ Typed Memoryviews
Typed memoryviews can be used for efficient access to buffers, such as NumPy
Typed memoryviews can be used for efficient access to buffers, such as NumPy
arrays, without incurring any Python overhead. Memoryviews are similar to the
arrays, without incurring any Python overhead. Memoryviews are similar to the
current numpy array buffer support (``np.ndarray[np.float64_t, ndim=2]``, but
current numpy array buffer support (``np.ndarray[np.float64_t, ndim=2]``
)
, but
they have more features and cleaner syntax.
they have more features and cleaner syntax.
Memoryviews are more general than the old numpy aray buffer support, because
Memoryviews are more general than the old numpy aray buffer support, because
...
@@ -25,10 +16,8 @@ they can handle a wider variety of sources of array data. For example, they can
...
@@ -25,10 +16,8 @@ they can handle a wider variety of sources of array data. For example, they can
handle C arrays and the Cython array type (:ref:`view_cython_arrays`).
handle C arrays and the Cython array type (:ref:`view_cython_arrays`).
A memoryview can be used in any context (function parameters, module-level, cdef
A memoryview can be used in any context (function parameters, module-level, cdef
class attribute, etc) and can be obtained from any nearly any object that
class attribute, etc) and can be obtained from nearly any object that
exposes the `PEP 3118`_ buffer interface.
exposes writable buffer through the `PEP 3118`_ buffer interface.
.. Note:: Support is experimental and new in this release, there may be bugs!
.. _view_quickstart:
.. _view_quickstart:
...
@@ -148,8 +137,6 @@ Memoryviews can be copied inplace::
...
@@ -148,8 +137,6 @@ Memoryviews can be copied inplace::
They can also be copied with the ``copy()`` and ``copy_fortran()`` methods; see
They can also be copied with the ``copy()`` and ``copy_fortran()`` methods; see
:ref:`view_copy_c_fortran`.
:ref:`view_copy_c_fortran`.
.. Note:: Copying of buffers with ``object`` as the base type is not supported yet.
.. _view_transposing:
.. _view_transposing:
Transposing
Transposing
...
@@ -163,26 +150,9 @@ Numpy slices can be transposed::
...
@@ -163,26 +150,9 @@ Numpy slices can be transposed::
This gives a new, transposed, view on the data.
This gives a new, transposed, view on the data.
.. Mark: I tried this:
Transposing requires that all dimensions of the memoryview have a
c_contig = np.arange(24).reshape((2,3,4))
cdef int [:, :, ::1] c_contig_view = c_contig
cdef int[::1, :, :] c2f = c_contig_view.T
and got:
cdef int[::1, :, :] c2f = c_contig_view.T
^
------------------------------------------------------------
mincy.pyx:75:39: Memoryview 'int[:, :, ::1]' not conformable to memoryview 'int[::contiguous, :, :]'.
Is that what you were expecting?
Transposing requires the GIL_ (you cannot use ``nogil`` in the surrounding
function call. It also requires that all dimensions of the memoryview have a
direct access memory layout (i.e., there are no indirections through pointers).
direct access memory layout (i.e., there are no indirections through pointers).
See :ref:`view_general_layouts` for
more explanation
.
See :ref:`view_general_layouts` for
details
.
Newaxis
Newaxis
-------
-------
...
@@ -267,7 +237,7 @@ Background
...
@@ -267,7 +237,7 @@ Background
The concepts are as follows: there is data access and data packing. Data access
The concepts are as follows: there is data access and data packing. Data access
means either direct (no pointer) or indirect (pointer). Data packing means your
means either direct (no pointer) or indirect (pointer). Data packing means your
data may be contiguous or not contiguous in memory, and may use *strides* to
data may be contiguous or not contiguous in memory, and may use *strides* to
identify the
data
for each dimension.
identify the
jumps in memory consecutive indices need to take
for each dimension.
Numpy arrays provide a good model of strided direct data access, so we'll use
Numpy arrays provide a good model of strided direct data access, so we'll use
them for a refresher on the concepts of C and Fortran contiguous arrays, and
them for a refresher on the concepts of C and Fortran contiguous arrays, and
...
@@ -486,9 +456,10 @@ not need the GIL::
...
@@ -486,9 +456,10 @@ not need the GIL::
cpdef int sum3d(int[:, :, :] arr) nogil:
cpdef int sum3d(int[:, :, :] arr) nogil:
...
...
In particular, you do not need the GIL for memoryview indexing or slicing.
In particular, you do not need the GIL for memoryview indexing, slicing or
Memoryviews require the GIL for copies (:ref:`view_copy_c_fortran`), and
transposing. Memoryviews require the GIL for the copy methods
transposes (:ref:`view_transposing`).
(:ref:`view_copy_c_fortran`), or when the dtype is object and an object
element is read or written.
Memoryview Objects and Cython Arrays
Memoryview Objects and Cython Arrays
====================================
====================================
...
...
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