Skip to content

Commit 8fc43c9

Browse files
committed
Improve data types page
This is large a reorganization to improve the readability of this page, by replacing many subheadings with tables, by removing duplication in notes, and by reorganizing content. Furthermore, the description on how dtype objects are used is extended: - add more ways in which dtype objects are used - explain that `dtype=` keywords determine output dtype and not internal/intermediate calculation dtype of arrays - cross-link type promotion rules
1 parent a902944 commit 8fc43c9

File tree

1 file changed

+79
-120
lines changed

1 file changed

+79
-120
lines changed

spec/draft/API_specification/data_types.rst

+79-120
Original file line numberDiff line numberDiff line change
@@ -5,109 +5,84 @@ Data Types
55

66
Array API specification for supported data types.
77

8-
A conforming implementation of the array API standard must provide and support the following data types.
8+
A conforming implementation of the array API standard must provide and support
9+
the following data types ("dtypes") in its array object, and as data type
10+
objects in its main namespace under the specified names:
11+
12+
+--------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
13+
| dtype object | description |
14+
+==============+============================================================================================================================================================================================+
15+
| bool | Boolean (``True`` or ``False``). |
16+
+--------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
17+
| int8 | An 8-bit signed integer whose values exist on the interval ``[-128, +127]``. |
18+
+--------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
19+
| int16 | A 16-bit signed integer whose values exist on the interval ``[−32,767, +32,767]``. |
20+
+--------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
21+
| int32 | A 32-bit signed integer whose values exist on the interval ``[−2,147,483,647, +2,147,483,647]``. |
22+
+--------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
23+
| int64 | A 64-bit signed integer whose values exist on the interval ``[−9,223,372,036,854,775,807, +9,223,372,036,854,775,807]``. |
24+
+--------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
25+
| uint8 | An 8-bit unsigned integer whose values exist on the interval ``[0, +255]``. |
26+
+--------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
27+
| uint16 | A 16-bit unsigned integer whose values exist on the interval ``[0, +65,535]``. |
28+
+--------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
29+
| uint32 | A 32-bit unsigned integer whose values exist on the interval ``[0, +4,294,967,295]``. |
30+
+--------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
31+
| uint64 | A 64-bit unsigned integer whose values exist on the interval ``[0, +18,446,744,073,709,551,615]``. |
32+
+--------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
33+
| float32 | IEEE 754 single-precision (32-bit) binary floating-point number (see IEEE 754-2019). |
34+
+--------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
35+
| float64 | IEEE 754 double-precision (64-bit) binary floating-point number (see IEEE 754-2019). |
36+
+--------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
37+
| complex64 | Single-precision (64-bit) complex floating-point number whose real and imaginary components must be IEEE 754 single-precision (32-bit) binary floating-point numbers (see IEEE 754-2019). |
38+
+--------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
39+
| complex128 | Double-precision (128-bit) complex floating-point number whose real and imaginary components must be IEEE 754 double-precision (64-bit) binary floating-point numbers (see IEEE 754-2019). |
40+
+--------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
41+
42+
Data type objects must have the following methods (no attributes are required):
943

10-
bool
11-
----
12-
13-
Boolean (``True`` or ``False``).
14-
15-
int8
16-
----
17-
18-
An 8-bit signed integer whose values exist on the interval ``[-128, +127]``.
19-
20-
int16
21-
-----
22-
23-
A 16-bit signed integer whose values exist on the interval ``[−32,767, +32,767]``.
24-
25-
int32
26-
-----
27-
28-
A 32-bit signed integer whose values exist on the interval ``[−2,147,483,647, +2,147,483,647]``.
29-
30-
int64
31-
-----
32-
33-
A 64-bit signed integer whose values exist on the interval ``[−9,223,372,036,854,775,807, +9,223,372,036,854,775,807]``.
34-
35-
uint8
36-
-----
37-
38-
An 8-bit unsigned integer whose values exist on the interval ``[0, +255]``.
39-
40-
uint16
41-
------
42-
43-
A 16-bit unsigned integer whose values exist on the interval ``[0, +65,535]``.
44-
45-
uint32
46-
------
47-
48-
A 32-bit unsigned integer whose values exist on the interval ``[0, +4,294,967,295]``.
49-
50-
uint64
51-
------
52-
53-
A 64-bit unsigned integer whose values exist on the interval ``[0, +18,446,744,073,709,551,615]``.
54-
55-
float32
56-
-------
57-
58-
IEEE 754 single-precision (32-bit) binary floating-point number (see IEEE 754-2019).
59-
60-
float64
61-
-------
44+
..
45+
NOTE: please keep the functions in alphabetical order
6246
63-
IEEE 754 double-precision (64-bit) binary floating-point number (see IEEE 754-2019).
47+
.. currentmodule:: array_api.data_types
6448

65-
complex64
66-
---------
49+
.. autosummary::
50+
:toctree: generated
51+
:template: method.rst
6752

68-
Single-precision (64-bit) complex floating-point number whose real and imaginary components must be IEEE 754 single-precision (32-bit) binary floating-point numbers (see IEEE 754-2019).
53+
__eq__
6954

70-
complex128
71-
----------
7255

73-
Double-precision (128-bit) complex floating-point number whose real and imaginary components must be IEEE 754 double-precision (64-bit) binary floating-point numbers (see IEEE 754-2019).
56+
.. note::
57+
A conforming implementation of the array API standard may provide and
58+
support additional data types beyond those described in this specification.
59+
It may also support additional methods and attributes on dtype objects.
7460

7561
.. note::
7662
IEEE 754-2019 requires support for subnormal (a.k.a., denormal) numbers, which are useful for supporting gradual underflow. However, hardware support for subnormal numbers is not universal, and many platforms (e.g., accelerators) and compilers support toggling denormals-are-zero (DAZ) and/or flush-to-zero (FTZ) behavior to increase performance and to guard against timing attacks.
7763

7864
Accordingly, subnormal behavior is left unspecified and, thus, implementation-defined. Conforming implementations may vary in their support for subnormal numbers.
7965

80-
.. note::
81-
A conforming implementation of the array API standard may provide and support additional data types beyond those described in this specification.
82-
83-
.. _data-type-objects:
8466

85-
Data Type Objects
86-
-----------------
67+
Use of data type objects
68+
------------------------
8769

88-
Data types ("dtypes") are objects which are used as ``dtype`` specifiers in functions and methods (e.g., ``zeros((2, 3), dtype=float32)``).
70+
Data type objects are used as ``dtype`` specifiers in functions and methods
71+
(e.g., ``zeros((2, 3), dtype=float32)``), accessible as ``.dtype`` attribute on
72+
arrays, and used in various casting and introspection functions (e.g.,
73+
``isdtype(x.dtype, 'integral')``).
8974

90-
.. note::
91-
A conforming implementation may add additional methods or attributes to data type objects beyond those described in this specification.
75+
``dtype`` keywords in functions specify the dtype of arrays returned from
76+
functions or methods. ``dtype`` keywords are not required to affect the data
77+
type used for intermediate calculations or results (e.g., implementors are free
78+
to use a higher-precision dtype when accumulating values for reductions, as
79+
long as the returned array has the specified dtype).
9280

9381
.. note::
9482
Implementations may provide other ways to specify data types (e.g., ``zeros((2, 3), dtype='f4')``) which are not described in this specification; however, in order to ensure portability, array library consumers are recommended to use data type objects as provided by specification conforming array libraries.
9583

96-
A conforming implementation of the array API standard must provide and support data type objects having the following attributes and methods.
97-
98-
Methods
99-
~~~~~~~
100-
101-
..
102-
NOTE: please keep the functions in alphabetical order
103-
104-
.. currentmodule:: array_api.data_types
105-
106-
.. autosummary::
107-
:toctree: generated
108-
:template: method.rst
109-
110-
__eq__
84+
When arrays with different dtypes or different dtype objects are used together,
85+
what happens is described in :ref:`type-promotion`.
11186

11287

11388
.. _data-type-defaults:
@@ -138,48 +113,32 @@ the library should clearly warn about this in its documentation.
138113
.. note::
139114
The default data types should be clearly defined in a conforming library's documentation.
140115

116+
141117
.. _data-type-categories:
142118

143119
Data Type Categories
144120
--------------------
145121

146122
For the purpose of organizing functions within this specification, the following data type categories are defined.
147123

148-
.. note::
149-
Conforming libraries are not required to organize data types according to these categories. These categories are only intended for use within this specification.
150-
151-
152-
Numeric Data Types
153-
~~~~~~~~~~~~~~~~~~
154-
155-
``int8``, ``int16``, ``int32``, ``int64``, ``uint8``, ``uint16``, ``uint32``, ``uint64``, ``float32``, ``float64``, ``complex64``, and ``complex128``.
156-
157-
Real-valued Data Types
158-
~~~~~~~~~~~~~~~~~~~~~~
159-
160-
``int8``, ``int16``, ``int32``, ``int64``, ``uint8``, ``uint16``, ``uint32``, ``uint64``, ``float32``, and ``float64``.
161-
162-
Integer Data Types
163-
~~~~~~~~~~~~~~~~~~
164-
165-
``int8``, ``int16``, ``int32``, ``int64``, ``uint8``, ``uint16``, ``uint32``, and ``uint64``.
166-
167-
Floating-point Data Types
168-
~~~~~~~~~~~~~~~~~~~~~~~~~
124+
+----------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------+
125+
| data type category | dtypes |
126+
+============================+========================================================================================================================================================+
127+
| Numeric | ``int8``, ``int16``, ``int32``, ``int64``, ``uint8``, ``uint16``, ``uint32``, ``uint64``, ``float32``, ``float64``, ``complex64``, and ``complex128``. |
128+
+----------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------+
129+
| Real-valued | ``int8``, ``int16``, ``int32``, ``int64``, ``uint8``, ``uint16``, ``uint32``, ``uint64``, ``float32``, and ``float64``. |
130+
+----------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------+
131+
| Integer | ``int8``, ``int16``, ``int32``, ``int64``, ``uint8``, ``uint16``, ``uint32``, and ``uint64``. |
132+
+----------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------+
133+
| Floating-point | ``float32``, ``float64``, ``complex64``, and ``complex128``. |
134+
+----------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------+
135+
| Real-valued floating-point | ``float32`` and ``float64``. |
136+
+----------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------+
137+
| Complex floating-point | ``complex64`` and ``complex128``. |
138+
+----------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------+
139+
| Boolean | ``bool``. |
140+
+----------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------+
169141

170-
``float32``, ``float64``, ``complex64``, and ``complex128``.
171142

172-
Real-valued Floating-point Data Types
173-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
174-
175-
``float32`` and ``float64``.
176-
177-
Complex Floating-point Data Types
178-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
179-
180-
``complex64`` and ``complex128``.
181-
182-
Boolean Data Types
183-
~~~~~~~~~~~~~~~~~~
184-
185-
``bool``.
143+
.. note::
144+
Conforming libraries are not required to organize data types according to these categories. These categories are only intended for use within this specification.

0 commit comments

Comments
 (0)