You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: spec/draft/API_specification/type_promotion.rst
+17-9Lines changed: 17 additions & 9 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -110,7 +110,6 @@ where
110
110
- **c16**: double-precision complex floating-point number (i.e., ``complex128``)
111
111
composed of two double-precision (64-bit) floating-point numbers
112
112
113
-
114
113
Notes
115
114
~~~~~
116
115
@@ -132,21 +131,30 @@ where ``<op>`` is a built-in operator (including in-place operators, but excludi
132
131
133
132
- a Python ``bool`` for a ``bool`` array data type.
134
133
- a Python ``int`` within the bounds of the given data type for integer array :ref:`data-types`.
135
-
- a Python ``int``, ``float``, or ``complex`` for real-valued floating-point array data types.
134
+
- a Python ``int``or ``float`` for real-valued floating-point array data types.
136
135
- a Python ``int``, ``float``, or ``complex`` for complex floating-point array data types.
137
136
138
137
Provided the above requirements are met, the expected behavior is equivalent to:
139
138
140
-
1. Convert the scalar to zero-dimensional array with the same data type as that of the array used in the expression.
139
+
1. Convert the scalar to a zero-dimensional array with the same data type as that of the array used in the expression.
141
140
2. Execute the operation for ``array <op> 0-D array`` (or ``0-D array <op> array`` if ``scalar`` was the left-hand argument).
142
141
143
-
.. note::
144
-
Behavior is not specified when mixing a Python ``float`` and an array with an integer data type; this may give ``float32``, ``float64``, or raise an exception. Behavior is implementation-specific.
142
+
Additionally, using Python ``complex`` scalars together with arrays must be supported for:
143
+
144
+
- ``array <op> scalar``
145
+
- ``scalar <op> array``
145
146
146
-
Behavior is also not specified for integers outside of the bounds of a given integer data type. Integers outside of bounds may result in overflow or an error.
147
+
where ``<op>`` is a built-in operator (including in-place operators, but excluding the matmul ``@`` operator; see :ref:`operators` for operators supported by the array object) and ``scalar`` has a type and value compatible with a promoted array data type:
147
148
149
+
- a Python ``complex`` for real-valued floating-point array data types.
148
150
149
-
.. note::
150
-
Mixing a Python ``complex`` and an array with a real-valued data type is allowed; the result is an array of the data type of the same *precision* as the array operand. In other word, ``1j <op> float32_array`` results in a ``complex64`` array; ``1j <op> float64_array`` results in a ``complex128`` array.
151
+
Provided the above requirements are met, the expected behavior is equivalent to:
152
+
153
+
1. Convert the scalar to a zero-dimensional array with a complex floating-point array data type having the same precision as that of the array operand used in the expression (e.g., if an array has a ``float32`` data type, the scalar must be converted to a zero-dimensional array having a ``complex64`` data type; if an array has a ``float64`` data type, the scalar must be converted to a zero-dimensional array have a ``complex128`` data type).
154
+
2. Execute the operation for ``array <op> 0-D array`` (or ``0-D array <op> array`` if ``scalar`` was the left-hand argument).
155
+
156
+
Behavior is not specified for integers outside of the bounds of a given integer data type. Integers outside of bounds may result in overflow or an error.
157
+
158
+
Behavior is not specified when mixing a Python ``float`` and an array with an integer data type; this may give ``float32``, ``float64``, or raise an exception. Behavior is implementation-specific.
151
159
152
-
Behavior is not specificed when mixing ``complex`` scalars with integer arrays; this may give ``complex64``, ``complex128``, or raise an exception. Behavior is implementation-specific.
160
+
Behavior is not specified when mixing a Python ``complex`` and an array with an integer data type; this may give ``complex64``, ``complex128``, or raise an exception. Behavior is implementation-specific.
0 commit comments