Skip to content

Commit 162034b

Browse files
committed
Run black on the .py files for the API specification
1 parent d56d369 commit 162034b

17 files changed

+705
-115
lines changed

spec/API_specification/array_api/_types.py

+46-13
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,29 @@
77
from __future__ import annotations
88

99
from dataclasses import dataclass
10-
from typing import Any, List, Literal, Optional, Sequence, Tuple, TypeVar, Union, Protocol
10+
from typing import (
11+
Any,
12+
List,
13+
Literal,
14+
Optional,
15+
Sequence,
16+
Tuple,
17+
TypeVar,
18+
Union,
19+
Protocol,
20+
)
1121
from enum import Enum
1222

13-
array = TypeVar('array')
14-
device = TypeVar('device')
15-
dtype = TypeVar('dtype')
16-
SupportsDLPack = TypeVar('SupportsDLPack')
17-
SupportsBufferProtocol = TypeVar('SupportsBufferProtocol')
18-
PyCapsule = TypeVar('PyCapsule')
23+
array = TypeVar("array")
24+
device = TypeVar("device")
25+
dtype = TypeVar("dtype")
26+
SupportsDLPack = TypeVar("SupportsDLPack")
27+
SupportsBufferProtocol = TypeVar("SupportsBufferProtocol")
28+
PyCapsule = TypeVar("PyCapsule")
1929
# ellipsis cannot actually be imported from anywhere, so include a dummy here
2030
# to keep pyflakes happy. https://github.com/python/typeshed/issues/3556
21-
ellipsis = TypeVar('ellipsis')
31+
ellipsis = TypeVar("ellipsis")
32+
2233

2334
@dataclass
2435
class finfo_object:
@@ -28,6 +39,7 @@ class finfo_object:
2839
min: float
2940
smallest_normal: float
3041

42+
3143
@dataclass
3244
class iinfo_object:
3345
bits: int
@@ -37,11 +49,32 @@ class iinfo_object:
3749

3850
_T_co = TypeVar("_T_co", covariant=True)
3951

52+
4053
class NestedSequence(Protocol[_T_co]):
41-
def __getitem__(self, key: int, /) -> Union[_T_co, NestedSequence[_T_co]]: ...
42-
def __len__(self, /) -> int: ...
54+
def __getitem__(self, key: int, /) -> Union[_T_co, NestedSequence[_T_co]]:
55+
...
56+
57+
def __len__(self, /) -> int:
58+
...
4359

4460

45-
__all__ = ['Any', 'List', 'Literal', 'NestedSequence', 'Optional',
46-
'PyCapsule', 'SupportsBufferProtocol', 'SupportsDLPack', 'Tuple', 'Union', 'Sequence',
47-
'array', 'device', 'dtype', 'ellipsis', 'finfo_object', 'iinfo_object', 'Enum']
61+
__all__ = [
62+
"Any",
63+
"List",
64+
"Literal",
65+
"NestedSequence",
66+
"Optional",
67+
"PyCapsule",
68+
"SupportsBufferProtocol",
69+
"SupportsDLPack",
70+
"Tuple",
71+
"Union",
72+
"Sequence",
73+
"array",
74+
"device",
75+
"dtype",
76+
"ellipsis",
77+
"finfo_object",
78+
"iinfo_object",
79+
"Enum",
80+
]

spec/API_specification/array_api/array_object.py

+48-17
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,20 @@
11
from __future__ import annotations
22

3-
from ._types import (array, dtype as Dtype, device as Device, Optional, Tuple,
4-
Union, Any, PyCapsule, Enum, ellipsis)
5-
6-
class _array():
3+
from ._types import (
4+
array,
5+
dtype as Dtype,
6+
device as Device,
7+
Optional,
8+
Tuple,
9+
Union,
10+
Any,
11+
PyCapsule,
12+
Enum,
13+
ellipsis,
14+
)
15+
16+
17+
class _array:
718
def __init__(self: array) -> None:
819
"""
920
Initialize the attributes for the array object class.
@@ -246,7 +257,9 @@ def __and__(self: array, other: Union[int, bool, array], /) -> array:
246257
Element-wise results must equal the results returned by the equivalent element-wise function :func:`~array_api.bitwise_and`.
247258
"""
248259

249-
def __array_namespace__(self: array, /, *, api_version: Optional[str] = None) -> Any:
260+
def __array_namespace__(
261+
self: array, /, *, api_version: Optional[str] = None
262+
) -> Any:
250263
"""
251264
Returns an object that has all the array API functions on it.
252265
@@ -298,9 +311,9 @@ def __complex__(self: array, /) -> complex:
298311
299312
- If ``self`` is ``True``, the result is ``1+0j``.
300313
- If ``self`` is ``False``, the result is ``0+0j``.
301-
314+
302315
For real-valued floating-point operands,
303-
316+
304317
- If ``self`` is ``NaN``, the result is ``NaN + NaN j``.
305318
- If ``self`` is ``+infinity``, the result is ``+infinity + 0j``.
306319
- If ``self`` is ``-infinity``, the result is ``-infinity + 0j``.
@@ -317,7 +330,9 @@ def __complex__(self: array, /) -> complex:
317330
a Python ``complex`` object representing the single element of the array instance.
318331
"""
319332

320-
def __dlpack__(self: array, /, *, stream: Optional[Union[int, Any]] = None) -> PyCapsule:
333+
def __dlpack__(
334+
self: array, /, *, stream: Optional[Union[int, Any]] = None
335+
) -> PyCapsule:
321336
"""
322337
Exports the array for consumption by :func:`~array_api.from_dlpack` as a DLPack capsule.
323338
@@ -559,7 +574,13 @@ def __ge__(self: array, other: Union[int, float, array], /) -> array:
559574
Element-wise results must equal the results returned by the equivalent element-wise function :func:`~array_api.greater_equal`.
560575
"""
561576

562-
def __getitem__(self: array, key: Union[int, slice, ellipsis, Tuple[Union[int, slice, ellipsis], ...], array], /) -> array:
577+
def __getitem__(
578+
self: array,
579+
key: Union[
580+
int, slice, ellipsis, Tuple[Union[int, slice, ellipsis], ...], array
581+
],
582+
/,
583+
) -> array:
563584
"""
564585
Returns ``self[key]``.
565586
@@ -1099,7 +1120,14 @@ def __rshift__(self: array, other: Union[int, array], /) -> array:
10991120
Element-wise results must equal the results returned by the equivalent element-wise function :func:`~array_api.bitwise_right_shift`.
11001121
"""
11011122

1102-
def __setitem__(self: array, key: Union[int, slice, ellipsis, Tuple[Union[int, slice, ellipsis], ...], array], value: Union[int, float, bool, array], /) -> None:
1123+
def __setitem__(
1124+
self: array,
1125+
key: Union[
1126+
int, slice, ellipsis, Tuple[Union[int, slice, ellipsis], ...], array
1127+
],
1128+
value: Union[int, float, bool, array],
1129+
/,
1130+
) -> None:
11031131
"""
11041132
Sets ``self[key]`` to ``value``.
11051133
@@ -1196,17 +1224,17 @@ def __truediv__(self: array, other: Union[int, float, array], /) -> array:
11961224
+------------+----------------+-----------------+--------------------------+
11971225
11981226
In general, for complex floating-point operands, real-valued floating-point special cases must independently apply to the real and imaginary component operations involving real numbers as described in the above table.
1199-
1227+
12001228
When ``a``, ``b``, ``c``, or ``d`` are all finite numbers (i.e., a value other than ``NaN``, ``+infinity``, or ``-infinity``), division of complex floating-point operands should be computed as if calculated according to the textbook formula for complex number division
1201-
1229+
12021230
.. math::
12031231
\frac{a + bj}{c + dj} = \frac{(ac + bd) + (bc - ad)j}{c^2 + d^2}
1204-
1232+
12051233
When at least one of ``a``, ``b``, ``c``, or ``d`` is ``NaN``, ``+infinity``, or ``-infinity``,
1206-
1234+
12071235
- If ``a``, ``b``, ``c``, and ``d`` are all ``NaN``, the result is ``NaN + NaN j``.
12081236
- In the remaining cases, the result is implementation dependent.
1209-
1237+
12101238
.. note::
12111239
For complex floating-point operands, the results of special cases may be implementation dependent depending on how an implementation chooses to model complex numbers and complex infinity (e.g., complex plane versus Riemann sphere). For those implementations following C99 and its one-infinity model, when at least one component is infinite, even if the other component is ``NaN``, the complex value is infinite, and the usual arithmetic rules do not apply to complex-complex division. In the interest of performance, other implementations may want to avoid the complex branching logic necessary to implement the one-infinity model and choose to implement all complex-complex division according to the textbook formula. Accordingly, special case behavior is unlikely to be consistent across implementations.
12121240
@@ -1248,7 +1276,9 @@ def __xor__(self: array, other: Union[int, bool, array], /) -> array:
12481276
Element-wise results must equal the results returned by the equivalent element-wise function :func:`~array_api.bitwise_xor`.
12491277
"""
12501278

1251-
def to_device(self: array, device: Device, /, *, stream: Optional[Union[int, Any]] = None) -> array:
1279+
def to_device(
1280+
self: array, device: Device, /, *, stream: Optional[Union[int, Any]] = None
1281+
) -> array:
12521282
"""
12531283
Copy the array from the device on which it currently resides to the specified ``device``.
12541284
@@ -1271,6 +1301,7 @@ def to_device(self: array, device: Device, /, *, stream: Optional[Union[int, Any
12711301
If ``stream`` is given, the copy operation should be enqueued on the provided ``stream``; otherwise, the copy operation should be enqueued on the default stream/queue. Whether the copy is performed synchronously or asynchronously is implementation-dependent. Accordingly, if synchronization is required to guarantee data safety, this must be clearly explained in a conforming library's documentation.
12721302
"""
12731303

1304+
12741305
array = _array
12751306

1276-
__all__ = ['array']
1307+
__all__ = ["array"]

spec/API_specification/array_api/constants.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@
55
``e = 2.71828182845904523536028747135266249775724709369995...``
66
"""
77

8-
inf = float('inf')
8+
inf = float("inf")
99
"""
1010
IEEE 754 floating-point representation of (positive) infinity.
1111
"""
1212

13-
nan = float('nan')
13+
nan = float("nan")
1414
"""
1515
IEEE 754 floating-point representation of Not a Number (``NaN``).
1616
"""
@@ -27,4 +27,4 @@
2727
``pi = 3.1415926535897932384626433...``
2828
"""
2929

30-
__all__ = ['e', 'inf', 'nan', 'newaxis', 'pi']
30+
__all__ = ["e", "inf", "nan", "newaxis", "pi"]

0 commit comments

Comments
 (0)