Typing for multi-dimensional arrays
還沒有人認領這個 Issue。
評估
研究方向
先閱讀 issue、連結的 NumPy issue 和 numpy_stubs repository,然後檢視連結的陣列形狀型別標註文件。比較圍繞字面值、可變參數泛型、維度識別和註解語法的提案;該 issue 沒有定義具體的實作目標,也沒有定義能夠確認完成情況的測試。
由索引模型根據 Issue 內容生成。
描述
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).
To help guide discussion, I wrote a document outlining ideas for array shape typing.
To summarize:
- 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. - 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 integersNandM. These dimension variables look very similar toTypeVar, ifTypeVarsupported integers as types. - 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 lengthNand any number of proceeding dimensions. There are particular rules (broadcasting) that should be enforced for matching multiple arguments with variable numbers of dimensions.
This will likely require some new typing features (as well as type-checker support). Notably:
- Support for literal values (https://github.com/python/typing/issues/478), so we can type check operations like
array.sum(axis=0). - Variadic generics (https://github.com/python/typing/issues/193), we can write types like
NDArray[N]andNDArray[N, M]. - Some sort of support for dimension identity in shapes (e.g., integer types, or
DimensionVaras described in my doc). - Standard syntax for writing array dtype/shape annotations: what should these look like?
- 主要語言
- Python
- 星號
- 1.8k
- 分支
- 302
- 平均合併
- 23 小時
- 30 天內合併 PR
- 8
貢獻指南
這個儲存庫沒有索引到貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
python/typing 的其他 Issue
-
topic: typing spec
難度 2/5 1-3 小時 新手友好度 72/100
-
topic: typing spec
難度 2/5 1-3 小時 新手友好度 75/100
-
topic: documentation
難度 2/5 1-3 小時 新手友好度 76/100
-
topic: documentation
難度 2/5 1-3 小時 新手友好度 65/100
-
topic: conformance tests topic: typing spec
難度 3/5 1-2 天 新手友好度 72/100
相似的 Issue
-
bug
難度 2/5 1-3 小時 新手友好度 75/100
xinnan-tech/xiaozhi-fde-talk#263 ·
-
rules
難度 1/5 1 小時以內 新手友好度 90/100
-
難度 2/5 1-3 小時 新手友好度 70/100
huggingface/Repo2RLEnv#163 · 1 則留言 ·
-
難度 1/5 1 小時以內 新手友好度 95/100
huggingface/sentence-transformers#4074 ·
-
comp/dashboard invalid P3
難度 2/5 1-3 小時 新手友好度 70/100
NousResearch/hermes-agent#121143 ·