Typing for multi-dimensional arrays
Chưa có ai nhận issue này.
- Ngôn ngữ chính
- Python
- Star
- 1.8k
- Fork
- 302
- Merge trung bình
- 23 giờ
- Pull request đã merge (30 ngày)
- 8
Mô tả
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?
Hướng dẫn đóng góp
Chưa lập chỉ mục được hướng dẫn đóng góp cho kho mã nguồn này
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Hướng nghiên cứu
Bắt đầu bằng cách đọc issue, issue NumPy được liên kết và repository numpy_stubs, sau đó xem lại tài liệu được liên kết về typing cho shape của array. So sánh các đề xuất xoay quanh các giá trị literal, variadic generics, tính đồng nhất của chiều và cú pháp annotation; issue không xác định mục tiêu triển khai cụ thể hoặc một test có thể xác lập việc hoàn thành.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Đánh giá
- Công nghệ
- numpy, python
- Lĩnh vực
- tooling
- Loại issue
- Tính năng
- Độ khó
- 5/5
- Thời gian dự kiến
- Hơn một tuần
- Mức độ hoạt động
- Đình trệ
- Độ rõ ràng
- Cần làm rõ
- Mức phù hợp với người mới
- 25/100