|
| 1 | +from ._types import List, Tuple, Union, array, dtype, finfo_object, iinfo_object |
| 2 | + |
| 3 | +def astype(x: array, dtype: dtype, /, *, copy: bool = True) -> array: |
| 4 | + """ |
| 5 | + Copies an array to a specified data type irrespective of :ref:`type-promotion` rules. |
| 6 | +
|
| 7 | + .. note:: |
| 8 | + Casting floating-point ``NaN`` and ``infinity`` values to integral data types is not specified and is implementation-dependent. |
| 9 | +
|
| 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``. |
| 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``. |
| 14 | +
|
| 15 | + Parameters |
| 16 | + ---------- |
| 17 | + x: array |
| 18 | + array to cast. |
| 19 | + dtype: dtype |
| 20 | + desired data type. |
| 21 | + copy: bool |
| 22 | + specifies whether to copy an array when the specified ``dtype`` matches the data type of the input array ``x``. If ``True``, a newly allocated array must always be returned. If ``False`` and the specified ``dtype`` matches the data type of the input array, the input array must be returned; otherwise, a newly allocated must be returned. Default: ``True``. |
| 23 | +
|
| 24 | + Returns |
| 25 | + ------- |
| 26 | + out: array |
| 27 | + an array having the specified data type. The returned array must have the same shape as ``x``. |
| 28 | + """ |
| 29 | + |
| 30 | +def broadcast_arrays(*arrays: array) -> List[array]: |
| 31 | + """ |
| 32 | + Broadcasts one or more arrays against one another. |
| 33 | +
|
| 34 | + Parameters |
| 35 | + ---------- |
| 36 | + arrays: array |
| 37 | + an arbitrary number of to-be broadcasted arrays. |
| 38 | +
|
| 39 | + Returns |
| 40 | + ------- |
| 41 | + out: List[array] |
| 42 | + a list of broadcasted arrays. Each array must have the same shape. Each array must have the same dtype as its corresponding input array. |
| 43 | + """ |
| 44 | + |
| 45 | +def broadcast_to(x: array, /, shape: Tuple[int, ...]) -> array: |
| 46 | + """ |
| 47 | + Broadcasts an array to a specified shape. |
| 48 | +
|
| 49 | + Parameters |
| 50 | + ---------- |
| 51 | + x: array |
| 52 | + array to broadcast. |
| 53 | + shape: Tuple[int, ...] |
| 54 | + 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 | +def can_cast(from_: Union[dtype, array], to: dtype, /) -> bool: |
| 63 | + """ |
| 64 | + Determines if one data type can be cast to another data type according :ref:`type-promotion` rules. |
| 65 | +
|
| 66 | + Parameters |
| 67 | + ---------- |
| 68 | + from_: Union[dtype, array] |
| 69 | + input data type or array from which to cast. |
| 70 | + to: dtype |
| 71 | + desired data type. |
| 72 | +
|
| 73 | + Returns |
| 74 | + ------- |
| 75 | + out: bool |
| 76 | + ``True`` if the cast can occur according to :ref:`type-promotion` rules; otherwise, ``False``. |
| 77 | + """ |
| 78 | + |
| 79 | +def finfo(type: Union[dtype, array], /) -> finfo_object: |
| 80 | + """ |
| 81 | + Machine limits for floating-point data types. |
| 82 | +
|
| 83 | + Parameters |
| 84 | + ---------- |
| 85 | + type: Union[dtype, array] |
| 86 | + the kind of floating-point data-type about which to get information. |
| 87 | +
|
| 88 | + Returns |
| 89 | + ------- |
| 90 | + out: finfo object |
| 91 | + an object having the followng attributes: |
| 92 | +
|
| 93 | + - **bits**: *int* |
| 94 | +
|
| 95 | + number of bits occupied by the floating-point data type. |
| 96 | +
|
| 97 | + - **eps**: *float* |
| 98 | +
|
| 99 | + difference between 1.0 and the next smallest representable floating-point number larger than 1.0 according to the IEEE-754 standard. |
| 100 | +
|
| 101 | + - **max**: *float* |
| 102 | +
|
| 103 | + largest representable number. |
| 104 | +
|
| 105 | + - **min**: *float* |
| 106 | +
|
| 107 | + smallest representable number. |
| 108 | +
|
| 109 | + - **smallest_normal**: *float* |
| 110 | +
|
| 111 | + smallest positive floating-point number with full precision. |
| 112 | + """ |
| 113 | + |
| 114 | +def iinfo(type: Union[dtype, array], /) -> iinfo_object: |
| 115 | + """ |
| 116 | + Machine limits for integer data types. |
| 117 | +
|
| 118 | + Parameters |
| 119 | + ---------- |
| 120 | + type: Union[dtype, array] |
| 121 | + the kind of integer data-type about which to get information. |
| 122 | +
|
| 123 | + Returns |
| 124 | + ------- |
| 125 | + out: iinfo object |
| 126 | + a class with that encapsules the following attributes: |
| 127 | +
|
| 128 | + - **bits**: *int* |
| 129 | +
|
| 130 | + number of bits occupied by the type. |
| 131 | +
|
| 132 | + - **max**: *int* |
| 133 | +
|
| 134 | + largest representable number. |
| 135 | +
|
| 136 | + - **min**: *int* |
| 137 | +
|
| 138 | + smallest representable number. |
| 139 | + """ |
| 140 | + |
| 141 | +def result_type(*arrays_and_dtypes: Union[array, dtype]) -> dtype: |
| 142 | + """ |
| 143 | + Returns the dtype that results from applying the type promotion rules (see :ref:`type-promotion`) to the arguments. |
| 144 | +
|
| 145 | + .. note:: |
| 146 | + If provided mixed dtypes (e.g., integer and floating-point), the returned dtype will be implementation-specific. |
| 147 | +
|
| 148 | + Parameters |
| 149 | + ---------- |
| 150 | + arrays_and_dtypes: Union[array, dtype] |
| 151 | + an arbitrary number of input arrays and/or dtypes. |
| 152 | +
|
| 153 | + Returns |
| 154 | + ------- |
| 155 | + out: dtype |
| 156 | + the dtype resulting from an operation involving the input arrays and dtypes. |
| 157 | + """ |
| 158 | + |
| 159 | +__all__ = ['astype', 'broadcast_arrays', 'broadcast_to', 'can_cast', 'finfo', 'iinfo', 'result_type'] |
0 commit comments