Skip to content

Commit a7fffab

Browse files
committed
Rename file and fix rendering issues
1 parent ff0a5b0 commit a7fffab

File tree

5 files changed

+190
-145
lines changed

5 files changed

+190
-145
lines changed

spec/draft/API_specification/inspection.rst

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,36 @@ Inspection
33

44
Array API specification for namespace inspection utilities.
55

6-
A conforming implementation of the array API standard must provide and support the following functions and objects.
6+
A conforming implementation of the array API standard must provide and support the following functions and associated inspection APIs.
77

88

99
Objects in API
1010
--------------
1111

12-
.. currentmodule:: array_api
12+
.. currentmodule:: array_api.info
1313

1414
..
1515
NOTE: please keep the functions in alphabetical order
1616
1717
.. autosummary::
1818
:toctree: generated
19-
:template: attribute.rst
20-
:nosignatures:
19+
:template: method.rst
2120

2221
__array_namespace_info__
23-
Info
22+
23+
24+
Inspection APIs
25+
---------------
26+
..
27+
NOTE: please keep the methods in alphabetical order
28+
29+
30+
.. autosummary::
31+
:toctree: generated
32+
:template: method.rst
33+
34+
capabilities
35+
default_device
36+
default_dtypes
37+
devices
38+
dtypes

src/array_api_stubs/_draft/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
from . import data_types as dtype
88
from .elementwise_functions import *
99
from .indexing_functions import *
10-
from .inspection import *
1110
from .linear_algebra_functions import *
1211
from .manipulation_functions import *
1312
from .searching_functions import *
@@ -17,6 +16,7 @@
1716
from .utility_functions import *
1817
from . import linalg
1918
from . import fft
19+
from . import info
2020

2121

2222
__array_api_version__: str = "YYYY.MM"

src/array_api_stubs/_draft/_types.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@
2525
"finfo_object",
2626
"iinfo_object",
2727
"Enum",
28+
"DefaultDataTypes",
29+
"DataTypes",
30+
"Capabilities",
31+
"Info",
2832
]
2933

3034
from dataclasses import dataclass
@@ -85,6 +89,28 @@
8589
)
8690

8791

92+
@dataclass
93+
class Info:
94+
"""Namespace returned by `__array_namespace_info__`."""
95+
96+
def capabilities() -> Capabilities:
97+
...
98+
99+
def default_device() -> device:
100+
...
101+
102+
def default_dtypes(*, device: Optional[device]) -> DefaultDataTypes:
103+
...
104+
105+
def devices() -> List[device]:
106+
...
107+
108+
def dtypes(
109+
*, device: Optional[device], kind: Optional[Union[str, Tuple[str, ...]]]
110+
) -> DataTypes:
111+
...
112+
113+
88114
@dataclass
89115
class finfo_object:
90116
"""Dataclass returned by `finfo`."""

src/array_api_stubs/_draft/info.py

Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
__all__ = [
2+
"__array_namespace_info__",
3+
"capabilities",
4+
"default_device",
5+
"default_dtypes",
6+
"devices",
7+
"dtypes",
8+
]
9+
10+
from ._types import (
11+
Optional,
12+
Union,
13+
Tuple,
14+
List,
15+
device,
16+
dtype,
17+
DefaultDataTypes,
18+
DataTypes,
19+
Capabilities,
20+
Info,
21+
)
22+
23+
24+
def __array_namespace_info__() -> Info:
25+
"""
26+
Returns a namespace with Array API namespace inspection utilities.
27+
28+
Returns
29+
-------
30+
out: Info
31+
Namespace with Array API namespace inspection utilities.
32+
"""
33+
34+
35+
def capabilities() -> Capabilities:
36+
"""
37+
Returns a dictionary of array library capabilities.
38+
39+
The dictionary should contain the following keys:
40+
41+
- **boolean_indexing**: boolean indicating whether an array library supports boolean indexing.
42+
- **data_dependent_shapes**: boolean indicating whether an array library supports data-dependent output shapes.
43+
44+
Returns
45+
-------
46+
out: Capabilities
47+
a dictionary of array library capabilities.
48+
"""
49+
50+
51+
def default_device() -> device:
52+
"""
53+
Returns an object for the default device.
54+
55+
Returns
56+
-------
57+
out: device
58+
an object corresponding to the default device.
59+
"""
60+
61+
62+
def default_dtypes(
63+
*,
64+
device: Optional[device] = None,
65+
) -> DefaultDataTypes:
66+
"""
67+
Returns a dictionary containing default data types.
68+
69+
The dictionary should have the following keys:
70+
71+
- **real floating**: default real floating-point data type.
72+
- **complex floating**: default complex floating-point data type.
73+
- **integral**: default integral data type.
74+
- **indexing**: default index data type.
75+
76+
Parameters
77+
----------
78+
device: Optional[device]
79+
device for which to return default data types. If ``device`` is ``None``, the returned data types must be the default data types for the current device. If ``device`` is not ``None``, the returned data types must be default data types specific to the specified device. Default: ``None``.
80+
81+
.. note::
82+
Some array libraries have the concept of a device context manager, allowing library consumers to manage the current device context. When ``device`` is ``None``, libraries supporting a device context should return the default data types for the current device. For libraries without a context manager or supporting only a single device, those libraries should return the default data types for the default device.
83+
84+
Returns
85+
-------
86+
out: DefaultDataTypes
87+
a dictionary containing the default data type for respective data type kinds.
88+
"""
89+
90+
91+
def dtypes(
92+
*,
93+
device: Optional[device] = None,
94+
kind: Optional[Union[str, Tuple[str, ...]]] = None,
95+
) -> DataTypes:
96+
"""
97+
Returns a dictionary of supported *Array API* data types.
98+
99+
.. note::
100+
While specification-conforming array libraries may support additional data types which are not present in this specification, data types which are not present in this specification should not be included in the returned dictionary.
101+
102+
Parameters
103+
----------
104+
kind: Optional[Union[str, Tuple[str, ...]]]
105+
data type kind.
106+
107+
- If ``kind`` is ``None``, the function must return a dictionary containing all supported Array API data types.
108+
109+
- If ``kind`` is a string, the function must return a dictionary containing the data types belonging to the specified data type kind. The following data type kinds must be supported:
110+
111+
- ``'bool'``: boolean data types (e.g., ``bool``).
112+
- ``'signed integer'``: signed integer data types (e.g., ``int8``, ``int16``, ``int32``, ``int64``).
113+
- ``'unsigned integer'``: unsigned integer data types (e.g., ``uint8``, ``uint16``, ``uint32``, ``uint64``).
114+
- ``'integral'``: integer data types. Shorthand for ``('signed integer', 'unsigned integer')``.
115+
- ``'real floating'``: real-valued floating-point data types (e.g., ``float32``, ``float64``).
116+
- ``'complex floating'``: complex floating-point data types (e.g., ``complex64``, ``complex128``).
117+
- ``'numeric'``: numeric data types. Shorthand for ``('integral', 'real floating', 'complex floating')``.
118+
119+
- If ``kind`` is a tuple, the tuple specifies a union of data type kinds, and the function must return a dictionary containing the data types belonging to at least one of the specified data type kinds.
120+
121+
Default: ``None``.
122+
device: Optional[device]
123+
device for which to return supported data types. If ``device`` is ``None``, the returned data types must be the supported data types for the current device; otherwise, the returned data types must be supported data types specific to the specified device. Default: ``None``.
124+
125+
.. note::
126+
Some array libraries have the concept of a device context manager, allowing library consumers to manage the current device context. When ``device`` is ``None``, libraries supporting a device context should return the supported data types for the current device. For libraries without a context manager or supporting only a single device, those libraries should return the supported data types for the default device.
127+
128+
Returns
129+
-------
130+
out: DataTypes
131+
a dictionary containing supported data types.
132+
"""
133+
134+
135+
def devices() -> List[device]:
136+
"""
137+
Returns a list of supported devices.
138+
139+
Returns
140+
-------
141+
out: List[device]
142+
a list of supported devices.
143+
"""

src/array_api_stubs/_draft/inspection.py

Lines changed: 0 additions & 139 deletions
This file was deleted.

0 commit comments

Comments
 (0)