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
Change dtype=None behavior in sum/prod/cumulative_sum/linalg.trace
Closesdata-apisgh-731. This is a backwards-incompatible change. It seems
justified and necessary because array libraries all behave like the
required behavior described in this commit, are not planning to change,
and the initial rationale for the "upcast float" requirement wasn't
strong. See discussion in data-apisgh-731 for more details.
data type of the returned array. If ``None``, the returned array must have the same data type as ``x``, unless ``x`` has an integer dtype supporting a smaller range of values than the default integer dtype (e.g., ``x`` has an ``int16`` or ``uint32`` dtype and the default integer dtype is ``int64``). In those latter cases:
746
746
747
-
- 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``.
748
-
- if the default data type corresponding to the data type "kind" of ``x`` has the same or a larger range of values than the data type of ``x``,
749
-
- if ``x`` has a real-valued floating-point data type, the returned array must have the default real-valued floating-point data type.
750
-
- if ``x`` has a complex floating-point data type, the returned array must have the default complex floating-point data type.
751
-
- if ``x`` has a signed integer data type (e.g., ``int16``), the returned array must have the default integer data type.
752
-
- 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).
747
+
- if ``x`` has a signed integer data type (e.g., ``int16``), the returned array must have the default integer data type.
748
+
- 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).
753
749
754
-
If the data type (either specified or resolved) differs from the data type of ``x``, the input array should be cast to the specified data type before computing the sum. Default: ``None``.
755
-
756
-
.. note::
757
-
keyword argument is intended to help prevent data type overflows.
750
+
If the data type (either specified or resolved) differs from the data type of ``x``, the input array should be cast to the specified data type before computing the sum (rationale: the ``dtype`` keyword argument is intended to help prevent overflows). Default: ``None``.
Copy file name to clipboardExpand all lines: src/array_api_stubs/_draft/statistical_functions.py
+15-35
Original file line number
Diff line number
Diff line change
@@ -23,22 +23,14 @@ def cumulative_sum(
23
23
axis along which a cumulative sum must be computed. If ``axis`` is negative, the function must determine the axis along which to compute a cumulative sum by counting from the last dimension.
24
24
25
25
If ``x`` is a one-dimensional array, providing an ``axis`` is optional; however, if ``x`` has more than one dimension, providing an ``axis`` is required.
26
-
dtype: Optional[dtype]
27
-
data type of the returned array. If ``None``,
28
-
29
-
- 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``.
30
-
31
-
- if the default data type corresponding to the data type "kind" of ``x`` has the same or a larger range of values than the data type of ``x``,
32
26
33
-
- if ``x`` has a real-valued floating-point data type, the returned array must have the default real-valued floating-point data type.
34
-
- if ``x`` has a complex floating-point data type, the returned array must have the default complex floating-point data type.
35
-
- if ``x`` has a signed integer data type (e.g., ``int16``), the returned array must have the default integer data type.
36
-
- 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).
27
+
dtype: Optional[dtype]
28
+
data type of the returned array. If ``None``, the returned array must have the same data type as ``x``, unless ``x`` has an integer dtype supporting a smaller range of values than the default integer dtype (e.g., ``x`` has an ``int16`` or ``uint32`` dtype and the default integer dtype is ``int64``). In those latter cases:
37
29
38
-
If the data type (either specified or resolved) differs from the data type of ``x``, the input array should be cast to the specified data type before computing the sum. Default: ``None``.
30
+
- if ``x`` has a signed integer data type (e.g., ``int16``), the returned array must have the default integer data type.
31
+
- 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).
39
32
40
-
.. note::
41
-
keyword argument is intended to help prevent data type overflows.
33
+
If the data type (either specified or resolved) differs from the data type of ``x``, the input array should be cast to the specified data type before computing the sum (rationale: the ``dtype`` keyword argument is intended to help prevent overflows). Default: ``None``.
42
34
43
35
include_initial: bool
44
36
boolean indicating whether to include the initial value as the first value in the output. By convention, the initial value must be the additive identity (i.e., zero). Default: ``False``.
@@ -200,20 +192,14 @@ def prod(
200
192
input array. Should have a numeric data type.
201
193
axis: Optional[Union[int, Tuple[int, ...]]]
202
194
axis or axes along which products must be computed. By default, the product must be computed over the entire array. If a tuple of integers, products must be computed over multiple axes. Default: ``None``.
203
-
dtype: Optional[dtype]
204
-
data type of the returned array. If ``None``,
205
195
206
-
- 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``.
207
-
- if the default data type corresponding to the data type "kind" of ``x`` has the same or a larger range of values than the data type of ``x``,
208
-
- if ``x`` has a real-valued floating-point data type, the returned array must have the default real-valued floating-point data type.
209
-
- if ``x`` has a complex floating-point data type, the returned array must have the default complex floating-point data type.
210
-
- if ``x`` has a signed integer data type (e.g., ``int16``), the returned array must have the default integer data type.
211
-
- 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).
196
+
dtype: Optional[dtype]
197
+
data type of the returned array. If ``None``, the returned array must have the same data type as ``x``, unless ``x`` has an integer dtype supporting a smaller range of values than the default integer dtype (e.g., ``x`` has an ``int16`` or ``uint32`` dtype and the default integer dtype is ``int64``). In those latter cases:
212
198
213
-
If the data type (either specified or resolved) differs from the data type of ``x``, the input array should be cast to the specified data type before computing the product. Default: ``None``.
199
+
- if ``x`` has a signed integer data type (e.g., ``int16``), the returned array must have the default integer data type.
200
+
- 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).
214
201
215
-
.. note::
216
-
This keyword argument is intended to help prevent data type overflows.
202
+
If the data type (either specified or resolved) differs from the data type of ``x``, the input array should be cast to the specified data type before computing the sum (rationale: the ``dtype`` keyword argument is intended to help prevent overflows). Default: ``None``.
217
203
218
204
keepdims: bool
219
205
if ``True``, the reduced axes (dimensions) must be included in the result as singleton dimensions, and, accordingly, the result must be compatible with the input array (see :ref:`broadcasting`). Otherwise, if ``False``, the reduced axes (dimensions) must not be included in the result. Default: ``False``.
@@ -298,20 +284,14 @@ def sum(
298
284
input array. Should have a numeric data type.
299
285
axis: Optional[Union[int, Tuple[int, ...]]]
300
286
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``.
301
-
dtype: Optional[dtype]
302
-
data type of the returned array. If ``None``,
303
287
304
-
- 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``.
305
-
- if the default data type corresponding to the data type "kind" of ``x`` has the same or a larger range of values than the data type of ``x``,
306
-
- if ``x`` has a real-valued floating-point data type, the returned array must have the default real-valued floating-point data type.
307
-
- if ``x`` has a complex floating-point data type, the returned array must have the default complex floating-point data type.
308
-
- if ``x`` has a signed integer data type (e.g., ``int16``), the returned array must have the default integer data type.
309
-
- 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).
288
+
dtype: Optional[dtype]
289
+
data type of the returned array. If ``None``, the returned array must have the same data type as ``x``, unless ``x`` has an integer dtype supporting a smaller range of values than the default integer dtype (e.g., ``x`` has an ``int16`` or ``uint32`` dtype and the default integer dtype is ``int64``). In those latter cases:
310
290
311
-
If the data type (either specified or resolved) differs from the data type of ``x``, the input array should be cast to the specified data type before computing the sum. Default: ``None``.
291
+
- if ``x`` has a signed integer data type (e.g., ``int16``), the returned array must have the default integer data type.
292
+
- 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).
312
293
313
-
.. note::
314
-
keyword argument is intended to help prevent data type overflows.
294
+
If the data type (either specified or resolved) differs from the data type of ``x``, the input array should be cast to the specified data type before computing the sum (rationale: the ``dtype`` keyword argument is intended to help prevent overflows). Default: ``None``.
315
295
316
296
keepdims: bool
317
297
if ``True``, the reduced axes (dimensions) must be included in the result as singleton dimensions, and, accordingly, the result must be compatible with the input array (see :ref:`broadcasting`). Otherwise, if ``False``, the reduced axes (dimensions) must not be included in the result. Default: ``False``.
0 commit comments