Skip to content

Commit 48c09fc

Browse files
authored
Add complex floating-point data types (#418)
* Add complex floating-point data types * Add complex dtypes to numeric category and add real-valued data types category * Replace "numeric data type" with "real-valued data type" This change ensures that the specification maintains the status quo in terms of accepted dtypes for the current set of APIs. Subsequent PRs will add support to APIs for complex number data types on a case-by-case basis. * Add category for real-valued floating-point data types * Fix underline
1 parent 73dbcb5 commit 48c09fc

10 files changed

+221
-205
lines changed

spec/API_specification/array_object.rst

+2-2
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ A conforming implementation of the array API standard must provide and support a
8282
- `operator.pow(x1, x2) <https://docs.python.org/3/library/operator.html#operator.pow>`_
8383
- `operator.__pow__(x1, x2) <https://docs.python.org/3/library/operator.html#operator.__pow__>`_
8484

85-
Arithmetic operators should be defined for arrays having numeric data types.
85+
Arithmetic operators should be defined for arrays having real-valued data types.
8686

8787
Array Operators
8888
~~~~~~~~~~~~~~~
@@ -94,7 +94,7 @@ A conforming implementation of the array API standard must provide and support a
9494
- `operator.matmul(x1, x2) <https://docs.python.org/3/library/operator.html#operator.matmul>`_
9595
- `operator.__matmul__(x1, x2) <https://docs.python.org/3/library/operator.html#operator.__matmul__>`_
9696

97-
The matmul ``@`` operator should be defined for arrays having numeric data types.
97+
The matmul ``@`` operator should be defined for arrays having real-valued data types.
9898

9999
Bitwise Operators
100100
~~~~~~~~~~~~~~~~~

spec/API_specification/data_types.rst

+30-14
Original file line numberDiff line numberDiff line change
@@ -62,19 +62,20 @@ float64
6262

6363
IEEE 754 double-precision (64-bit) binary floating-point number (see IEEE 754-2019).
6464

65-
.. note::
66-
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.
65+
complex64
66+
---------
6767

68-
Accordingly, subnormal behavior is left unspecified and, thus, implementation-defined. Conforming implementations may vary in their support for subnormal numbers.
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).
6969

70-
.. admonition:: Future extension
71-
:class: admonition tip
70+
complex128
71+
----------
7272

73-
``complex64`` and ``complex128`` data types are expected to be included in the next version of this standard and to have the following casting rules (will be added to :ref:`type-promotion`):
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).
7474

75-
.. image:: /_static/images/dtype_promotion_complex.png
75+
.. note::
76+
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.
7677

77-
See `array-api/issues/102 <https://github.com/data-apis/array-api/issues/102>`_ for more details
78+
Accordingly, subnormal behavior is left unspecified and, thus, implementation-defined. Conforming implementations may vary in their support for subnormal numbers.
7879

7980
.. note::
8081
A conforming implementation of the array API standard may provide and support additional data types beyond those described in this specification.
@@ -116,11 +117,14 @@ Default Data Types
116117

117118
A conforming implementation of the array API standard must define the following default data types.
118119

119-
- a default floating-point data type (either ``float32`` or ``float64``).
120+
- a default real-valued floating-point data type (either ``float32`` or ``float64``).
121+
- a default complex floating-point data type (either ``complex64`` or ``complex128``).
120122
- a default integer data type (either ``int32`` or ``int64``).
121123
- a default array index data type (either ``int32`` or ``int64``).
122124

123-
The default floating-point data type must be the same across platforms.
125+
The default real-valued floating-point and complex floating-point data types must be the same across platforms.
126+
127+
The default complex floating-point point data type should match the default real-valued floating-point data type. For example, if the default real-valued floating-point data type is ``float32``, the default complex floating-point data type must be ``complex64``. If the default real-valued floating-point data type is ``float64``, the default complex floating-point data type must be ``complex128``.
124128

125129
The default integer data type should be the same across platforms, but the default may vary depending on whether Python is 32-bit or 64-bit.
126130

@@ -139,14 +143,16 @@ For the purpose of organizing functions within this specification, the following
139143
.. note::
140144
Conforming libraries are not required to organize data types according to these categories. These categories are only intended for use within this specification.
141145

142-
.. note::
143-
Future versions of the specification will include additional categories for complex data types.
144-
145146

146147
Numeric Data Types
147148
~~~~~~~~~~~~~~~~~~
148149

149-
``int8``, ``int16``, ``int32``, ``int64``, ``uint8``, ``uint16``, ``uint32``, ``uint64``, ``float32``, and ``float64`` (i.e., all data types except for ``bool``).
150+
``int8``, ``int16``, ``int32``, ``int64``, ``uint8``, ``uint16``, ``uint32``, ``uint64``, ``float32``, ``float64``, ``complex64``, and ``complex128``.
151+
152+
Real-valued Data Types
153+
~~~~~~~~~~~~~~~~~~~~~~
154+
155+
``int8``, ``int16``, ``int32``, ``int64``, ``uint8``, ``uint16``, ``uint32``, ``uint64``, ``float32``, and ``float64``.
150156

151157
Integer Data Types
152158
~~~~~~~~~~~~~~~~~~
@@ -156,8 +162,18 @@ Integer Data Types
156162
Floating-point Data Types
157163
~~~~~~~~~~~~~~~~~~~~~~~~~
158164

165+
``float32``, ``float64``, ``complex64``, and ``complex128``.
166+
167+
Real-valued Floating-point Data Types
168+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
169+
159170
``float32`` and ``float64``.
160171

172+
Complex Floating-point Data Types
173+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
174+
175+
``complex64`` and ``complex128``.
176+
161177
Boolean Data Types
162178
~~~~~~~~~~~~~~~~~~
163179

spec/API_specification/signatures/array_object.py

+32-32
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ def __abs__(self: array, /) -> array:
126126
Parameters
127127
----------
128128
self: array
129-
array instance. Should have a numeric data type.
129+
array instance. Should have a real-valued data type.
130130
131131
Returns
132132
-------
@@ -170,9 +170,9 @@ def __add__(self: array, other: Union[int, float, array], /) -> array:
170170
Parameters
171171
----------
172172
self: array
173-
array instance (augend array). Should have a numeric data type.
173+
array instance (augend array). Should have a real-valued data type.
174174
other: Union[int, float, array]
175-
addend array. Must be compatible with ``self`` (see :ref:`broadcasting`). Should have a numeric data type.
175+
addend array. Must be compatible with ``self`` (see :ref:`broadcasting`). Should have a real-valued data type.
176176
177177
Returns
178178
-------
@@ -346,7 +346,7 @@ def __float__(self: array, /) -> float:
346346
Parameters
347347
----------
348348
self: array
349-
zero-dimensional array instance. Must have a floating-point data type.
349+
zero-dimensional array instance. Must have a real-valued floating-point data type.
350350
351351
Returns
352352
-------
@@ -400,9 +400,9 @@ def __floordiv__(self: array, other: Union[int, float, array], /) -> array:
400400
Parameters
401401
----------
402402
self: array
403-
array instance. Should have a numeric data type.
403+
array instance. Should have a real-valued data type.
404404
other: Union[int, float, array]
405-
other array. Must be compatible with ``self`` (see :ref:`broadcasting`). Should have a numeric data type.
405+
other array. Must be compatible with ``self`` (see :ref:`broadcasting`). Should have a real-valued data type.
406406
407407
Returns
408408
-------
@@ -421,9 +421,9 @@ def __ge__(self: array, other: Union[int, float, array], /) -> array:
421421
Parameters
422422
----------
423423
self: array
424-
array instance. Should have a numeric data type.
424+
array instance. Should have a real-valued data type.
425425
other: Union[int, float, array]
426-
other array. Must be compatible with ``self`` (see :ref:`broadcasting`). Should have a numeric data type.
426+
other array. Must be compatible with ``self`` (see :ref:`broadcasting`). Should have a real-valued data type.
427427
428428
Returns
429429
-------
@@ -459,9 +459,9 @@ def __gt__(self: array, other: Union[int, float, array], /) -> array:
459459
Parameters
460460
----------
461461
self: array
462-
array instance. Should have a numeric data type.
462+
array instance. Should have a real-valued data type.
463463
other: Union[int, float, array]
464-
other array. Must be compatible with ``self`` (see :ref:`broadcasting`). Should have a numeric data type.
464+
other array. Must be compatible with ``self`` (see :ref:`broadcasting`). Should have a real-valued data type.
465465
466466
Returns
467467
-------
@@ -532,9 +532,9 @@ def __le__(self: array, other: Union[int, float, array], /) -> array:
532532
Parameters
533533
----------
534534
self: array
535-
array instance. Should have a numeric data type.
535+
array instance. Should have a real-valued data type.
536536
other: Union[int, float, array]
537-
other array. Must be compatible with ``self`` (see :ref:`broadcasting`). Should have a numeric data type.
537+
other array. Must be compatible with ``self`` (see :ref:`broadcasting`). Should have a real-valued data type.
538538
539539
Returns
540540
-------
@@ -574,9 +574,9 @@ def __lt__(self: array, other: Union[int, float, array], /) -> array:
574574
Parameters
575575
----------
576576
self: array
577-
array instance. Should have a numeric data type.
577+
array instance. Should have a real-valued data type.
578578
other: Union[int, float, array]
579-
other array. Must be compatible with ``self`` (see :ref:`broadcasting`). Should have a numeric data type.
579+
other array. Must be compatible with ``self`` (see :ref:`broadcasting`). Should have a real-valued data type.
580580
581581
Returns
582582
-------
@@ -598,9 +598,9 @@ def __matmul__(self: array, other: array, /) -> array:
598598
Parameters
599599
----------
600600
self: array
601-
array instance. Should have a numeric data type. Must have at least one dimension. If ``self`` is one-dimensional having shape ``(M,)`` and ``other`` has more than one dimension, ``self`` must be promoted to a two-dimensional array by prepending ``1`` to its dimensions (i.e., must have shape ``(1, M)``). After matrix multiplication, the prepended dimensions in the returned array must be removed. If ``self`` has more than one dimension (including after vector-to-matrix promotion), ``shape(self)[:-2]`` must be compatible with ``shape(other)[:-2]`` (after vector-to-matrix promotion) (see :ref:`broadcasting`). If ``self`` has shape ``(..., M, K)``, the innermost two dimensions form matrices on which to perform matrix multiplication.
601+
array instance. Should have a real-valued data type. Must have at least one dimension. If ``self`` is one-dimensional having shape ``(M,)`` and ``other`` has more than one dimension, ``self`` must be promoted to a two-dimensional array by prepending ``1`` to its dimensions (i.e., must have shape ``(1, M)``). After matrix multiplication, the prepended dimensions in the returned array must be removed. If ``self`` has more than one dimension (including after vector-to-matrix promotion), ``shape(self)[:-2]`` must be compatible with ``shape(other)[:-2]`` (after vector-to-matrix promotion) (see :ref:`broadcasting`). If ``self`` has shape ``(..., M, K)``, the innermost two dimensions form matrices on which to perform matrix multiplication.
602602
other: array
603-
other array. Should have a numeric data type. Must have at least one dimension. If ``other`` is one-dimensional having shape ``(N,)`` and ``self`` has more than one dimension, ``other`` must be promoted to a two-dimensional array by appending ``1`` to its dimensions (i.e., must have shape ``(N, 1)``). After matrix multiplication, the appended dimensions in the returned array must be removed. If ``other`` has more than one dimension (including after vector-to-matrix promotion), ``shape(other)[:-2]`` must be compatible with ``shape(self)[:-2]`` (after vector-to-matrix promotion) (see :ref:`broadcasting`). If ``other`` has shape ``(..., K, N)``, the innermost two dimensions form matrices on which to perform matrix multiplication.
603+
other array. Should have a real-valued data type. Must have at least one dimension. If ``other`` is one-dimensional having shape ``(N,)`` and ``self`` has more than one dimension, ``other`` must be promoted to a two-dimensional array by appending ``1`` to its dimensions (i.e., must have shape ``(N, 1)``). After matrix multiplication, the appended dimensions in the returned array must be removed. If ``other`` has more than one dimension (including after vector-to-matrix promotion), ``shape(other)[:-2]`` must be compatible with ``shape(self)[:-2]`` (after vector-to-matrix promotion) (see :ref:`broadcasting`). If ``other`` has shape ``(..., K, N)``, the innermost two dimensions form matrices on which to perform matrix multiplication.
604604
605605
Returns
606606
-------
@@ -665,14 +665,14 @@ def __mod__(self: array, other: Union[int, float, array], /) -> array:
665665
Parameters
666666
----------
667667
self: array
668-
array instance. Should have a numeric data type.
668+
array instance. Should have a real-valued data type.
669669
other: Union[int, float, array]
670-
other array. Must be compatible with ``self`` (see :ref:`broadcasting`). Should have a numeric data type.
670+
other array. Must be compatible with ``self`` (see :ref:`broadcasting`). Should have a real-valued data type.
671671
672672
Returns
673673
-------
674674
out: array
675-
an array containing the element-wise results. Each element-wise result must have the same sign as the respective element ``other_i``. The returned array must have a floating-point data type determined by :ref:`type-promotion`.
675+
an array containing the element-wise results. Each element-wise result must have the same sign as the respective element ``other_i``. The returned array must have a real-valued floating-point data type determined by :ref:`type-promotion`.
676676
677677
678678
.. note::
@@ -704,9 +704,9 @@ def __mul__(self: array, other: Union[int, float, array], /) -> array:
704704
Parameters
705705
----------
706706
self: array
707-
array instance. Should have a numeric data type.
707+
array instance. Should have a real-valued data type.
708708
other: Union[int, float, array]
709-
other array. Must be compatible with ``self`` (see :ref:`broadcasting`). Should have a numeric data type.
709+
other array. Must be compatible with ``self`` (see :ref:`broadcasting`). Should have a real-valued data type.
710710
711711
Returns
712712
-------
@@ -749,7 +749,7 @@ def __neg__(self: array, /) -> array:
749749
Parameters
750750
----------
751751
self: array
752-
array instance. Should have a numeric data type.
752+
array instance. Should have a real-valued data type.
753753
754754
Returns
755755
-------
@@ -789,7 +789,7 @@ def __pos__(self: array, /) -> array:
789789
Parameters
790790
----------
791791
self: array
792-
array instance. Should have a numeric data type.
792+
array instance. Should have a real-valued data type.
793793
794794
Returns
795795
-------
@@ -808,7 +808,7 @@ def __pow__(self: array, other: Union[int, float, array], /) -> array:
808808
.. note::
809809
If both ``self`` and ``other`` have integer data types, the result of ``__pow__`` when `other_i` is negative (i.e., less than zero) is unspecified and thus implementation-dependent.
810810
811-
If ``self`` has an integer data type and ``other`` has a floating-point data type, behavior is implementation-dependent, as type promotion between data type "kinds" (e.g., integer versus floating-point) is unspecified.
811+
If ``self`` has an integer data type and ``other`` has a real-valued floating-point data type, behavior is implementation-dependent, as type promotion between data type "kinds" (e.g., integer versus floating-point) is unspecified.
812812
813813
**Special cases**
814814
@@ -842,9 +842,9 @@ def __pow__(self: array, other: Union[int, float, array], /) -> array:
842842
Parameters
843843
----------
844844
self: array
845-
array instance whose elements correspond to the exponentiation base. Should have a numeric data type.
845+
array instance whose elements correspond to the exponentiation base. Should have a real-valued data type.
846846
other: Union[int, float, array]
847-
other array whose elements correspond to the exponentiation exponent. Must be compatible with ``self`` (see :ref:`broadcasting`). Should have a numeric data type.
847+
other array whose elements correspond to the exponentiation exponent. Must be compatible with ``self`` (see :ref:`broadcasting`). Should have a real-valued data type.
848848
849849
Returns
850850
-------
@@ -907,9 +907,9 @@ def __sub__(self: array, other: Union[int, float, array], /) -> array:
907907
Parameters
908908
----------
909909
self: array
910-
array instance (minuend array). Should have a numeric data type.
910+
array instance (minuend array). Should have a real-valued data type.
911911
other: Union[int, float, array]
912-
subtrahend array. Must be compatible with ``self`` (see :ref:`broadcasting`). Should have a numeric data type.
912+
subtrahend array. Must be compatible with ``self`` (see :ref:`broadcasting`). Should have a real-valued data type.
913913
914914
Returns
915915
-------
@@ -928,7 +928,7 @@ def __truediv__(self: array, other: Union[int, float, array], /) -> array:
928928
.. note::
929929
If one or both of ``self`` and ``other`` have integer data types, the result is implementation-dependent, as type promotion between data type "kinds" (e.g., integer versus floating-point) is unspecified.
930930
931-
Specification-compliant libraries may choose to raise an error or return an array containing the element-wise results. If an array is returned, the array must have a floating-point data type.
931+
Specification-compliant libraries may choose to raise an error or return an array containing the element-wise results. If an array is returned, the array must have a real-valued floating-point data type.
932932
933933
**Special cases**
934934
@@ -960,14 +960,14 @@ def __truediv__(self: array, other: Union[int, float, array], /) -> array:
960960
Parameters
961961
----------
962962
self: array
963-
array instance. Should have a numeric data type.
963+
array instance. Should have a real-valued data type.
964964
other: Union[int, float, array]
965-
other array. Must be compatible with ``self`` (see :ref:`broadcasting`). Should have a numeric data type.
965+
other array. Must be compatible with ``self`` (see :ref:`broadcasting`). Should have a real-valued data type.
966966
967967
Returns
968968
-------
969969
out: array
970-
an array containing the element-wise results. The returned array should have a floating-point data type determined by :ref:`type-promotion`.
970+
an array containing the element-wise results. The returned array should have a real-valued floating-point data type determined by :ref:`type-promotion`.
971971
972972
973973
.. note::

0 commit comments

Comments
 (0)