|
5 | 5 | "NumericArray", |
6 | 6 | ) |
7 | 7 |
|
| 8 | +from pathlib import Path |
8 | 9 | from types import ModuleType |
9 | 10 | from typing import Literal, Protocol, TypeAlias |
10 | 11 | from typing_extensions import TypeVar |
|
13 | 14 |
|
14 | 15 | from ._utils import docstring_setter |
15 | 16 |
|
| 17 | +# Load docstrings from TOML file |
| 18 | +try: |
| 19 | + import tomllib |
| 20 | +except ImportError: |
| 21 | + import tomli as tomllib # type: ignore[import-not-found, no-redef] |
| 22 | + |
| 23 | +_docstrings_path = Path(__file__).parent / "_array_docstrings.toml" |
| 24 | +with _docstrings_path.open("rb") as f: |
| 25 | + _array_docstrings = tomllib.load(f)["docstrings"] |
| 26 | + |
16 | 27 | NS_co = TypeVar("NS_co", covariant=True, default=ModuleType) |
17 | 28 | InputT = TypeVar("InputT") |
18 | 29 |
|
@@ -40,302 +51,7 @@ def __array_namespace__( |
40 | 51 | ) -> NS_co: ... |
41 | 52 |
|
42 | 53 |
|
43 | | -@docstring_setter( |
44 | | - __pos__="""Evaluates `+self_i` for each element of an array instance. |
45 | | -
|
46 | | - Returns: |
47 | | - Self: An array containing the evaluated result for each element. |
48 | | - The returned array must have the same data type as self. |
49 | | -
|
50 | | - See Also: |
51 | | - array_api_typing.Positive |
52 | | -
|
53 | | - """, |
54 | | - __neg__="""Evaluates `-self_i` for each element of an array instance. |
55 | | -
|
56 | | - Returns: |
57 | | - Self: an array containing the evaluated result for each element in |
58 | | - self. The returned array must have a data type determined by Type |
59 | | - Promotion Rules. |
60 | | -
|
61 | | - See Also: |
62 | | - array_api_typing.Negative |
63 | | -
|
64 | | - """, |
65 | | - __add__="""Calculates the sum for each element of an array instance with the respective element of the array `other`. |
66 | | -
|
67 | | - Args: |
68 | | - other: addend array. Must be compatible with `self` (see |
69 | | - Broadcasting). Should have a numeric data type. |
70 | | -
|
71 | | - Returns: |
72 | | - Self: an array containing the element-wise sums. The returned array |
73 | | - must have a data type determined by Type Promotion Rules. |
74 | | -
|
75 | | - See Also: |
76 | | - array_api_typing.Add |
77 | | -
|
78 | | - """, # noqa: E501 |
79 | | - __iadd__="""Calculates the in-place sum for each element of an array instance with the respective element of the array `other`. |
80 | | -
|
81 | | - Args: |
82 | | - other: addend array. Must be compatible with `self` (see Broadcasting). Should have a numeric data type. |
83 | | -
|
84 | | - Returns: |
85 | | - Self: `self`, after performing the in-place addition. The returned array must have a data type determined by Type Promotion Rules. |
86 | | -
|
87 | | - See Also: |
88 | | - array_api_typing.Add |
89 | | -
|
90 | | - """, # noqa: E501 |
91 | | - __radd__="""Calculates the sum for each element of the array `other` with the respective element of an array instance. |
92 | | -
|
93 | | - Args: |
94 | | - other: addend array. Must be compatible with `self` (see Broadcasting). Should have a numeric data type. |
95 | | -
|
96 | | - Returns: |
97 | | - Self: an array containing the element-wise sums. The returned array must have a data type determined by Type Promotion Rules. |
98 | | -
|
99 | | - See Also: |
100 | | - array_api_typing.Add |
101 | | -
|
102 | | - """, # noqa: E501 |
103 | | - __sub__="""Calculates the difference for each element of an array instance with the respective element of the array other. |
104 | | -
|
105 | | - The result of `self_i - other_i` must be the same as `self_i + |
106 | | - (-other_i)` and must be governed by the same floating-point rules as |
107 | | - addition (see `CanArrayAdd`). |
108 | | -
|
109 | | - Args: |
110 | | - other: subtrahend array. Must be compatible with self (see |
111 | | - Broadcasting). Should have a numeric data type. |
112 | | -
|
113 | | - Returns: |
114 | | - Self: an array containing the element-wise differences. The returned |
115 | | - array must have a data type determined by Type Promotion Rules. |
116 | | -
|
117 | | - See Also: |
118 | | - array_api_typing.Subtract |
119 | | -
|
120 | | - """, # noqa: E501 |
121 | | - __isub__="""Calculates the in-place difference for each element of an array instance with the respective element of the array `other`. |
122 | | -
|
123 | | - Args: |
124 | | - other: subtrahend array. Must be compatible with `self` (see |
125 | | - Broadcasting). Should have a numeric data type. |
126 | | -
|
127 | | - Returns: |
128 | | - Self: `self`, after performing the in-place subtraction. The returned array must have a data type determined by Type Promotion Rules. |
129 | | -
|
130 | | - See Also: |
131 | | - array_api_typing.Subtract |
132 | | -
|
133 | | - """, # noqa: E501 |
134 | | - __rsub__="""Calculates the difference for each element of the array `other` with the respective element of an array instance. |
135 | | -
|
136 | | - The result of `other_i - self_i` must be the same as `other_i + (-self_i)` |
137 | | - and must be governed by the same floating-point rules as addition (see |
138 | | - `CanArrayAdd`). |
139 | | -
|
140 | | - Args: |
141 | | - other: minuend array. Must be compatible with `self` (see Broadcasting). |
142 | | - Should have a numeric data type. |
143 | | -
|
144 | | - Returns: |
145 | | - Self: an array containing the element-wise differences. The returned |
146 | | - array must have a data type determined by Type Promotion Rules. |
147 | | -
|
148 | | - See Also: |
149 | | - array_api_typing.Subtract |
150 | | -
|
151 | | - """, # noqa: E501 |
152 | | - __mul__="""Calculates the product for each element of an array instance with the respective element of the array `other`. |
153 | | -
|
154 | | - Args: |
155 | | - other: multiplicand array. Must be compatible with self (see |
156 | | - Broadcasting). Should have a numeric data type. |
157 | | -
|
158 | | - Returns: |
159 | | - Self: an array containing the element-wise products. The returned |
160 | | - array must have a data type determined by Type Promotion Rules. |
161 | | -
|
162 | | - See Also: |
163 | | - array_api_typing.Multiply |
164 | | -
|
165 | | - """, |
166 | | - __imul__="""Calculates the in-place product for each element of an array instance with the respective element of the array `other`. |
167 | | -
|
168 | | - Args: |
169 | | - other: multiplicand array. Must be compatible with `self` (see |
170 | | - Broadcasting). Should have a numeric data type. |
171 | | -
|
172 | | - Returns: |
173 | | - Self: `self`, after performing the in-place multiplication. The returned |
174 | | - array must have a data type determined by Type Promotion Rules. |
175 | | -
|
176 | | - See Also: |
177 | | - array_api_typing.Multiply |
178 | | -
|
179 | | - """, |
180 | | - __rmul__="""Calculates the product for each element of the array `other` with the respective element of an array instance. |
181 | | -
|
182 | | - Args: |
183 | | - other: multiplicand array. Must be compatible with `self` (see |
184 | | - Broadcasting). Should have a numeric data type. |
185 | | -
|
186 | | - Returns: |
187 | | - Self: an array containing the element-wise products. The returned array |
188 | | - must have a data type determined by Type Promotion Rules. |
189 | | -
|
190 | | - See Also: |
191 | | - array_api_typing.Multiply |
192 | | -
|
193 | | - """, |
194 | | - __truediv__="""Evaluates `self_i / other_i` for each element of an array instance with the respective element of the array `other`. |
195 | | -
|
196 | | - Args: |
197 | | - other: Must be compatible with `self` (see Broadcasting). Should have a |
198 | | - numeric data type. |
199 | | -
|
200 | | - Returns: |
201 | | - Self: an array containing the element-wise results. The returned array |
202 | | - should have a floating-point data type determined by Type Promotion |
203 | | - Rules. |
204 | | -
|
205 | | - See Also: |
206 | | - array_api_typing.TrueDiv |
207 | | -
|
208 | | - """, |
209 | | - __itruediv__="""Calculates the in-place quotient for each element of an array instance with the respective element of the array `other`. |
210 | | -
|
211 | | - Args: |
212 | | - other: divisor array. Must be compatible with `self` (see Broadcasting). Should have a numeric data type. |
213 | | -
|
214 | | - Returns: |
215 | | - Self: `self`, after performing the in-place true division. The returned array must have a data type determined by Type Promotion Rules. |
216 | | -
|
217 | | - See Also: |
218 | | - array_api_typing.TrueDiv |
219 | | -
|
220 | | - """, |
221 | | - __rtruediv__="""Calculates the quotient for each element of the array `other` with the respective element of an array instance. |
222 | | -
|
223 | | - Args: |
224 | | - other: dividend array. Must be compatible with `self` (see Broadcasting). Should have a numeric data type. |
225 | | -
|
226 | | - Returns: |
227 | | - Self: an array containing the element-wise quotients. The returned array must have a data type determined by Type Promotion Rules. |
228 | | -
|
229 | | - See Also: |
230 | | - array_api_typing.TrueDiv |
231 | | -
|
232 | | - """, |
233 | | - __floordiv__="""Evaluates `self_i // other_i` for each element of an array instance with the respective element of the array `other`. |
234 | | -
|
235 | | - Args: |
236 | | - other: Must be compatible with `self` (see Broadcasting). Should have a numeric data type. |
237 | | -
|
238 | | - Returns: |
239 | | - Self: an array containing the element-wise results. The returned array must have a data type determined by Type Promotion Rules. |
240 | | -
|
241 | | - See Also: |
242 | | - array_api_typing.FloorDiv |
243 | | -
|
244 | | - """, # noqa: E501 |
245 | | - __ifloordiv__="""Calculates the in-place floor division for each element of an array instance with the respective element of the array `other`. |
246 | | -
|
247 | | - Args: |
248 | | - other: divisor array. Must be compatible with `self` (see Broadcasting). Should have a numeric data type. |
249 | | -
|
250 | | - Returns: |
251 | | - Self: `self`, after performing the in-place floor division. The returned array must have a data type determined by Type Promotion Rules. |
252 | | -
|
253 | | - See Also: |
254 | | - array_api_typing.FloorDiv |
255 | | -
|
256 | | - """, # noqa: E501 |
257 | | - __rfloordiv__="""Calculates the floor division for each element of the array `other` with the respective element of an array instance. |
258 | | -
|
259 | | - Args: |
260 | | - other: dividend array. Must be compatible with `self` (see Broadcasting). Should have a numeric data type. |
261 | | -
|
262 | | - Returns: |
263 | | - Self: an array containing the element-wise floor division results. The returned array must have a data type determined by Type Promotion Rules. |
264 | | -
|
265 | | - See Also: |
266 | | - array_api_typing.FloorDiv |
267 | | -
|
268 | | - """, # noqa: E501 |
269 | | - __imod__="""Calculates the in-place remainder for each element of an array instance with the respective element of the array `other`. |
270 | | -
|
271 | | - Args: |
272 | | - other: divisor array. Must be compatible with `self` (see Broadcasting). Should have a numeric data type. |
273 | | -
|
274 | | - Returns: |
275 | | - Self: `self`, after performing the in-place modulo operation. The returned array must have a data type determined by Type Promotion Rules. |
276 | | -
|
277 | | - See Also: |
278 | | - array_api_typing.Remainder |
279 | | -
|
280 | | - """, # noqa: E501 |
281 | | - __mod__=r"""Evaluates `self_i % other_i` for each element of an array instance with the respective element of the array `other`. |
282 | | -
|
283 | | - Args: |
284 | | - other: Must be compatible with `self` (see Broadcasting). Should have a numeric data type. |
285 | | -
|
286 | | - Returns: |
287 | | - Self: an array containing the element-wise results. Each element-wise result must have the same sign as the respective element `other_i`. The returned array must have a floating-point data type determined by Type Promotion Rules. |
288 | | -
|
289 | | - See Also: |
290 | | - array_api_typing.Remainder |
291 | | -
|
292 | | - """, # noqa: E501 |
293 | | - __rmod__="""Calculates the remainder for each element of the array `other` with the respective element of an array instance. |
294 | | -
|
295 | | - Args: |
296 | | - other: dividend array. Must be compatible with `self` (see Broadcasting). Should have a numeric data type. |
297 | | -
|
298 | | - Returns: |
299 | | - Self: an array containing the element-wise remainders. The returned array must have a data type determined by Type Promotion Rules. |
300 | | -
|
301 | | - See Also: |
302 | | - array_api_typing.Remainder |
303 | | -
|
304 | | - """, # noqa: E501 |
305 | | - __pow__="""Calculates an implementation-dependent approximation of exponentiation by raising each element (the base) of an array instance to the power of `other_i` (the exponent), where `other_i` is the corresponding element of the array `other`. |
306 | | -
|
307 | | - Args: |
308 | | - other: array whose elements correspond to the exponentiation exponent. Must be compatible with `self` (see Broadcasting). Should have a numeric data type. |
309 | | -
|
310 | | - Returns: |
311 | | - Self: an array containing the element-wise results. The returned array must have a data type determined by Type Promotion Rules. |
312 | | -
|
313 | | - """, # noqa: E501 |
314 | | - __ipow__="""Calculates the in-place power for each element of an array instance with the respective element of the array `other`. |
315 | | -
|
316 | | - Args: |
317 | | - other: exponent array. Must be compatible with `self` (see Broadcasting). Should have a numeric data type. |
318 | | -
|
319 | | - Returns: |
320 | | - Self: `self`, after performing the in-place power operation. The returned array must have a data type determined by Type Promotion Rules. |
321 | | -
|
322 | | - See Also: |
323 | | - array_api_typing.Power |
324 | | -
|
325 | | - """, # noqa: E501 |
326 | | - __rpow__="""Calculates the power for each element of the array `other` raised to the respective element of an array instance. |
327 | | -
|
328 | | - Args: |
329 | | - other: base array. Must be compatible with `self` (see Broadcasting). Should have a numeric data type. |
330 | | -
|
331 | | - Returns: |
332 | | - Self: an array containing the element-wise powers. The returned array must have a data type determined by Type Promotion Rules. |
333 | | -
|
334 | | - See Also: |
335 | | - array_api_typing.Power |
336 | | -
|
337 | | - """, # noqa: E501 |
338 | | -) |
| 54 | +@docstring_setter(**_array_docstrings) |
339 | 55 | class Array( |
340 | 56 | HasArrayNamespace[NS_co], |
341 | 57 | op.CanPosSelf, |
|
0 commit comments