types-array-api 1.1.2__tar.gz → 1.1.4__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (29) hide show
  1. {types_array_api-1.1.2/src/types_array_api.egg-info → types_array_api-1.1.4}/PKG-INFO +62 -9
  2. {types_array_api-1.1.2 → types_array_api-1.1.4}/README.md +61 -8
  3. {types_array_api-1.1.2 → types_array_api-1.1.4}/pyproject.toml +2 -1
  4. {types_array_api-1.1.2 → types_array_api-1.1.4}/src/array_api/_2022_12.py +420 -31
  5. {types_array_api-1.1.2 → types_array_api-1.1.4}/src/array_api/_2023_12.py +425 -36
  6. {types_array_api-1.1.2 → types_array_api-1.1.4}/src/array_api/_2024_12.py +409 -37
  7. types_array_api-1.1.4/src/array_api/__init__.py +1 -0
  8. {types_array_api-1.1.2 → types_array_api-1.1.4}/src/array_api/_draft.py +413 -39
  9. {types_array_api-1.1.2 → types_array_api-1.1.4}/src/array_api/cli/_main.py +50 -3
  10. {types_array_api-1.1.2 → types_array_api-1.1.4/src/types_array_api.egg-info}/PKG-INFO +62 -9
  11. {types_array_api-1.1.2 → types_array_api-1.1.4}/src/types_array_api.egg-info/entry_points.txt +1 -0
  12. types_array_api-1.1.4/tests/test_main.py +42 -0
  13. types_array_api-1.1.2/src/array_api/__init__.py +0 -1
  14. types_array_api-1.1.2/tests/test_main.py +0 -25
  15. {types_array_api-1.1.2 → types_array_api-1.1.4}/LICENSE +0 -0
  16. {types_array_api-1.1.2 → types_array_api-1.1.4}/LICENSE-MIT +0 -0
  17. {types_array_api-1.1.2 → types_array_api-1.1.4}/setup.cfg +0 -0
  18. {types_array_api-1.1.2 → types_array_api-1.1.4}/setup.py +0 -0
  19. {types_array_api-1.1.2 → types_array_api-1.1.4}/src/array_api/__main__.py +0 -0
  20. {types_array_api-1.1.2 → types_array_api-1.1.4}/src/array_api/cli/__init__.py +0 -0
  21. {types_array_api-1.1.2 → types_array_api-1.1.4}/src/array_api/cli/cli.py +0 -0
  22. {types_array_api-1.1.2 → types_array_api-1.1.4}/src/array_api/py.typed +0 -0
  23. {types_array_api-1.1.2 → types_array_api-1.1.4}/src/array_api_compat/__init__.pyi +0 -0
  24. {types_array_api-1.1.2 → types_array_api-1.1.4}/src/types_array_api.egg-info/SOURCES.txt +0 -0
  25. {types_array_api-1.1.2 → types_array_api-1.1.4}/src/types_array_api.egg-info/dependency_links.txt +0 -0
  26. {types_array_api-1.1.2 → types_array_api-1.1.4}/src/types_array_api.egg-info/requires.txt +0 -0
  27. {types_array_api-1.1.2 → types_array_api-1.1.4}/src/types_array_api.egg-info/top_level.txt +0 -0
  28. {types_array_api-1.1.2 → types_array_api-1.1.4}/tests/test_cli.py +0 -0
  29. {types_array_api-1.1.2 → types_array_api-1.1.4}/tests/test_dunder_main.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: types-array-api
3
- Version: 1.1.2
3
+ Version: 1.1.4
4
4
  Summary: Typing for array API and array-api-compat
5
5
  Author-email: 34j <34j.95a2p@simplelogin.com>
6
6
  License-Expression: MIT AND Apache-2.0
@@ -83,7 +83,7 @@ pip install types-array-api
83
83
 
84
84
  ### Type stubs
85
85
 
86
- Provices type stubs for [`array-api-compat`](https://data-apis.org/array-api-compat/).
86
+ Autocompletion for [`array-api-compat`](https://data-apis.org/array-api-compat/) is available in your IDE **just by installing** this package.
87
87
 
88
88
  ```python
89
89
  import array_api_compat
@@ -94,19 +94,31 @@ xp = array_api_compat.array_namespace(x)
94
94
  ![Screenshot 1](https://raw.githubusercontent.com/34j/array-api/main/docs/_static/screenshot1.png)
95
95
  ![Screenshot 2](https://raw.githubusercontent.com/34j/array-api/main/docs/_static/screenshot2.png)
96
96
 
97
- ### Array Type
97
+ ### Typing functions using `Array`
98
98
 
99
- ```python
100
- from array_api._2024_12 import Array
99
+ There are multiple ways to type functions:
101
100
 
101
+ - ```python
102
+ from array_api._2024_12 import Array
102
103
 
103
- def my_function[TArray: Array](x: TArray) -> TArray:
104
- return x + 1
105
- ```
104
+ def simple(x: Array) -> Array:
105
+ return x + 1
106
+ ```
107
+
108
+ The simplest way to enjoy autocompletion for `Array`. This should be enough for most use cases.
109
+
110
+ - To make sure that the same type of array is returned (`ndarray`→`ndarray`, `Tensor`→`Tensor`), a `TypeVar` bound to `Array` can be used:
111
+
112
+ ```python
113
+ def generic[TArray: Array](x: TArray) -> TArray:
114
+ return x + 1
115
+ ```
116
+
117
+ ## Advanced Usage
106
118
 
107
119
  ### Namespace Type
108
120
 
109
- You can test if an object matches the Protocol by:
121
+ You can test if an object matches the Protocol as they are [`runtime-checkable`](https://docs.python.org/3/library/typing.html#typing.runtime_checkable):
110
122
 
111
123
  ```python
112
124
  import array_api_strict
@@ -120,6 +132,47 @@ assert isinstance(array_api_strict, ArrayNamespace)
120
132
  assert not isinstance(array_api_strict, ArrayNamespaceFull)
121
133
  ```
122
134
 
135
+ ### Shape Typing
136
+
137
+ - To clarify the input and output shapes, `ShapedArray` and `ShapedAnyArray` can be used:
138
+
139
+ ```python
140
+ from array_api._2024_12 import ShapedAnyArray as Array
141
+
142
+ def sum_last_axis[*TShape](x: Array[*TShape, Any]) -> Array[*TShape]:
143
+ return xp.sum(x, axis=-1)
144
+ ```
145
+
146
+ More complex example using [NewType](https://docs.python.org/3/library/typing.html#newtype) or [type aliases](https://docs.python.org/3/library/typing.html#type-aliases):
147
+
148
+ ```python
149
+ RTheta = NewType("RTheta", int)
150
+ XY = NewType("XY", int)
151
+ def polar_coordinates[*TShape](randtheta: Array[*TShape, RTheta]) -> Array[*TShape, XY]:
152
+ """Convert polar coordinates to Cartesian coordinates."""
153
+ r = randtheta[..., 0]
154
+ theta = randtheta[..., 1]
155
+ x = r * xp.cos(theta)
156
+ y = r * xp.sin(theta)
157
+ return xp.stack((x, y), axis=-1)
158
+ ```
159
+
160
+ Note that `ShapedAnyArray` exists only for **documentation purposes** and internally it is treated as `Array`.
161
+ Using both generic and shaped are impossible due to [python/typing#548](https://github.com/python/typing/issues/548).
162
+
163
+ - Note that the below example is ideal but impossible due to Python specification.
164
+
165
+ ```python
166
+ def impossible[
167
+ TDtype,
168
+ TDevice,
169
+ *TShapeFormer: int,
170
+ *TShapeLatter: int,
171
+ TArray: Array
172
+ ](x: TArray[*TShapeFormer, *TShapeLatter | Literal[1], TDtype, TDevice], y: TArray[*TShapeLatter | Literal[1], TDtype, TDevice]) -> TArray[*TShapeFormer, *TShapeLatter, TDtype, TDevice]:
173
+ return x + y # broadcasting
174
+ ```
175
+
123
176
  ## Contributors ✨
124
177
 
125
178
  Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/docs/en/emoji-key)):
@@ -52,7 +52,7 @@ pip install types-array-api
52
52
 
53
53
  ### Type stubs
54
54
 
55
- Provices type stubs for [`array-api-compat`](https://data-apis.org/array-api-compat/).
55
+ Autocompletion for [`array-api-compat`](https://data-apis.org/array-api-compat/) is available in your IDE **just by installing** this package.
56
56
 
57
57
  ```python
58
58
  import array_api_compat
@@ -63,19 +63,31 @@ xp = array_api_compat.array_namespace(x)
63
63
  ![Screenshot 1](https://raw.githubusercontent.com/34j/array-api/main/docs/_static/screenshot1.png)
64
64
  ![Screenshot 2](https://raw.githubusercontent.com/34j/array-api/main/docs/_static/screenshot2.png)
65
65
 
66
- ### Array Type
66
+ ### Typing functions using `Array`
67
67
 
68
- ```python
69
- from array_api._2024_12 import Array
68
+ There are multiple ways to type functions:
70
69
 
70
+ - ```python
71
+ from array_api._2024_12 import Array
71
72
 
72
- def my_function[TArray: Array](x: TArray) -> TArray:
73
- return x + 1
74
- ```
73
+ def simple(x: Array) -> Array:
74
+ return x + 1
75
+ ```
76
+
77
+ The simplest way to enjoy autocompletion for `Array`. This should be enough for most use cases.
78
+
79
+ - To make sure that the same type of array is returned (`ndarray`→`ndarray`, `Tensor`→`Tensor`), a `TypeVar` bound to `Array` can be used:
80
+
81
+ ```python
82
+ def generic[TArray: Array](x: TArray) -> TArray:
83
+ return x + 1
84
+ ```
85
+
86
+ ## Advanced Usage
75
87
 
76
88
  ### Namespace Type
77
89
 
78
- You can test if an object matches the Protocol by:
90
+ You can test if an object matches the Protocol as they are [`runtime-checkable`](https://docs.python.org/3/library/typing.html#typing.runtime_checkable):
79
91
 
80
92
  ```python
81
93
  import array_api_strict
@@ -89,6 +101,47 @@ assert isinstance(array_api_strict, ArrayNamespace)
89
101
  assert not isinstance(array_api_strict, ArrayNamespaceFull)
90
102
  ```
91
103
 
104
+ ### Shape Typing
105
+
106
+ - To clarify the input and output shapes, `ShapedArray` and `ShapedAnyArray` can be used:
107
+
108
+ ```python
109
+ from array_api._2024_12 import ShapedAnyArray as Array
110
+
111
+ def sum_last_axis[*TShape](x: Array[*TShape, Any]) -> Array[*TShape]:
112
+ return xp.sum(x, axis=-1)
113
+ ```
114
+
115
+ More complex example using [NewType](https://docs.python.org/3/library/typing.html#newtype) or [type aliases](https://docs.python.org/3/library/typing.html#type-aliases):
116
+
117
+ ```python
118
+ RTheta = NewType("RTheta", int)
119
+ XY = NewType("XY", int)
120
+ def polar_coordinates[*TShape](randtheta: Array[*TShape, RTheta]) -> Array[*TShape, XY]:
121
+ """Convert polar coordinates to Cartesian coordinates."""
122
+ r = randtheta[..., 0]
123
+ theta = randtheta[..., 1]
124
+ x = r * xp.cos(theta)
125
+ y = r * xp.sin(theta)
126
+ return xp.stack((x, y), axis=-1)
127
+ ```
128
+
129
+ Note that `ShapedAnyArray` exists only for **documentation purposes** and internally it is treated as `Array`.
130
+ Using both generic and shaped are impossible due to [python/typing#548](https://github.com/python/typing/issues/548).
131
+
132
+ - Note that the below example is ideal but impossible due to Python specification.
133
+
134
+ ```python
135
+ def impossible[
136
+ TDtype,
137
+ TDevice,
138
+ *TShapeFormer: int,
139
+ *TShapeLatter: int,
140
+ TArray: Array
141
+ ](x: TArray[*TShapeFormer, *TShapeLatter | Literal[1], TDtype, TDevice], y: TArray[*TShapeLatter | Literal[1], TDtype, TDevice]) -> TArray[*TShapeFormer, *TShapeLatter, TDtype, TDevice]:
142
+ return x + y # broadcasting
143
+ ```
144
+
92
145
  ## Contributors ✨
93
146
 
94
147
  Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/docs/en/emoji-key)):
@@ -4,7 +4,7 @@ requires = [ "setuptools" ]
4
4
 
5
5
  [project]
6
6
  name = "types-array-api"
7
- version = "1.1.2"
7
+ version = "1.1.4"
8
8
  description = "Typing for array API and array-api-compat"
9
9
  readme = "README.md"
10
10
  license = "MIT AND Apache-2.0"
@@ -38,6 +38,7 @@ urls.Changelog = "https://github.com/34j/types-array-api/blob/main/CHANGELOG.md"
38
38
  urls.documentation = "https://array-api.readthedocs.io"
39
39
  urls.repository = "https://github.com/34j/types-array-api"
40
40
  scripts.array-api = "array_api.cli:app"
41
+ scripts.types-array-api = "array_api.cli:app"
41
42
 
42
43
  [dependency-groups]
43
44
  dev = [