Array API compatible wrapper for :py:func:`np.full `. See its docstring for more information.
(
shape: Union[int, Tuple[int, ...]],
fill_value: Union[int, float],
*,
dtype: Optional[Dtype] = None,
device: Optional[Device] = None,
)
| 158 | |
| 159 | |
| 160 | def full( |
| 161 | shape: Union[int, Tuple[int, ...]], |
| 162 | fill_value: Union[int, float], |
| 163 | *, |
| 164 | dtype: Optional[Dtype] = None, |
| 165 | device: Optional[Device] = None, |
| 166 | ) -> Array: |
| 167 | """ |
| 168 | Array API compatible wrapper for :py:func:`np.full <numpy.full>`. |
| 169 | |
| 170 | See its docstring for more information. |
| 171 | """ |
| 172 | from ._array_object import Array |
| 173 | |
| 174 | _check_valid_dtype(dtype) |
| 175 | if device not in ["cpu", None]: |
| 176 | raise ValueError(f"Unsupported device {device!r}") |
| 177 | if isinstance(fill_value, Array) and fill_value.ndim == 0: |
| 178 | fill_value = fill_value._array |
| 179 | res = np.full(shape, fill_value, dtype=dtype) |
| 180 | if res.dtype not in _all_dtypes: |
| 181 | # This will happen if the fill value is not something that NumPy |
| 182 | # coerces to one of the acceptable dtypes. |
| 183 | raise TypeError("Invalid input to full") |
| 184 | return Array._new(res) |
| 185 | |
| 186 | |
| 187 | def full_like( |