Syntax for typing multi-dimensional arrays
Ninguém assumiu esta issue ainda.
Avaliação
- Dificuldade
- 5/5
- Tempo estimado
- Mais de uma semana
- Facilidade para iniciantes
- 25/100
- Tipo de issue
- Funcionalidade
- Clareza
- Precisa de esclarecimento
- Status de atividade
- Estagnada
- Stack de tecnologia
- numpy, python
- Domínio
- developer-experience, tooling
Direção de pesquisa
Comece pela issue sobre arrays multidimensionais maiores (#513) e pelo documento de design vinculado, especialmente sua seção “Possible syntax”. Compare as formas propostas para dtype e shape, incluindo argumentos genéricos e variádicos, e revise a discussão existente. O trabalho estará concluído quando uma sintaxe definida, que ofereça suporte aos casos opcionais e genéricos mencionados, tiver sido alcançada e documentada.
Escrita pelo modelo de indexação a partir do texto da issue.
Descrição
As part of the larger project for multi-dimensional arrays (https://github.com/python/typing/issues/513), one of the first questions I would like to settle is what syntax for typing data-types and shapes should look like.
Both dtype and shape should be optional, and it should be possible to define multi-dimensional arrays for which either or both of these are generic:
dtype: indicates the data type for array elements, e.g.,np.float64shape: indicates the shape of the multi-dimensional array, a tuple of zero or more integers. We would like to support integer and variable sized dimensions, and variable numbers of dimensions. These are most naturally represented with indexing by a variadic number of integer, variable, colon:and/or ellipsis...arguments, e.g.,NDArray[1, N, :, ...]for an array with dimensions of size 1, sizeN, and arbitrary size, followed by 0 or more arbitrary sized dimensions.
For NumPy, ideally we would like to add basic typing support for dtype (using Generic) even before typing for shape is possible. But we'd like to know what the ultimate syntax should look like, so we don't paint ourselves into a corner.
One key question: can we safely rely on using a single generic argument for dtypes (e.g., np.ndarray[np.float64]) as indicating an array without any shape constraints?
My doc (same as in the master issue) considers a number of options under the "Possible syntax" section.
So far, I think the best option is some variation of "two generic arguments", for dtype and shape. But this could quickly get annoyingly verbose when sprinkled all over a code-base, e.g., np.ndarray[np.float32, Shaped[..., N, M]]:
- It would be nice to support syntax like
np.ndarray[np.float32](the multi-dimensional equivalent ofList[float]) as an alias fornp.ndarray[np.float32, Any], but we don't yet have optional arguments for generics (variadic arguments are a somewhat awkward fit for a single argument). - It would also be nice to allow omitting
Shaped[], e.g., by writing dimensions as variadic generics to the array type likenp.ndarray[np.float32, ..., N, M]. One possible ambiguity is how to specify scalar arrays:np.ndarray[np.float32,]looks very similar tonp.ndarray[np.float32]. But scalar arrays are rare enough that these could potentially be resolved by disallowingnp.ndarray[np.float32,]in favor of requiringnp.ndarray[np.float32, Shape[()]].
- Linguagem predominante
- Python
- Estrelas
- 1.8k
- Forks
- 302
- Merge médio
- 23h
- PRs com merge (30d)
- 8
Guia de contribuição
Nenhum guia de contribuição indexado para este repositório
Primeiros passos
- Leia a issue inteira e depois o guia de contribuição do projeto.
- Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
- Faça um fork do repositório e trabalhe em uma branch.
- Abra um pull request que referencie o número da issue.
Mais de python/typing
-
topic: typing spec
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 72/100
-
topic: typing spec
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 75/100
-
topic: documentation
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 76/100
-
topic: documentation
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 65/100
-
topic: conformance tests topic: typing spec
Dificuldade 3/5 1-2 dias Facilidade para iniciantes 72/100
Todas as issues de python/typing
Issues semelhantes
-
essnmx good first issue
Dificuldade 1/5 Menos de uma hora Facilidade para iniciantes 95/100
-
[Feature] 奇物选择添加优先级 Aberta
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 65/100
syfoud/Simulated_Scepter#174 ·
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 75/100
Giskard-AI/giskard-oss#2840 · 1 comentário ·
-
A claim comment carrying the issue number is silently declined while the workflow reports success Abertaarea: repo bug perceived difficulty: 2
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 70/100
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 75/100
yeti-platform/yeti#1380 ·