Title: [ENH] Support F-contiguous `memoryview`s in `cast` · Issue #91484 · python/cpython · GitHub
Open Graph Title: [ENH] Support F-contiguous `memoryview`s in `cast` · Issue #91484 · python/cpython
X Title: [ENH] Support F-contiguous `memoryview`s in `cast` · Issue #91484 · python/cpython
Description: Currently memoryview.cast requires C-contiguous data when going from N-D to 1-D. As a result F-contiguous data is not supported. Please see example below: >>> mv.c_contiguous False >>> mv.f_contiguous True >>> mv.cast("B") Traceback (mos...
Open Graph Description: Currently memoryview.cast requires C-contiguous data when going from N-D to 1-D. As a result F-contiguous data is not supported. Please see example below: >>> mv.c_contiguous False >>> mv.f_contigu...
X Description: Currently memoryview.cast requires C-contiguous data when going from N-D to 1-D. As a result F-contiguous data is not supported. Please see example below: >>> mv.c_contiguous False >>...
Opengraph URL: https://github.com/python/cpython/issues/91484
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"[ENH] Support F-contiguous `memoryview`s in `cast`","articleBody":"Currently [`memoryview.cast` requires C-contiguous data]( https://github.com/python/cpython/blob/7d8b69e1d1f125454d8cec81ff0dee72f2bef957/Objects/memoryobject.c#L1369-L1373 ) when going from N-D to 1-D. As a result F-contiguous data is not supported. Please see example below:\r\n\r\n```python\r\n\u003e\u003e\u003e mv.c_contiguous\r\nFalse\r\n\u003e\u003e\u003e mv.f_contiguous\r\nTrue\r\n\u003e\u003e\u003e mv.cast(\"B\")\r\nTraceback (most recent call last):\r\n File \"\u003cstdin\u003e\", line 1, in \u003cmodule\u003e\r\nTypeError: memoryview: casts are restricted to C-contiguous views\r\n```\r\n\r\nHowever as F-contiguous data is still contiguous and can be viewed in 1-D, it seems possible to support this type of data as well. `PickleBuffer`'s `raw` method [does appear to support both C \u0026 F contiguous data]( https://github.com/python/cpython/blob/f4c03484da59049eb62a9bf7777b963e2267d187/Objects/picklebufobject.c#L156-L161 ). Building off the example above:\r\n\r\n```python\r\n\u003e\u003e\u003e from pickle import PickleBuffer\r\n\u003e\u003e\u003e pb = PickleBuffer(mv)\r\n\u003e\u003e\u003e pb.raw()\r\n\u003cmemory at 0x1105cec70\u003e\r\n```\r\n\r\nThis would be useful when interacting with other libraries that work with this kind of data. That said, don't know if there is other context behind the C-contiguous constraint that I may be missing here.\n\n\u003c!-- gh-linked-prs --\u003e\n### Linked PRs\n* gh-137803\n\u003c!-- /gh-linked-prs --\u003e\n","author":{"url":"https://github.com/jakirkham","@type":"Person","name":"jakirkham"},"datePublished":"2022-04-12T20:39:40.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":2},"url":"https://github.com/91484/cpython/issues/91484"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:e7f95f31-0521-5ae1-50a8-4e6cb4d1fd50 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 9DDA:34E738:526BAF:6CF074:696B428B |
| html-safe-nonce | fc6343737a62154513b28e36d0aa6d52e3179bb2f188fbe28a5a98380103b07f |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5RERBOjM0RTczODo1MjZCQUY6NkNGMDc0OjY5NkI0MjhCIiwidmlzaXRvcl9pZCI6IjcwODU4NDk1ODgwMTM5NDEzODciLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 6d83ae6ec5e20e016cc3f727afeb6ff30ba3bcb5fa73ebadf1365799f11906fe |
| hovercard-subject-tag | issue:1202365244 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/python/cpython/91484/issue_layout |
| twitter:image | https://opengraph.githubassets.com/19fe5bd149b4681f73da8186d46df250c72a1a5e5182e09fc050305e93b5e456/python/cpython/issues/91484 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/19fe5bd149b4681f73da8186d46df250c72a1a5e5182e09fc050305e93b5e456/python/cpython/issues/91484 |
| og:image:alt | Currently memoryview.cast requires C-contiguous data when going from N-D to 1-D. As a result F-contiguous data is not supported. Please see example below: >>> mv.c_contiguous False >>> mv.f_contigu... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | jakirkham |
| hostname | github.com |
| expected-hostname | github.com |
| None | 5f99f7c1d70f01da5b93e5ca90303359738944d8ab470e396496262c66e60b8d |
| turbo-cache-control | no-preview |
| go-import | github.com/python/cpython git https://github.com/python/cpython.git |
| octolytics-dimension-user_id | 1525981 |
| octolytics-dimension-user_login | python |
| octolytics-dimension-repository_id | 81598961 |
| octolytics-dimension-repository_nwo | python/cpython |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 81598961 |
| octolytics-dimension-repository_network_root_nwo | python/cpython |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 82560a55c6b2054555076f46e683151ee28a19bc |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width