Skip to content

Commit 6d07556

Browse files
authored
Standardize formatting using black on .py files
Run `black` on `.py` files (with git-blame-ignore-revs)
2 parents b186a1c + 8a16247 commit 6d07556

19 files changed

+720
-134
lines changed

Diff for: .git-blame-ignore-revs

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Migrate code style to Black
2+
162034b12711dad54589c5dc9e75942695a7957f

Diff for: spec/API_specification/array_api/__init__.py

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
"""Function stubs and API documentation for the array API standard."""
2+
13
from .array_object import *
24
from .constants import *
35
from .creation_functions import *

Diff for: spec/API_specification/array_api/_types.py

+49-14
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,82 @@
11
"""
2-
This file defines the types for type annotations.
2+
Types for type annotations used in the array API standard.
33
44
The type variables should be replaced with the actual types for a given
55
library, e.g., for NumPy TypeVar('array') would be replaced with ndarray.
66
"""
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:
36+
"""Dataclass returned by `finfo`."""
2537
bits: int
2638
eps: float
2739
max: float
2840
min: float
2941
smallest_normal: float
3042

43+
3144
@dataclass
3245
class iinfo_object:
46+
"""Dataclass returned by `iinfo`."""
3347
bits: int
3448
max: int
3549
min: int
3650

3751

3852
_T_co = TypeVar("_T_co", covariant=True)
3953

54+
4055
class NestedSequence(Protocol[_T_co]):
41-
def __getitem__(self, key: int, /) -> Union[_T_co, NestedSequence[_T_co]]: ...
42-
def __len__(self, /) -> int: ...
56+
def __getitem__(self, key: int, /) -> Union[_T_co, NestedSequence[_T_co]]:
57+
...
58+
59+
def __len__(self, /) -> int:
60+
...
4361

4462

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

Diff for: spec/API_specification/array_api/array_object.py

+49-20
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,22 @@
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:
8-
"""
9-
Initialize the attributes for the array object class.
10-
"""
19+
"""Initialize the attributes for the array object class."""
1120

1221
@property
1322
def dtype(self: array) -> Dtype:
@@ -246,7 +255,9 @@ def __and__(self: array, other: Union[int, bool, array], /) -> array:
246255
Element-wise results must equal the results returned by the equivalent element-wise function :func:`~array_api.bitwise_and`.
247256
"""
248257

249-
def __array_namespace__(self: array, /, *, api_version: Optional[str] = None) -> Any:
258+
def __array_namespace__(
259+
self: array, /, *, api_version: Optional[str] = None
260+
) -> Any:
250261
"""
251262
Returns an object that has all the array API functions on it.
252263
@@ -298,9 +309,9 @@ def __complex__(self: array, /) -> complex:
298309
299310
- If ``self`` is ``True``, the result is ``1+0j``.
300311
- If ``self`` is ``False``, the result is ``0+0j``.
301-
312+
302313
For real-valued floating-point operands,
303-
314+
304315
- If ``self`` is ``NaN``, the result is ``NaN + NaN j``.
305316
- If ``self`` is ``+infinity``, the result is ``+infinity + 0j``.
306317
- If ``self`` is ``-infinity``, the result is ``-infinity + 0j``.
@@ -317,7 +328,9 @@ def __complex__(self: array, /) -> complex:
317328
a Python ``complex`` object representing the single element of the array instance.
318329
"""
319330

320-
def __dlpack__(self: array, /, *, stream: Optional[Union[int, Any]] = None) -> PyCapsule:
331+
def __dlpack__(
332+
self: array, /, *, stream: Optional[Union[int, Any]] = None
333+
) -> PyCapsule:
321334
"""
322335
Exports the array for consumption by :func:`~array_api.from_dlpack` as a DLPack capsule.
323336
@@ -559,7 +572,13 @@ def __ge__(self: array, other: Union[int, float, array], /) -> array:
559572
Element-wise results must equal the results returned by the equivalent element-wise function :func:`~array_api.greater_equal`.
560573
"""
561574

562-
def __getitem__(self: array, key: Union[int, slice, ellipsis, Tuple[Union[int, slice, ellipsis], ...], array], /) -> array:
575+
def __getitem__(
576+
self: array,
577+
key: Union[
578+
int, slice, ellipsis, Tuple[Union[int, slice, ellipsis], ...], array
579+
],
580+
/,
581+
) -> array:
563582
"""
564583
Returns ``self[key]``.
565584
@@ -1099,7 +1118,14 @@ def __rshift__(self: array, other: Union[int, array], /) -> array:
10991118
Element-wise results must equal the results returned by the equivalent element-wise function :func:`~array_api.bitwise_right_shift`.
11001119
"""
11011120

1102-
def __setitem__(self: array, key: Union[int, slice, ellipsis, Tuple[Union[int, slice, ellipsis], ...], array], value: Union[int, float, bool, array], /) -> None:
1121+
def __setitem__(
1122+
self: array,
1123+
key: Union[
1124+
int, slice, ellipsis, Tuple[Union[int, slice, ellipsis], ...], array
1125+
],
1126+
value: Union[int, float, bool, array],
1127+
/,
1128+
) -> None:
11031129
"""
11041130
Sets ``self[key]`` to ``value``.
11051131
@@ -1196,17 +1222,17 @@ def __truediv__(self: array, other: Union[int, float, array], /) -> array:
11961222
+------------+----------------+-----------------+--------------------------+
11971223
11981224
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-
1225+
12001226
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-
1227+
12021228
.. math::
12031229
\frac{a + bj}{c + dj} = \frac{(ac + bd) + (bc - ad)j}{c^2 + d^2}
1204-
1230+
12051231
When at least one of ``a``, ``b``, ``c``, or ``d`` is ``NaN``, ``+infinity``, or ``-infinity``,
1206-
1232+
12071233
- If ``a``, ``b``, ``c``, and ``d`` are all ``NaN``, the result is ``NaN + NaN j``.
12081234
- In the remaining cases, the result is implementation dependent.
1209-
1235+
12101236
.. note::
12111237
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.
12121238
@@ -1248,7 +1274,9 @@ def __xor__(self: array, other: Union[int, bool, array], /) -> array:
12481274
Element-wise results must equal the results returned by the equivalent element-wise function :func:`~array_api.bitwise_xor`.
12491275
"""
12501276

1251-
def to_device(self: array, device: Device, /, *, stream: Optional[Union[int, Any]] = None) -> array:
1277+
def to_device(
1278+
self: array, device: Device, /, *, stream: Optional[Union[int, Any]] = None
1279+
) -> array:
12521280
"""
12531281
Copy the array from the device on which it currently resides to the specified ``device``.
12541282
@@ -1271,6 +1299,7 @@ def to_device(self: array, device: Device, /, *, stream: Optional[Union[int, Any
12711299
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.
12721300
"""
12731301

1302+
12741303
array = _array
12751304

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

Diff for: 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)