Skip to content

Run black on .py files (with git-blame-ignore-revs) #575

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Dec 15, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .git-blame-ignore-revs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Migrate code style to Black
162034b12711dad54589c5dc9e75942695a7957f
2 changes: 2 additions & 0 deletions spec/API_specification/array_api/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
"""Function stubs and API documentation for the array API standard."""

from .array_object import *
from .constants import *
from .creation_functions import *
63 changes: 49 additions & 14 deletions spec/API_specification/array_api/_types.py
Original file line number Diff line number Diff line change
@@ -1,47 +1,82 @@
"""
This file defines the types for type annotations.
Types for type annotations used in the array API standard.

The type variables should be replaced with the actual types for a given
library, e.g., for NumPy TypeVar('array') would be replaced with ndarray.
"""
from __future__ import annotations

from dataclasses import dataclass
from typing import Any, List, Literal, Optional, Sequence, Tuple, TypeVar, Union, Protocol
from typing import (
Any,
List,
Literal,
Optional,
Sequence,
Tuple,
TypeVar,
Union,
Protocol,
)
from enum import Enum

array = TypeVar('array')
device = TypeVar('device')
dtype = TypeVar('dtype')
SupportsDLPack = TypeVar('SupportsDLPack')
SupportsBufferProtocol = TypeVar('SupportsBufferProtocol')
PyCapsule = TypeVar('PyCapsule')
array = TypeVar("array")
device = TypeVar("device")
dtype = TypeVar("dtype")
SupportsDLPack = TypeVar("SupportsDLPack")
SupportsBufferProtocol = TypeVar("SupportsBufferProtocol")
PyCapsule = TypeVar("PyCapsule")
# ellipsis cannot actually be imported from anywhere, so include a dummy here
# to keep pyflakes happy. https://github.com/python/typeshed/issues/3556
ellipsis = TypeVar('ellipsis')
ellipsis = TypeVar("ellipsis")


@dataclass
class finfo_object:
"""Dataclass returned by `finfo`."""
bits: int
eps: float
max: float
min: float
smallest_normal: float


@dataclass
class iinfo_object:
"""Dataclass returned by `iinfo`."""
bits: int
max: int
min: int


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


class NestedSequence(Protocol[_T_co]):
def __getitem__(self, key: int, /) -> Union[_T_co, NestedSequence[_T_co]]: ...
def __len__(self, /) -> int: ...
def __getitem__(self, key: int, /) -> Union[_T_co, NestedSequence[_T_co]]:
...

def __len__(self, /) -> int:
...


__all__ = ['Any', 'List', 'Literal', 'NestedSequence', 'Optional',
'PyCapsule', 'SupportsBufferProtocol', 'SupportsDLPack', 'Tuple', 'Union', 'Sequence',
'array', 'device', 'dtype', 'ellipsis', 'finfo_object', 'iinfo_object', 'Enum']
__all__ = [
"Any",
"List",
"Literal",
"NestedSequence",
"Optional",
"PyCapsule",
"SupportsBufferProtocol",
"SupportsDLPack",
"Tuple",
"Union",
"Sequence",
"array",
"device",
"dtype",
"ellipsis",
"finfo_object",
"iinfo_object",
"Enum",
]
69 changes: 49 additions & 20 deletions spec/API_specification/array_api/array_object.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,22 @@
from __future__ import annotations

from ._types import (array, dtype as Dtype, device as Device, Optional, Tuple,
Union, Any, PyCapsule, Enum, ellipsis)

class _array():
from ._types import (
array,
dtype as Dtype,
device as Device,
Optional,
Tuple,
Union,
Any,
PyCapsule,
Enum,
ellipsis,
)


class _array:
def __init__(self: array) -> None:
"""
Initialize the attributes for the array object class.
"""
"""Initialize the attributes for the array object class."""

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

def __array_namespace__(self: array, /, *, api_version: Optional[str] = None) -> Any:
def __array_namespace__(
self: array, /, *, api_version: Optional[str] = None
) -> Any:
"""
Returns an object that has all the array API functions on it.

@@ -298,9 +309,9 @@ def __complex__(self: array, /) -> complex:

- If ``self`` is ``True``, the result is ``1+0j``.
- If ``self`` is ``False``, the result is ``0+0j``.

For real-valued floating-point operands,

- If ``self`` is ``NaN``, the result is ``NaN + NaN j``.
- If ``self`` is ``+infinity``, the result is ``+infinity + 0j``.
- If ``self`` is ``-infinity``, the result is ``-infinity + 0j``.
@@ -317,7 +328,9 @@ def __complex__(self: array, /) -> complex:
a Python ``complex`` object representing the single element of the array instance.
"""

def __dlpack__(self: array, /, *, stream: Optional[Union[int, Any]] = None) -> PyCapsule:
def __dlpack__(
self: array, /, *, stream: Optional[Union[int, Any]] = None
) -> PyCapsule:
"""
Exports the array for consumption by :func:`~array_api.from_dlpack` as a DLPack capsule.

@@ -559,7 +572,13 @@ def __ge__(self: array, other: Union[int, float, array], /) -> array:
Element-wise results must equal the results returned by the equivalent element-wise function :func:`~array_api.greater_equal`.
"""

def __getitem__(self: array, key: Union[int, slice, ellipsis, Tuple[Union[int, slice, ellipsis], ...], array], /) -> array:
def __getitem__(
self: array,
key: Union[
int, slice, ellipsis, Tuple[Union[int, slice, ellipsis], ...], array
],
/,
) -> array:
"""
Returns ``self[key]``.

@@ -1099,7 +1118,14 @@ def __rshift__(self: array, other: Union[int, array], /) -> array:
Element-wise results must equal the results returned by the equivalent element-wise function :func:`~array_api.bitwise_right_shift`.
"""

def __setitem__(self: array, key: Union[int, slice, ellipsis, Tuple[Union[int, slice, ellipsis], ...], array], value: Union[int, float, bool, array], /) -> None:
def __setitem__(
self: array,
key: Union[
int, slice, ellipsis, Tuple[Union[int, slice, ellipsis], ...], array
],
value: Union[int, float, bool, array],
/,
) -> None:
"""
Sets ``self[key]`` to ``value``.

@@ -1196,17 +1222,17 @@ def __truediv__(self: array, other: Union[int, float, array], /) -> array:
+------------+----------------+-----------------+--------------------------+

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.

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

.. math::
\frac{a + bj}{c + dj} = \frac{(ac + bd) + (bc - ad)j}{c^2 + d^2}

When at least one of ``a``, ``b``, ``c``, or ``d`` is ``NaN``, ``+infinity``, or ``-infinity``,

- If ``a``, ``b``, ``c``, and ``d`` are all ``NaN``, the result is ``NaN + NaN j``.
- In the remaining cases, the result is implementation dependent.

.. note::
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.

@@ -1248,7 +1274,9 @@ def __xor__(self: array, other: Union[int, bool, array], /) -> array:
Element-wise results must equal the results returned by the equivalent element-wise function :func:`~array_api.bitwise_xor`.
"""

def to_device(self: array, device: Device, /, *, stream: Optional[Union[int, Any]] = None) -> array:
def to_device(
self: array, device: Device, /, *, stream: Optional[Union[int, Any]] = None
) -> array:
"""
Copy the array from the device on which it currently resides to the specified ``device``.

@@ -1271,6 +1299,7 @@ def to_device(self: array, device: Device, /, *, stream: Optional[Union[int, Any
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.
"""


array = _array

__all__ = ['array']
__all__ = ["array"]
6 changes: 3 additions & 3 deletions spec/API_specification/array_api/constants.py
Original file line number Diff line number Diff line change
@@ -5,12 +5,12 @@
``e = 2.71828182845904523536028747135266249775724709369995...``
"""

inf = float('inf')
inf = float("inf")
"""
IEEE 754 floating-point representation of (positive) infinity.
"""

nan = float('nan')
nan = float("nan")
"""
IEEE 754 floating-point representation of Not a Number (``NaN``).
"""
@@ -27,4 +27,4 @@
``pi = 3.1415926535897932384626433...``
"""

__all__ = ['e', 'inf', 'nan', 'newaxis', 'pi']
__all__ = ["e", "inf", "nan", "newaxis", "pi"]
Loading