Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 70e543b

Browse files
author
Stefan Krah
committed
Issue #23756: Clarify the terms "contiguous" and "bytes-like object".
Patch by Martin Panter.
1 parent 0c51595 commit 70e543b

4 files changed

Lines changed: 30 additions & 13 deletions

File tree

Doc/c-api/buffer.rst

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,8 @@ a buffer, see :c:func:`PyObject_GetBuffer`.
9696
block of the exporter. For example, with negative :c:member:`~Py_buffer.strides`
9797
the value may point to the end of the memory block.
9898

99-
For contiguous arrays, the value points to the beginning of the memory
100-
block.
99+
For :term:`contiguous` arrays, the value points to the beginning of
100+
the memory block.
101101

102102
.. c:member:: void \*obj
103103
@@ -281,11 +281,14 @@ of the flags below it.
281281
+-----------------------------+-------+---------+------------+
282282

283283

284+
.. index:: contiguous, C-contiguous, Fortran contiguous
285+
284286
contiguity requests
285287
~~~~~~~~~~~~~~~~~~~
286288

287-
C or Fortran contiguity can be explicitly requested, with and without stride
288-
information. Without stride information, the buffer must be C-contiguous.
289+
C or Fortran :term:`contiguity <contiguous>` can be explicitly requested,
290+
with and without stride information. Without stride information, the buffer
291+
must be C-contiguous.
289292

290293
.. tabularcolumns:: |p{0.35\linewidth}|l|l|l|l|
291294

@@ -466,13 +469,13 @@ Buffer-related functions
466469
.. c:function:: int PyBuffer_IsContiguous(Py_buffer *view, char order)
467470
468471
Return 1 if the memory defined by the *view* is C-style (*order* is
469-
``'C'``) or Fortran-style (*order* is ``'F'``) contiguous or either one
472+
``'C'``) or Fortran-style (*order* is ``'F'``) :term:`contiguous` or either one
470473
(*order* is ``'A'``). Return 0 otherwise.
471474
472475
473476
.. c:function:: void PyBuffer_FillContiguousStrides(int ndim, Py_ssize_t *shape, Py_ssize_t *strides, Py_ssize_t itemsize, char order)
474477
475-
Fill the *strides* array with byte-strides of a contiguous (C-style if
478+
Fill the *strides* array with byte-strides of a :term:`contiguous` (C-style if
476479
*order* is ``'C'`` or Fortran-style if *order* is ``'F'``) array of the
477480
given shape with the given number of bytes per element.
478481

Doc/c-api/memoryview.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ any other object.
3535
3636
.. c:function:: PyObject *PyMemoryView_GetContiguous(PyObject *obj, int buffertype, char order)
3737
38-
Create a memoryview object to a contiguous chunk of memory (in either
38+
Create a memoryview object to a :term:`contiguous` chunk of memory (in either
3939
'C' or 'F'ortran *order*) from an object that defines the buffer
4040
interface. If memory is contiguous, the memoryview object points to the
4141
original memory. Otherwise, a copy is made and the memoryview points to a

Doc/glossary.rst

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,10 @@ Glossary
109109
A :term:`text file` reads and writes :class:`str` objects.
110110

111111
bytes-like object
112-
An object that supports the :ref:`bufferobjects`, like :class:`bytes`,
113-
:class:`bytearray` or :class:`memoryview`. Bytes-like objects can
112+
An object that supports the :ref:`bufferobjects` and can
113+
export a C-:term:`contiguous` buffer. This includes all :class:`bytes`,
114+
:class:`bytearray`, and :class:`array.array` objects, as well as many
115+
common :class:`memoryview` objects. Bytes-like objects can
114116
be used for various operations that work with binary data; these include
115117
compression, saving to a binary file, and sending over a socket.
116118

@@ -169,6 +171,18 @@ Glossary
169171
statement by defining :meth:`__enter__` and :meth:`__exit__` methods.
170172
See :pep:`343`.
171173

174+
contiguous
175+
.. index:: C-contiguous, Fortran contiguous
176+
177+
A buffer is considered contiguous exactly if it is either
178+
*C-contiguous* or *Fortran contiguous*. Zero-dimensional buffers are
179+
C and Fortran contiguous. In one-dimensional arrays, the items
180+
must be layed out in memory next to each other, in order of
181+
increasing indexes starting from zero. In multidimensional
182+
C-contiguous arrays, the last index varies the fastest when
183+
visiting items in order of memory address. However, in
184+
Fortran contiguous arrays, the first index varies the fastest.
185+
172186
coroutine
173187
Coroutines is a more generalized form of subroutines. Subroutines are
174188
entered at one point and exited at another point. Coroutines can be

Doc/library/stdtypes.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3561,7 +3561,7 @@ copying.
35613561
Cast a memoryview to a new format or shape. *shape* defaults to
35623562
``[byte_length//new_itemsize]``, which means that the result view
35633563
will be one-dimensional. The return value is a new memoryview, but
3564-
the buffer itself is not copied. Supported casts are 1D -> C-contiguous
3564+
the buffer itself is not copied. Supported casts are 1D -> C-:term:`contiguous`
35653565
and C-contiguous -> 1D.
35663566

35673567
The destination format is restricted to a single element native format in
@@ -3752,19 +3752,19 @@ copying.
37523752

37533753
.. attribute:: c_contiguous
37543754

3755-
A bool indicating whether the memory is C-contiguous.
3755+
A bool indicating whether the memory is C-:term:`contiguous`.
37563756

37573757
.. versionadded:: 3.3
37583758

37593759
.. attribute:: f_contiguous
37603760

3761-
A bool indicating whether the memory is Fortran contiguous.
3761+
A bool indicating whether the memory is Fortran :term:`contiguous`.
37623762

37633763
.. versionadded:: 3.3
37643764

37653765
.. attribute:: contiguous
37663766

3767-
A bool indicating whether the memory is contiguous.
3767+
A bool indicating whether the memory is :term:`contiguous`.
37683768

37693769
.. versionadded:: 3.3
37703770

0 commit comments

Comments
 (0)