Skip to content

Bound test_full fill values to default dtypes #31

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 21, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions array_api_tests/dtype_helpers.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
from warnings import warn
from typing import NamedTuple

from . import _array_module as xp
from ._array_module import _UndefinedStub


__all__ = [
Expand All @@ -16,6 +18,8 @@
'is_int_dtype',
'is_float_dtype',
'dtype_ranges',
'default_int',
'default_float',
'promotion_table',
'dtype_nbits',
'dtype_signed',
Expand Down Expand Up @@ -84,6 +88,18 @@ class MinMax(NamedTuple):
}


if isinstance(xp.asarray, _UndefinedStub):
default_int = xp.int32
default_float = xp.float32
warn(
'array module does not have attribute asarray. '
'default int is assumed int32, default float is assumed float32'
)
else:
default_int = xp.asarray(int()).dtype
default_float = xp.asarray(float()).dtype


_numeric_promotions = {
# ints
(xp.int8, xp.int8): xp.int8,
Expand Down
14 changes: 12 additions & 2 deletions array_api_tests/test_creation_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from . import xps

from hypothesis import assume, given
from hypothesis.strategies import integers, floats, one_of, none, booleans, just, shared, composite
from hypothesis.strategies import integers, floats, one_of, none, booleans, just, shared, composite, SearchStrategy


int_range = integers(-MAX_ARRAY_SIZE, MAX_ARRAY_SIZE)
Expand Down Expand Up @@ -128,10 +128,20 @@ def test_eye(n_rows, n_cols, k, dtype):
assert a[i, j] == 0, "eye() did not produce a 0 off the diagonal"


default_unsafe_dtypes = [xp.uint64]
if dh.default_int == xp.int32:
default_unsafe_dtypes.extend([xp.uint32, xp.int64])
if dh.default_float == xp.float32:
default_unsafe_dtypes.append(xp.float64)
default_safe_scalar_dtypes: SearchStrategy = xps.scalar_dtypes().filter(
lambda d: d not in default_unsafe_dtypes
)


@composite
def full_fill_values(draw):
kw = draw(shared(kwargs(dtype=none() | xps.scalar_dtypes()), key="full_kw"))
dtype = kw.get("dtype", None) or draw(xps.scalar_dtypes())
dtype = kw.get("dtype", None) or draw(default_safe_scalar_dtypes)
return draw(xps.from_dtype(dtype))


Expand Down