Title: Typing for multi-dimensional arrays · Issue #513 · python/typing · GitHub
Open Graph Title: Typing for multi-dimensional arrays · Issue #513 · python/typing
X Title: Typing for multi-dimensional arrays · Issue #513 · python/typing
Description: I'd like to open a discussion about typing for multi-dimensional arrays in general, and more specifically for NumPy. We have already been discussing this over in the NumPy issue tracker (numpy/numpy#7370) and recently opened a new reposi...
Open Graph Description: I'd like to open a discussion about typing for multi-dimensional arrays in general, and more specifically for NumPy. We have already been discussing this over in the NumPy issue tracker (numpy/nump...
X Description: I'd like to open a discussion about typing for multi-dimensional arrays in general, and more specifically for NumPy. We have already been discussing this over in the NumPy issue tracker (numpy/...
Opengraph URL: https://github.com/python/typing/issues/513
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Typing for multi-dimensional arrays","articleBody":"I'd like to open a discussion about typing for multi-dimensional arrays in general, and more specifically for NumPy. We have already been discussing this over in the NumPy issue tracker (https://github.com/numpy/numpy/issues/7370) and recently opened a new repository to start writing type stubs (https://github.com/numpy/numpy_stubs).\r\n\r\nTo help guide discussion, I wrote a document outlining [ideas for array shape typing](https://docs.google.com/document/d/1vpMse4c6DrWH5rq2tQSx3qwP_m_0lyn-Ij4WHqQqRHY/edit#).\r\n\r\nTo summarize:\r\n- We would like to be able to type-check both data types (e.g., `float64`) and shapes (e.g., a 3x4 array) for multi-dimensional arrays.\r\n- There are many uses cases where support for checks using dimension identity would be valuable, e.g., to indicate that a function transforms an array with shape `(N, M)` to shape `(N,)` for arbitrary integers `N` and `M`. These dimension variables look very similar to `TypeVar`, if `TypeVar` supported integers as types.\r\n- A notion of \"zero or more additional dimensions\" would also be quite valuable, and is a core part of the type for many NumPy operations (generalized ufuncs). This might be naturally written with Ellipsis, e.g., `(...., N)` for an array with a last dimension of length `N` and any number of proceeding dimensions. There are particular rules (broadcasting) that should be enforced for matching multiple arguments with variable numbers of dimensions.\r\n\r\nThis will likely require some new typing features (as well as type-checker support). Notably:\r\n- Support for literal values (https://github.com/python/typing/issues/478), so we can type check operations like `array.sum(axis=0)`.\r\n- Variadic generics (https://github.com/python/typing/issues/193), we can write types like `NDArray[N]` and `NDArray[N, M]`.\r\n- Some sort of support for dimension identity in shapes (e.g., integer types, or `DimensionVar` as described in my doc).\r\n- Standard syntax for writing array dtype/shape annotations: what should these look like?","author":{"url":"https://github.com/shoyer","@type":"Person","name":"shoyer"},"datePublished":"2017-12-07T22:48:04Z","url":"https://github.com/python/typing/issues/513"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| 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:abfa410e-a8d6-1251-ee41-555ecdc65f94 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 83A6:1F3799:2BBD108:398EAFB:6B0016BC |
| html-safe-nonce | c9e89905fb27d42dce1746e83d5e1409e0f44d949206fb250cd3ec913375fd02 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4M0E2OjFGMzc5OToyQkJEMTA4OjM5OEVBRkI6NkIwMDE2QkMiLCJ2aXNpdG9yX2lkIjoiMzA1MTcxMDQ5NzY3MDgyOTc1NiIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 3d36dbd85a5f3fa5ccd4b03437438ad083c6bb7893e80d38ef4ea51fb1c90dde |
| hovercard-subject-tag | issue:280306982 |
| 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/typing/513/issue_layout |
| twitter:image | https://opengraph.githubassets.com/4bfe4754ec1c83bd1f63bbbc5d3f7b0f1da4df400789e05b353a38656ff0a9be/python/typing/issues/513 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/4bfe4754ec1c83bd1f63bbbc5d3f7b0f1da4df400789e05b353a38656ff0a9be/python/typing/issues/513 |
| og:image:alt | I'd like to open a discussion about typing for multi-dimensional arrays in general, and more specifically for NumPy. We have already been discussing this over in the NumPy issue tracker (numpy/nump... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | shoyer |
| hostname | github.com |
| expected-hostname | github.com |
| None | a2dd2291b1b13cc9c06f27ec92fa3dbaf34116fc24c9347b8539db61884c59f4 |
| turbo-cache-control | no-preview |
| go-import | github.com/python/typing git https://github.com/python/typing.git |
| octolytics-dimension-user_id | 1525981 |
| octolytics-dimension-user_login | python |
| octolytics-dimension-repository_id | 24604008 |
| octolytics-dimension-repository_nwo | python/typing |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 24604008 |
| octolytics-dimension-repository_network_root_nwo | python/typing |
| 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 | 70121d4e855ee0bb7b75cf15d061d91f8863c0f8 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width