Skip to content

Commit f96cd18

Browse files
authored
Add complex number support to sum (#538)
1 parent 58580d5 commit f96cd18

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

Diff for: spec/API_specification/array_api/statistical_functions.py

+4-5
Original file line numberDiff line numberDiff line change
@@ -174,21 +174,20 @@ def sum(x: array, /, *, axis: Optional[Union[int, Tuple[int, ...]]] = None, dtyp
174174
175175
- If ``N`` is ``0``, the sum is ``0`` (i.e., the empty sum).
176176
177-
For floating-point operands,
178-
179-
- If ``x_i`` is ``NaN``, the sum is ``NaN`` (i.e., ``NaN`` values propagate).
177+
For both real-valued and complex floating-point operands, special cases must be handled as if the operation is implemented by successive application of :func:`~array_api.add`.
180178
181179
Parameters
182180
----------
183181
x: array
184-
input array. Should have a real-valued data type.
182+
input array. Should have a numeric data type.
185183
axis: Optional[Union[int, Tuple[int, ...]]]
186184
axis or axes along which sums must be computed. By default, the sum must be computed over the entire array. If a tuple of integers, sums must be computed over multiple axes. Default: ``None``.
187185
dtype: Optional[dtype]
188186
data type of the returned array. If ``None``,
189187
190-
- if the default data type corresponding to the data type "kind" (integer or floating-point) of ``x`` has a smaller range of values than the data type of ``x`` (e.g., ``x`` has data type ``int64`` and the default data type is ``int32``, or ``x`` has data type ``uint64`` and the default data type is ``int64``), the returned array must have the same data type as ``x``.
188+
- if the default data type corresponding to the data type "kind" (integer, real-valued floating-point, or complex floating-point) of ``x`` has a smaller range of values than the data type of ``x`` (e.g., ``x`` has data type ``int64`` and the default data type is ``int32``, or ``x`` has data type ``uint64`` and the default data type is ``int64``), the returned array must have the same data type as ``x``.
191189
- if ``x`` has a real-valued floating-point data type, the returned array must have the default real-valued floating-point data type.
190+
- if ``x`` has a complex floating-point data type, the returned array must have the default complex floating-point data type.
192191
- if ``x`` has a signed integer data type (e.g., ``int16``), the returned array must have the default integer data type.
193192
- if ``x`` has an unsigned integer data type (e.g., ``uint16``), the returned array must have an unsigned integer data type having the same number of bits as the default integer data type (e.g., if the default integer data type is ``int32``, the returned array must have a ``uint32`` data type).
194193

0 commit comments

Comments
 (0)