Skip to content

Commit 6678890

Browse files
committed
gh-91484: Address review comments
1 parent f04156d commit 6678890

4 files changed

Lines changed: 14 additions & 5 deletions

File tree

Doc/library/stdtypes.rst

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4876,8 +4876,9 @@ copying.
48764876
Cast a memoryview to a new format or shape. *shape* defaults to
48774877
``[byte_length//new_itemsize]``, which means that the result view
48784878
will be one-dimensional. The return value is a new memoryview, but
4879-
the buffer itself is not copied. Supported casts are 1D -> C-:term:`contiguous`
4880-
and C-contiguous -> 1D.
4879+
the buffer itself is not copied. Supported casts are
4880+
1D -> C-:term:`contiguous`, C-contiguous -> 1D, and
4881+
F-contiguous -> 1D.
48814882

48824883
The destination format is restricted to a single element native format in
48834884
:mod:`struct` syntax. One of the formats must be a byte format
@@ -4964,6 +4965,10 @@ copying.
49644965
.. versionchanged:: 3.5
49654966
The source format is no longer restricted when casting to a byte view.
49664967

4968+
.. versionchanged:: next
4969+
Casting a multi-dimensional F-contiguous view to a one-dimensional
4970+
view is now supported.
4971+
49674972
.. method:: count(value, /)
49684973

49694974
Count the number of occurrences of *value*.

Doc/whatsnew/3.16.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,10 @@ New features
7575
Other language changes
7676
======================
7777

78+
* :meth:`memoryview.cast` now allows casting a multidimensional
79+
F-contiguous view to a one-dimensional view.
80+
(Contributed by Jaemin Park in :gh:`91484`.)
81+
7882
* :ref:`Frame objects <frame-objects>` now support :mod:`weak references
7983
<weakref>`. This allows associating extra data with active frames,
8084
for example in debuggers, without keeping the frames (and everything
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
memoryview.cast() now allows casting from N-D to 1-D for F-contiguous.
1+
:meth:`memoryview.cast` now allows casting from N-D to 1-D for F-contiguous.

Objects/memoryobject.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1485,9 +1485,9 @@ memoryview_cast_impl(PyMemoryViewObject *self, PyObject *format,
14851485
CHECK_RESTRICTED(self);
14861486

14871487
if (!MV_C_CONTIGUOUS(self->flags)) {
1488-
if(shape || self->view.ndim == 1 || !MV_F_CONTIGUOUS(self->flags)) {
1488+
if (shape || !MV_F_CONTIGUOUS(self->flags)) {
14891489
PyErr_SetString(PyExc_TypeError,
1490-
"memoryview: casts are restricted to C-contiguous views");
1490+
"memoryview: casts are restricted to contiguous views");
14911491
return NULL;
14921492
}
14931493
}

0 commit comments

Comments
 (0)