Skip to content

Commit 08b2102

Browse files
committed
BUG: fix full() output dtype (depends on fill_value type)
1 parent d48f411 commit 08b2102

1 file changed

Lines changed: 10 additions & 2 deletions

File tree

array_api_strict/_creation_functions.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -239,12 +239,20 @@ def full(
239239

240240
_check_device(device)
241241
_check_valid_dtype(dtype, device)
242-
if dtype is None:
243-
dtype = get_default_dtypes(device)["real floating"]
244242

245243
if not isinstance(fill_value, bool | int | float | complex):
246244
msg = f"Expected Python scalar fill_value, got type {type(fill_value)}"
247245
raise TypeError(msg)
246+
247+
if dtype is None:
248+
if type(fill_value) == bool:
249+
dtype = bool
250+
else:
251+
kind = {
252+
int: "integral", float: "real floating", complex: "complex floating"
253+
}[type(fill_value)]
254+
dtype = get_default_dtypes(device)[kind]
255+
248256
res = np.full(shape, fill_value, dtype=_np_dtype(dtype))
249257
if DType(res.dtype) not in _all_dtypes:
250258
# This will happen if the fill value is not something that NumPy

0 commit comments

Comments
 (0)