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
the distance between two adjacent elements (``out[i+1] - out[i]``). Must not be ``0``; may be negative, this results in an empty array if ``stop >= start``. Default: ``1``.
16
16
dtype: Optional[dtype]
17
-
output array data type. If ``dtype`` is ``None``, the output array data type must be inferred from ``start``, ``stop`` and ``step``. If those are all integers, the output array dtype must be the default integer dtype; if one or more have type ``float``, then the output array dtype must be the default floating-point data type. Default: ``None``.
17
+
output array data type. If ``dtype`` is ``None``, the output array data type must be inferred from ``start``, ``stop`` and ``step``. If those are all integers, the output array dtype must be the default integer dtype; if one or more have type ``float``, then the output array dtype must be the default real-valued floating-point data type. Default: ``None``.
18
18
device: Optional[device]
19
19
device on which to place the created array. Default: ``None``.
a one-dimensional array containing evenly spaced values. The length of the output array must be ``ceil((stop-start)/step)`` if ``stop - start`` and ``step`` have the same sign, and length ``0`` otherwise.
object to be converted to an array. May be a Python scalar, a (possibly nested) sequence of Python scalars, or an object supporting the Python buffer protocol.
An object supporting the buffer protocol can be turned into a memoryview through ``memoryview(obj)``.
44
44
45
45
dtype: Optional[dtype]
46
-
output array data type. If ``dtype`` is ``None``, the output array data type must be inferred from the data type(s) in ``obj``. If all input values are Python scalars, then
46
+
output array data type. If ``dtype`` is ``None``, the output array data type must be inferred from the data type(s) in ``obj``. If all input values are Python scalars, then, in order of precedence,
47
47
48
48
- if all values are of type ``bool``, the output data type must be ``bool``.
49
-
- if the values are a mixture of ``bool``\s and ``int``, the output data type must be the default integer data type.
50
-
- if one or more values are ``float``\s, the output data type must be the default floating-point data type.
49
+
- if all values are of type ``int`` or are a mixture of ``bool`` and ``int``, the output data type must be the default integer data type.
50
+
- if one or more values are ``complex`` numbers, the output data type must be the default complex floating-point data type.
51
+
- if one or more values are ``float``\s, the output data type must be the default real-valued floating-point data type.
51
52
52
53
Default: ``None``.
53
54
54
55
.. admonition:: Note
55
56
:class: note
56
57
57
-
If ``dtype`` is not ``None``, then array conversions should obey :ref:`type-promotion` rules. Conversions not specified according to :ref:`type-promotion` rules may or may not be permitted by a conforming array library. To perform an explicit cast, use :func:`signatures.data_type_functions.astype`.
58
+
If ``dtype`` is not ``None``, then array conversions should obey :ref:`type-promotion` rules. Conversions not specified according to :ref:`type-promotion` rules may or may not be permitted by a conforming array library. To perform an explicit cast, use :func:`array_api.astype`.
58
59
59
60
.. note::
60
61
If an input value exceeds the precision of the resolved output array data type, behavior is left unspecified and, thus, implementation-defined.
output array data type. If ``dtype`` is ``None``, the output array data type must be the default floating-point data type. Default: ``None``.
83
+
output array data type. If ``dtype`` is ``None``, the output array data type must be the default real-valued floating-point data type. Default: ``None``.
83
84
device: Optional[device]
84
85
device on which to place the created array. Default: ``None``.
index of the diagonal. A positive value refers to an upper diagonal, a negative value to a lower diagonal, and ``0`` to the main diagonal. Default: ``0``.
123
127
dtype: Optional[dtype]
124
-
output array data type. If ``dtype`` is ``None``, the output array data type must be the default floating-point data type. Default: ``None``.
128
+
output array data type. If ``dtype`` is ``None``, the output array data type must be the default real-valued floating-point data type. Default: ``None``.
125
129
device: Optional[device]
126
130
device on which to place the created array. Default: ``None``.
Returns a new array having a specified ``shape`` and filled with ``fill_value``.
157
161
158
162
Parameters
159
163
----------
160
164
shape: Union[int, Tuple[int, ...]]
161
165
output array shape.
162
-
fill_value: Union[int, float]
166
+
fill_value: Union[bool, int, float, complex]
163
167
fill value.
164
168
dtype: Optional[dtype]
165
-
output array data type. If ``dtype`` is ``None``, the output array data type must be inferred from ``fill_value``. If the fill value is an ``int``, the output array data type must be the default integer data type. If the fill value is a ``float``, the output array data type must be the default floating-point data type. If the fill value is a ``bool``, the output array must have boolean data type. Default: ``None``.
169
+
output array data type. If ``dtype`` is ``None``, the output array data type must be inferred from ``fill_value`` according to the following rules:
170
+
171
+
- If the fill value is an ``int``, the output array data type must be the default integer data type.
172
+
- If the fill value is a ``float``, the output array data type must be the default real-valued floating-point data type.
173
+
- If the fill value is a ``complex`` number, the output array data type must be the default complex floating-point data type.
174
+
- If the fill value is a ``bool``, the output array must have a boolean data type. Default: ``None``.
166
175
167
176
.. note::
168
177
If the ``fill_value`` exceeds the precision of the resolved default output array data type, behavior is left unspecified and, thus, implementation-defined.
If the ``fill_value`` exceeds the precision of the resolved output array data type, behavior is unspecified and, thus, implementation-defined.
194
203
195
204
.. note::
196
-
If the ``fill_value`` has a data type (``int`` or ``float``) which is not of the same data type kind as the resolved output array data type (see :ref:`type-promotion`), behavior is unspecified and, thus, implementation-defined.
205
+
If the ``fill_value`` has a data type which is not of the same data type kind (boolean, integer, or floating-point) as the resolved output array data type (see :ref:`type-promotion`), behavior is unspecified and, thus, implementation-defined.
197
206
198
207
device: Optional[device]
199
208
device on which to place the created array. If ``device`` is ``None``, the output array device must be inferred from ``x``. Default: ``None``.
number of samples. Must be a non-negative integer value; otherwise, the function must raise an exception.
223
232
dtype: Optional[dtype]
224
-
output array data type. Should be a floating-point data type. If ``dtype`` is ``None``, the output array data type must be the default floating-point data type. Default: ``None``.
233
+
output array data type. Should be a real-valued floating-point data type. If ``dtype`` is ``None``, the output array data type must be the default real-valued floating-point data type. Default: ``None``.
225
234
device: Optional[device]
226
235
device on which to place the created array. Default: ``None``.
While this specification recommends that this function only return arrays having a floating-point data type, specification-compliant array libraries may choose to support output arrays having an integer data type (e.g., due to backward compatibility concerns). However, function behavior when generating integer output arrays is unspecified and, thus, is implementation-defined. Accordingly, using this function to generate integer output arrays is not portable.
246
+
While this specification recommends that this function only return arrays having a real-valued floating-point data type, specification-compliant array libraries may choose to support output arrays having an integer data type (e.g., due to backward compatibility concerns). However, function behavior when generating integer output arrays is unspecified and, thus, is implementation-defined. Accordingly, using this function to generate integer output arrays is not portable.
238
247
239
248
.. note::
240
-
As mixed data type promotion is implementation-defined, behavior when ``start`` or ``stop`` exceeds the maximum safe integer of an output floating-point data type is implementation-defined. An implementation may choose to overflow or raise an exception.
249
+
As mixed data type promotion is implementation-defined, behavior when ``start`` or ``stop`` exceeds the maximum safe integer of an output real-valued floating-point data type is implementation-defined. An implementation may choose to overflow or raise an exception.
Returns a new array having a specified ``shape`` and filled with ones.
272
281
282
+
.. note::
283
+
An output array having a complex floating-point data type must contain complex numbers having a real component equal to one and an imaginary component equal to zero (i.e., ``1 + 0j``).
284
+
273
285
Parameters
274
286
----------
275
287
shape: Union[int, Tuple[int, ...]]
276
288
output array shape.
277
289
dtype: Optional[dtype]
278
-
output array data type. If ``dtype`` is ``None``, the output array data type must be the default floating-point data type. Default: ``None``.
290
+
output array data type. If ``dtype`` is ``None``, the output array data type must be the default real-valued floating-point data type. Default: ``None``.
279
291
device: Optional[device]
280
292
device on which to place the created array. Default: ``None``.
Returns a new array filled with ones and having the same ``shape`` as an input array ``x``.
291
303
304
+
.. note::
305
+
An output array having a complex floating-point data type must contain complex numbers having a real component equal to one and an imaginary component equal to zero (i.e., ``1 + 0j``).
output array data type. If ``dtype`` is ``None``, the output array data type must be the default floating-point data type. Default: ``None``.
377
+
output array data type. If ``dtype`` is ``None``, the output array data type must be the default real-valued floating-point data type. Default: ``None``.
363
378
device: Optional[device]
364
379
device on which to place the created array. Default: ``None``.
Casting floating-point ``NaN`` and ``infinity`` values to integral data types is not specified and is implementation-dependent.
9
9
10
10
.. note::
11
-
When casting a boolean input array to a numeric data type, a value of ``True`` must cast to a numeric value equal to ``1``, and a value of ``False`` must cast to a numeric value equal to ``0``.
11
+
When casting a boolean input array to a real-valued data type, a value of ``True`` must cast to a numeric value equal to ``1``, and a value of ``False`` must cast to a numeric value equal to ``0``.
12
12
13
-
When casting a numeric input array to ``bool``, a value of ``0`` must cast to ``False``, and a non-zero value must cast to ``True``.
13
+
When casting a real-valued input array to ``bool``, a value of ``0`` must cast to ``False``, and a non-zero value must cast to ``True``.
array shape. Must be compatible with ``x`` (see :ref:`broadcasting`). If the array is incompatible with the specified shape, the function should raise an exception.
55
-
56
-
Returns
57
-
-------
58
-
out: array
59
-
an array having a specified shape. Must have the same data type as ``x``.
60
-
"""
61
-
62
30
defcan_cast(from_: Union[dtype, array], to: dtype, /) ->bool:
63
31
"""
64
32
Determines if one data type can be cast to another data type according :ref:`type-promotion` rules.
0 commit comments