Skip to content

Commit 02108e0

Browse files
committed
Parse and add type signatures to all the function stubs
This only adds parameter types. Return types will be added in the next commit.
1 parent 873bc9c commit 02108e0

13 files changed

+297
-167
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
"""
2+
This file defines the types for type annotations.
3+
4+
The type variables should be replaced with the actual types for a given
5+
library, e.g., for NumPy TypeVar('array') would be replaced with ndarray.
6+
"""
7+
8+
from typing import Literal, Optional, Tuple, Union, TypeVar
9+
10+
array = TypeVar('array')
11+
device = TypeVar('device')
12+
dtype = TypeVar('dtype')
13+
14+
__all__ = ['Literal', 'Optional', 'Tuple', 'Union', 'array', 'device', 'dtype']
15+

array_api_tests/function_stubs/array_object.py

Lines changed: 28 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -14,157 +14,159 @@
1414
2. There is no real way to test that anyway.
1515
"""
1616

17-
def __abs__(x):
17+
from ._types import array
18+
19+
def __abs__(x: array):
1820
"""
1921
Note: __abs__ is a method of the array object.
2022
"""
2123
pass
2224

23-
def __add__(x1, x2):
25+
def __add__(x1: array, x2: array):
2426
"""
2527
Note: __add__ is a method of the array object.
2628
"""
2729
pass
2830

29-
def __and__(x1, x2):
31+
def __and__(x1: array, x2: array):
3032
"""
3133
Note: __and__ is a method of the array object.
3234
"""
3335
pass
3436

35-
def __eq__(x1, x2):
37+
def __eq__(x1: array, x2: array):
3638
"""
3739
Note: __eq__ is a method of the array object.
3840
"""
3941
pass
4042

41-
def __floordiv__(x1, x2):
43+
def __floordiv__(x1: array, x2: array):
4244
"""
4345
Note: __floordiv__ is a method of the array object.
4446
"""
4547
pass
4648

47-
def __ge__(x1, x2):
49+
def __ge__(x1: array, x2: array):
4850
"""
4951
Note: __ge__ is a method of the array object.
5052
"""
5153
pass
5254

53-
def __getitem__(x, key):
55+
def __ge__(x1: array, x2: array):
5456
"""
5557
Note: __getitem__ is a method of the array object.
5658
"""
5759
pass
5860

59-
def __gt__(x1, x2):
61+
def __gt__(x1: array, x2: array):
6062
"""
6163
Note: __gt__ is a method of the array object.
6264
"""
6365
pass
6466

65-
def __invert__(x):
67+
def __invert__(x: array):
6668
"""
6769
Note: __invert__ is a method of the array object.
6870
"""
6971
pass
7072

71-
def __le__(x1, x2):
73+
def __le__(x1: array, x2: array):
7274
"""
7375
Note: __le__ is a method of the array object.
7476
"""
7577
pass
7678

77-
def __len__(x):
79+
def __le__(x1: array, x2: array):
7880
"""
7981
Note: __len__ is a method of the array object.
8082
"""
8183
pass
8284

83-
def __lshift__(x1, x2):
85+
def __lshift__(x1: array, x2: array):
8486
"""
8587
Note: __lshift__ is a method of the array object.
8688
"""
8789
pass
8890

89-
def __lt__(x1, x2):
91+
def __lt__(x1: array, x2: array):
9092
"""
9193
Note: __lt__ is a method of the array object.
9294
"""
9395
pass
9496

95-
def __matmul__(x1, x2):
97+
def __matmul__(x1: array, x2: array):
9698
"""
9799
Note: __matmul__ is a method of the array object.
98100
"""
99101
pass
100102

101-
def __mod__(x1, x2):
103+
def __mod__(x1: array, x2: array):
102104
"""
103105
Note: __mod__ is a method of the array object.
104106
"""
105107
pass
106108

107-
def __mul__(x1, x2):
109+
def __mul__(x1: array, x2: array):
108110
"""
109111
Note: __mul__ is a method of the array object.
110112
"""
111113
pass
112114

113-
def __ne__(x1, x2):
115+
def __ne__(x1: array, x2: array):
114116
"""
115117
Note: __ne__ is a method of the array object.
116118
"""
117119
pass
118120

119-
def __neg__(x):
121+
def __neg__(x: array):
120122
"""
121123
Note: __neg__ is a method of the array object.
122124
"""
123125
pass
124126

125-
def __or__(x1, x2):
127+
def __or__(x1: array, x2: array):
126128
"""
127129
Note: __or__ is a method of the array object.
128130
"""
129131
pass
130132

131-
def __pos__(x):
133+
def __pos__(x: array):
132134
"""
133135
Note: __pos__ is a method of the array object.
134136
"""
135137
pass
136138

137-
def __pow__(x1, x2):
139+
def __pow__(x1: array, x2: array):
138140
"""
139141
Note: __pow__ is a method of the array object.
140142
"""
141143
pass
142144

143-
def __rshift__(x1, x2):
145+
def __rshift__(x1: array, x2: array):
144146
"""
145147
Note: __rshift__ is a method of the array object.
146148
"""
147149
pass
148150

149-
def __setitem__(x, key, value):
151+
def __rshift__(x1: array, x2: array):
150152
"""
151153
Note: __setitem__ is a method of the array object.
152154
"""
153155
pass
154156

155-
def __sub__(x1, x2):
157+
def __sub__(x1: array, x2: array):
156158
"""
157159
Note: __sub__ is a method of the array object.
158160
"""
159161
pass
160162

161-
def __truediv__(x1, x2):
163+
def __truediv__(x1: array, x2: array):
162164
"""
163165
Note: __truediv__ is a method of the array object.
164166
"""
165167
pass
166168

167-
def __xor__(x1, x2):
169+
def __xor__(x1: array, x2: array):
168170
"""
169171
Note: __xor__ is a method of the array object.
170172
"""

array_api_tests/function_stubs/constants.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
2. There is no real way to test that anyway.
1515
"""
1616

17+
1718
e = None
1819

1920
inf = None

array_api_tests/function_stubs/creation_functions.py

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,37 +14,39 @@
1414
2. There is no real way to test that anyway.
1515
"""
1616

17-
def arange(start, *, stop=None, step=1, dtype=None, device=None):
17+
from ._types import Optional, Tuple, Union, array, device, dtype
18+
19+
def arange(start: Union[int, float], *, stop: Optional[Union[int, float]] = None, step: Union[int, float] = 1, dtype: Optional[dtype] = None, device: Optional[device] = None):
1820
pass
1921

20-
def empty(shape, *, dtype=None, device=None):
22+
def empty(shape: Union[int, Tuple[int, ...]], *, dtype: Optional[dtype] = None, device: Optional[device] = None):
2123
pass
2224

23-
def empty_like(x, *, dtype=None, device=None):
25+
def empty_like(x: array, *, dtype: Optional[dtype] = None, device: Optional[device] = None):
2426
pass
2527

26-
def eye(N, *, M=None, k=0, dtype=None, device=None):
28+
def eye(N: int, *, M: Optional[int] = None, k: Optional[int] = 0, dtype: Optional[dtype] = None, device: Optional[device] = None):
2729
pass
2830

29-
def full(shape, fill_value, *, dtype=None, device=None):
31+
def full(shape: Union[int, Tuple[int, ...]], fill_value: Union[int, float], *, dtype: Optional[dtype] = None, device: Optional[device] = None):
3032
pass
3133

32-
def full_like(x, fill_value, *, dtype=None, device=None):
34+
def full_like(x: array, fill_value: Union[int, float], *, dtype: Optional[dtype] = None, device: Optional[device] = None):
3335
pass
3436

35-
def linspace(start, stop, num, *, dtype=None, device=None, endpoint=True):
37+
def linspace(start: Union[int, float], stop: Union[int, float], num: int, *, dtype: Optional[dtype] = None, device: Optional[device] = None, endpoint: Optional[bool] = True):
3638
pass
3739

38-
def ones(shape, *, dtype=None, device=None):
40+
def ones(shape: Union[int, Tuple[int, ...]], *, dtype: Optional[dtype] = None, device: Optional[device] = None):
3941
pass
4042

41-
def ones_like(x, *, dtype=None, device=None):
43+
def ones_like(x: array, *, dtype: Optional[dtype] = None, device: Optional[device] = None):
4244
pass
4345

44-
def zeros(shape, *, dtype=None, device=None):
46+
def zeros(shape: Union[int, Tuple[int, ...]], *, dtype: Optional[dtype] = None, device: Optional[device] = None):
4547
pass
4648

47-
def zeros_like(x, *, dtype=None, device=None):
49+
def zeros_like(x: array, *, dtype: Optional[dtype] = None, device: Optional[device] = None):
4850
pass
4951

5052
__all__ = ['arange', 'empty', 'empty_like', 'eye', 'full', 'full_like', 'linspace', 'ones', 'ones_like', 'zeros', 'zeros_like']

0 commit comments

Comments
 (0)