diff --git a/array_api_tests/hypothesis_helpers.py b/array_api_tests/hypothesis_helpers.py index 7bdc4dcf..1851180e 100644 --- a/array_api_tests/hypothesis_helpers.py +++ b/array_api_tests/hypothesis_helpers.py @@ -6,7 +6,7 @@ shared, tuples as hypotheses_tuples, floats, just, composite, one_of, none, booleans) -from hypothesis.extra.numpy import mutually_broadcastable_shapes +from hypothesis_array import mutually_broadcastable_shapes, get_strategies_namespace from hypothesis import assume from .pytest_helpers import nargs @@ -16,10 +16,14 @@ integer_or_boolean_dtype_objects, dtype_objects) from ._array_module import (ones, full, float32, float64, bool as bool_dtype, _UndefinedStub) from . import _array_module +from ._array_module import mod as xp from .function_stubs import elementwise_functions +xps = get_strategies_namespace(xp) + + # Set this to True to not fail tests just because a dtype isn't implemented. # If no compatible dtype is implemented for a given test, the test will fail # with a hypothesis health check error. Note that this functionality will not @@ -89,11 +93,11 @@ def tuples(elements, *, min_size=0, max_size=None, unique_by=None, unique=False) return lists(elements, min_size=min_size, max_size=max_size, unique_by=unique_by, unique=unique).map(tuple) -shapes = tuples(integers(0, 10)).filter(lambda shape: prod(shape) < MAX_ARRAY_SIZE) +shapes = xps.array_shapes(min_side=0).filter(lambda shape: prod(shape) < MAX_ARRAY_SIZE) # Use this to avoid memory errors with NumPy. # See https://github.com/numpy/numpy/issues/15753 -shapes = tuples(integers(0, 10)).filter( +shapes = xps.array_shapes(min_side=0).filter( lambda shape: prod([i for i in shape if i]) < MAX_ARRAY_SIZE) two_mutually_broadcastable_shapes = mutually_broadcastable_shapes(num_shapes=2)\ @@ -121,8 +125,17 @@ def two_broadcastable_shapes(draw, shapes=shapes): nonbroadcastable_ones_array_two_args = hypotheses_tuples(ones_arrays, ones_arrays) -# TODO: Generate general arrays here, rather than just scalars. -numeric_arrays = builds(full, just((1,)), floats()) +floating_arrays = xps.arrays(dtype=xps.floating_dtypes(), shape=xps.array_shapes()) + +@composite +def broadcastable_floating_array_pairs(draw): + dtype = draw(xps.floating_dtypes()) + broadcastable_shapes = draw(xps.mutually_broadcastable_shapes(2, min_dims=1)) + shape1, shape2 = broadcastable_shapes.input_shapes + assume(len(shape1) >= len(shape2)) + array1 = draw(xps.arrays(dtype=dtype, shape=shape1)) + array2 = draw(xps.arrays(dtype=dtype, shape=shape2)) + return array1, array2 @composite def scalars(draw, dtypes, finite=False): @@ -227,3 +240,5 @@ def multiaxis_indices(draw, shapes): extra = draw(lists(one_of(integer_indices(sizes), slices(sizes)), min_size=0, max_size=3)) res += extra return tuple(res) + + diff --git a/array_api_tests/special_cases/test_abs.py b/array_api_tests/special_cases/test_abs.py index 4ed04d02..17e3c464 100644 --- a/array_api_tests/special_cases/test_abs.py +++ b/array_api_tests/special_cases/test_abs.py @@ -8,13 +8,13 @@ """ from ..array_helpers import NaN, assert_exactly_equal, exactly_equal, infinity, zero -from ..hypothesis_helpers import numeric_arrays +from ..hypothesis_helpers import floating_arrays, broadcastable_floating_array_pairs from .._array_module import abs from hypothesis import given -@given(numeric_arrays) +@given(floating_arrays) def test_abs_special_cases_one_arg_equal_1(arg1): """ Special case test for `abs(x, /)`: @@ -27,7 +27,7 @@ def test_abs_special_cases_one_arg_equal_1(arg1): assert_exactly_equal(res[mask], (NaN(arg1.shape, arg1.dtype))[mask]) -@given(numeric_arrays) +@given(floating_arrays) def test_abs_special_cases_one_arg_equal_2(arg1): """ Special case test for `abs(x, /)`: @@ -40,7 +40,7 @@ def test_abs_special_cases_one_arg_equal_2(arg1): assert_exactly_equal(res[mask], (zero(arg1.shape, arg1.dtype))[mask]) -@given(numeric_arrays) +@given(floating_arrays) def test_abs_special_cases_one_arg_equal_3(arg1): """ Special case test for `abs(x, /)`: diff --git a/array_api_tests/special_cases/test_acos.py b/array_api_tests/special_cases/test_acos.py index b1c3cb56..b2788c3e 100644 --- a/array_api_tests/special_cases/test_acos.py +++ b/array_api_tests/special_cases/test_acos.py @@ -8,13 +8,13 @@ """ from ..array_helpers import NaN, assert_exactly_equal, exactly_equal, greater, less, one, zero -from ..hypothesis_helpers import numeric_arrays +from ..hypothesis_helpers import floating_arrays, broadcastable_floating_array_pairs from .._array_module import acos from hypothesis import given -@given(numeric_arrays) +@given(floating_arrays) def test_acos_special_cases_one_arg_equal_1(arg1): """ Special case test for `acos(x, /)`: @@ -27,7 +27,7 @@ def test_acos_special_cases_one_arg_equal_1(arg1): assert_exactly_equal(res[mask], (NaN(arg1.shape, arg1.dtype))[mask]) -@given(numeric_arrays) +@given(floating_arrays) def test_acos_special_cases_one_arg_equal_2(arg1): """ Special case test for `acos(x, /)`: @@ -40,7 +40,7 @@ def test_acos_special_cases_one_arg_equal_2(arg1): assert_exactly_equal(res[mask], (zero(arg1.shape, arg1.dtype))[mask]) -@given(numeric_arrays) +@given(floating_arrays) def test_acos_special_cases_one_arg_greater(arg1): """ Special case test for `acos(x, /)`: @@ -53,7 +53,7 @@ def test_acos_special_cases_one_arg_greater(arg1): assert_exactly_equal(res[mask], (NaN(arg1.shape, arg1.dtype))[mask]) -@given(numeric_arrays) +@given(floating_arrays) def test_acos_special_cases_one_arg_less(arg1): """ Special case test for `acos(x, /)`: diff --git a/array_api_tests/special_cases/test_acosh.py b/array_api_tests/special_cases/test_acosh.py index 8749eaf2..d98c232a 100644 --- a/array_api_tests/special_cases/test_acosh.py +++ b/array_api_tests/special_cases/test_acosh.py @@ -8,13 +8,13 @@ """ from ..array_helpers import NaN, assert_exactly_equal, exactly_equal, infinity, less, one, zero -from ..hypothesis_helpers import numeric_arrays +from ..hypothesis_helpers import floating_arrays, broadcastable_floating_array_pairs from .._array_module import acosh from hypothesis import given -@given(numeric_arrays) +@given(floating_arrays) def test_acosh_special_cases_one_arg_equal_1(arg1): """ Special case test for `acosh(x, /)`: @@ -27,7 +27,7 @@ def test_acosh_special_cases_one_arg_equal_1(arg1): assert_exactly_equal(res[mask], (NaN(arg1.shape, arg1.dtype))[mask]) -@given(numeric_arrays) +@given(floating_arrays) def test_acosh_special_cases_one_arg_equal_2(arg1): """ Special case test for `acosh(x, /)`: @@ -40,7 +40,7 @@ def test_acosh_special_cases_one_arg_equal_2(arg1): assert_exactly_equal(res[mask], (zero(arg1.shape, arg1.dtype))[mask]) -@given(numeric_arrays) +@given(floating_arrays) def test_acosh_special_cases_one_arg_equal_3(arg1): """ Special case test for `acosh(x, /)`: @@ -53,7 +53,7 @@ def test_acosh_special_cases_one_arg_equal_3(arg1): assert_exactly_equal(res[mask], (infinity(arg1.shape, arg1.dtype))[mask]) -@given(numeric_arrays) +@given(floating_arrays) def test_acosh_special_cases_one_arg_less(arg1): """ Special case test for `acosh(x, /)`: diff --git a/array_api_tests/special_cases/test_add.py b/array_api_tests/special_cases/test_add.py index eaccb803..5f9d926b 100644 --- a/array_api_tests/special_cases/test_add.py +++ b/array_api_tests/special_cases/test_add.py @@ -9,215 +9,231 @@ from ..array_helpers import (NaN, assert_exactly_equal, exactly_equal, infinity, isfinite, logical_and, logical_or, non_zero, zero) -from ..hypothesis_helpers import numeric_arrays +from ..hypothesis_helpers import floating_arrays, broadcastable_floating_array_pairs from .._array_module import add from hypothesis import given -@given(numeric_arrays, numeric_arrays) -def test_add_special_cases_two_args_either(arg1, arg2): +@given(broadcastable_floating_array_pairs()) +def test_add_special_cases_two_args_either(pair): """ Special case test for `add(x1, x2, /)`: - If either `x1_i` or `x2_i` is `NaN`, the result is `NaN`. """ + arg1, arg2 = pair res = add(arg1, arg2) mask = logical_or(exactly_equal(arg1, NaN(arg1.shape, arg1.dtype)), exactly_equal(arg2, NaN(arg1.shape, arg1.dtype))) assert_exactly_equal(res[mask], (NaN(arg1.shape, arg1.dtype))[mask]) -@given(numeric_arrays, numeric_arrays) -def test_add_special_cases_two_args_equal__equal_1(arg1, arg2): +@given(broadcastable_floating_array_pairs()) +def test_add_special_cases_two_args_equal__equal_1(pair): """ Special case test for `add(x1, x2, /)`: - If `x1_i` is `+infinity` and `x2_i` is `-infinity`, the result is `NaN`. """ + arg1, arg2 = pair res = add(arg1, arg2) mask = logical_and(exactly_equal(arg1, infinity(arg1.shape, arg1.dtype)), exactly_equal(arg2, -infinity(arg2.shape, arg2.dtype))) assert_exactly_equal(res[mask], (NaN(arg1.shape, arg1.dtype))[mask]) -@given(numeric_arrays, numeric_arrays) -def test_add_special_cases_two_args_equal__equal_2(arg1, arg2): +@given(broadcastable_floating_array_pairs()) +def test_add_special_cases_two_args_equal__equal_2(pair): """ Special case test for `add(x1, x2, /)`: - If `x1_i` is `-infinity` and `x2_i` is `+infinity`, the result is `NaN`. """ + arg1, arg2 = pair res = add(arg1, arg2) mask = logical_and(exactly_equal(arg1, -infinity(arg1.shape, arg1.dtype)), exactly_equal(arg2, infinity(arg2.shape, arg2.dtype))) assert_exactly_equal(res[mask], (NaN(arg1.shape, arg1.dtype))[mask]) -@given(numeric_arrays, numeric_arrays) -def test_add_special_cases_two_args_equal__equal_3(arg1, arg2): +@given(broadcastable_floating_array_pairs()) +def test_add_special_cases_two_args_equal__equal_3(pair): """ Special case test for `add(x1, x2, /)`: - If `x1_i` is `+infinity` and `x2_i` is `+infinity`, the result is `+infinity`. """ + arg1, arg2 = pair res = add(arg1, arg2) mask = logical_and(exactly_equal(arg1, infinity(arg1.shape, arg1.dtype)), exactly_equal(arg2, infinity(arg2.shape, arg2.dtype))) assert_exactly_equal(res[mask], (infinity(arg1.shape, arg1.dtype))[mask]) -@given(numeric_arrays, numeric_arrays) -def test_add_special_cases_two_args_equal__equal_4(arg1, arg2): +@given(broadcastable_floating_array_pairs()) +def test_add_special_cases_two_args_equal__equal_4(pair): """ Special case test for `add(x1, x2, /)`: - If `x1_i` is `-infinity` and `x2_i` is `-infinity`, the result is `-infinity`. """ + arg1, arg2 = pair res = add(arg1, arg2) mask = logical_and(exactly_equal(arg1, -infinity(arg1.shape, arg1.dtype)), exactly_equal(arg2, -infinity(arg2.shape, arg2.dtype))) assert_exactly_equal(res[mask], (-infinity(arg1.shape, arg1.dtype))[mask]) -@given(numeric_arrays, numeric_arrays) -def test_add_special_cases_two_args_equal__equal_5(arg1, arg2): +@given(broadcastable_floating_array_pairs()) +def test_add_special_cases_two_args_equal__equal_5(pair): """ Special case test for `add(x1, x2, /)`: - If `x1_i` is `+infinity` and `x2_i` is a finite number, the result is `+infinity`. """ + arg1, arg2 = pair res = add(arg1, arg2) mask = logical_and(exactly_equal(arg1, infinity(arg1.shape, arg1.dtype)), isfinite(arg2)) assert_exactly_equal(res[mask], (infinity(arg1.shape, arg1.dtype))[mask]) -@given(numeric_arrays, numeric_arrays) -def test_add_special_cases_two_args_equal__equal_6(arg1, arg2): +@given(broadcastable_floating_array_pairs()) +def test_add_special_cases_two_args_equal__equal_6(pair): """ Special case test for `add(x1, x2, /)`: - If `x1_i` is `-infinity` and `x2_i` is a finite number, the result is `-infinity`. """ + arg1, arg2 = pair res = add(arg1, arg2) mask = logical_and(exactly_equal(arg1, -infinity(arg1.shape, arg1.dtype)), isfinite(arg2)) assert_exactly_equal(res[mask], (-infinity(arg1.shape, arg1.dtype))[mask]) -@given(numeric_arrays, numeric_arrays) -def test_add_special_cases_two_args_equal__equal_7(arg1, arg2): +@given(broadcastable_floating_array_pairs()) +def test_add_special_cases_two_args_equal__equal_7(pair): """ Special case test for `add(x1, x2, /)`: - If `x1_i` is a finite number and `x2_i` is `+infinity`, the result is `+infinity`. """ + arg1, arg2 = pair res = add(arg1, arg2) mask = logical_and(isfinite(arg1), exactly_equal(arg2, infinity(arg2.shape, arg2.dtype))) assert_exactly_equal(res[mask], (infinity(arg1.shape, arg1.dtype))[mask]) -@given(numeric_arrays, numeric_arrays) -def test_add_special_cases_two_args_equal__equal_8(arg1, arg2): +@given(broadcastable_floating_array_pairs()) +def test_add_special_cases_two_args_equal__equal_8(pair): """ Special case test for `add(x1, x2, /)`: - If `x1_i` is a finite number and `x2_i` is `-infinity`, the result is `-infinity`. """ + arg1, arg2 = pair res = add(arg1, arg2) mask = logical_and(isfinite(arg1), exactly_equal(arg2, -infinity(arg2.shape, arg2.dtype))) assert_exactly_equal(res[mask], (-infinity(arg1.shape, arg1.dtype))[mask]) -@given(numeric_arrays, numeric_arrays) -def test_add_special_cases_two_args_equal__equal_9(arg1, arg2): +@given(broadcastable_floating_array_pairs()) +def test_add_special_cases_two_args_equal__equal_9(pair): """ Special case test for `add(x1, x2, /)`: - If `x1_i` is `-0` and `x2_i` is `-0`, the result is `-0`. """ + arg1, arg2 = pair res = add(arg1, arg2) mask = logical_and(exactly_equal(arg1, -zero(arg1.shape, arg1.dtype)), exactly_equal(arg2, -zero(arg2.shape, arg2.dtype))) assert_exactly_equal(res[mask], (-zero(arg1.shape, arg1.dtype))[mask]) -@given(numeric_arrays, numeric_arrays) -def test_add_special_cases_two_args_equal__equal_10(arg1, arg2): +@given(broadcastable_floating_array_pairs()) +def test_add_special_cases_two_args_equal__equal_10(pair): """ Special case test for `add(x1, x2, /)`: - If `x1_i` is `-0` and `x2_i` is `+0`, the result is `+0`. """ + arg1, arg2 = pair res = add(arg1, arg2) mask = logical_and(exactly_equal(arg1, -zero(arg1.shape, arg1.dtype)), exactly_equal(arg2, zero(arg2.shape, arg2.dtype))) assert_exactly_equal(res[mask], (zero(arg1.shape, arg1.dtype))[mask]) -@given(numeric_arrays, numeric_arrays) -def test_add_special_cases_two_args_equal__equal_11(arg1, arg2): +@given(broadcastable_floating_array_pairs()) +def test_add_special_cases_two_args_equal__equal_11(pair): """ Special case test for `add(x1, x2, /)`: - If `x1_i` is `+0` and `x2_i` is `-0`, the result is `+0`. """ + arg1, arg2 = pair res = add(arg1, arg2) mask = logical_and(exactly_equal(arg1, zero(arg1.shape, arg1.dtype)), exactly_equal(arg2, -zero(arg2.shape, arg2.dtype))) assert_exactly_equal(res[mask], (zero(arg1.shape, arg1.dtype))[mask]) -@given(numeric_arrays, numeric_arrays) -def test_add_special_cases_two_args_equal__equal_12(arg1, arg2): +@given(broadcastable_floating_array_pairs()) +def test_add_special_cases_two_args_equal__equal_12(pair): """ Special case test for `add(x1, x2, /)`: - If `x1_i` is `+0` and `x2_i` is `+0`, the result is `+0`. """ + arg1, arg2 = pair res = add(arg1, arg2) mask = logical_and(exactly_equal(arg1, zero(arg1.shape, arg1.dtype)), exactly_equal(arg2, zero(arg2.shape, arg2.dtype))) assert_exactly_equal(res[mask], (zero(arg1.shape, arg1.dtype))[mask]) -@given(numeric_arrays, numeric_arrays) -def test_add_special_cases_two_args_equal__equal_13(arg1, arg2): +@given(broadcastable_floating_array_pairs()) +def test_add_special_cases_two_args_equal__equal_13(pair): """ Special case test for `add(x1, x2, /)`: - If `x1_i` is a nonzero finite number and `x2_i` is `-x1_i`, the result is `+0`. """ + arg1, arg2 = pair res = add(arg1, arg2) mask = logical_and(logical_and(isfinite(arg1), non_zero(arg1)), exactly_equal(arg2, -arg1)) assert_exactly_equal(res[mask], (zero(arg1.shape, arg1.dtype))[mask]) -@given(numeric_arrays, numeric_arrays) -def test_add_special_cases_two_args_either__equal(arg1, arg2): +@given(broadcastable_floating_array_pairs()) +def test_add_special_cases_two_args_either__equal(pair): """ Special case test for `add(x1, x2, /)`: - If `x1_i` is either `+0` or `-0` and `x2_i` is a nonzero finite number, the result is `x2_i`. """ + arg1, arg2 = pair res = add(arg1, arg2) mask = logical_and(logical_or(exactly_equal(arg1, zero(arg1.shape, arg1.dtype)), exactly_equal(arg1, -zero(arg1.shape, arg1.dtype))), logical_and(isfinite(arg2), non_zero(arg2))) assert_exactly_equal(res[mask], (arg2)[mask]) -@given(numeric_arrays, numeric_arrays) -def test_add_special_cases_two_args_equal__either(arg1, arg2): +@given(broadcastable_floating_array_pairs()) +def test_add_special_cases_two_args_equal__either(pair): """ Special case test for `add(x1, x2, /)`: - If `x1_i` is a nonzero finite number and `x2_i` is either `+0` or `-0`, the result is `x1_i`. """ + arg1, arg2 = pair res = add(arg1, arg2) mask = logical_and(logical_and(isfinite(arg1), non_zero(arg1)), logical_or(exactly_equal(arg2, zero(arg2.shape, arg2.dtype)), exactly_equal(arg2, -zero(arg2.shape, arg2.dtype)))) assert_exactly_equal(res[mask], (arg1)[mask]) diff --git a/array_api_tests/special_cases/test_asin.py b/array_api_tests/special_cases/test_asin.py index 0a41b716..33793be6 100644 --- a/array_api_tests/special_cases/test_asin.py +++ b/array_api_tests/special_cases/test_asin.py @@ -8,13 +8,13 @@ """ from ..array_helpers import NaN, assert_exactly_equal, exactly_equal, greater, less, one, zero -from ..hypothesis_helpers import numeric_arrays +from ..hypothesis_helpers import floating_arrays, broadcastable_floating_array_pairs from .._array_module import asin from hypothesis import given -@given(numeric_arrays) +@given(floating_arrays) def test_asin_special_cases_one_arg_equal_1(arg1): """ Special case test for `asin(x, /)`: @@ -27,7 +27,7 @@ def test_asin_special_cases_one_arg_equal_1(arg1): assert_exactly_equal(res[mask], (NaN(arg1.shape, arg1.dtype))[mask]) -@given(numeric_arrays) +@given(floating_arrays) def test_asin_special_cases_one_arg_equal_2(arg1): """ Special case test for `asin(x, /)`: @@ -40,7 +40,7 @@ def test_asin_special_cases_one_arg_equal_2(arg1): assert_exactly_equal(res[mask], (zero(arg1.shape, arg1.dtype))[mask]) -@given(numeric_arrays) +@given(floating_arrays) def test_asin_special_cases_one_arg_equal_3(arg1): """ Special case test for `asin(x, /)`: @@ -53,7 +53,7 @@ def test_asin_special_cases_one_arg_equal_3(arg1): assert_exactly_equal(res[mask], (-zero(arg1.shape, arg1.dtype))[mask]) -@given(numeric_arrays) +@given(floating_arrays) def test_asin_special_cases_one_arg_greater(arg1): """ Special case test for `asin(x, /)`: @@ -66,7 +66,7 @@ def test_asin_special_cases_one_arg_greater(arg1): assert_exactly_equal(res[mask], (NaN(arg1.shape, arg1.dtype))[mask]) -@given(numeric_arrays) +@given(floating_arrays) def test_asin_special_cases_one_arg_less(arg1): """ Special case test for `asin(x, /)`: diff --git a/array_api_tests/special_cases/test_asinh.py b/array_api_tests/special_cases/test_asinh.py index a54d3346..f5dc3cec 100644 --- a/array_api_tests/special_cases/test_asinh.py +++ b/array_api_tests/special_cases/test_asinh.py @@ -8,13 +8,13 @@ """ from ..array_helpers import NaN, assert_exactly_equal, exactly_equal, infinity, zero -from ..hypothesis_helpers import numeric_arrays +from ..hypothesis_helpers import floating_arrays, broadcastable_floating_array_pairs from .._array_module import asinh from hypothesis import given -@given(numeric_arrays) +@given(floating_arrays) def test_asinh_special_cases_one_arg_equal_1(arg1): """ Special case test for `asinh(x, /)`: @@ -27,7 +27,7 @@ def test_asinh_special_cases_one_arg_equal_1(arg1): assert_exactly_equal(res[mask], (NaN(arg1.shape, arg1.dtype))[mask]) -@given(numeric_arrays) +@given(floating_arrays) def test_asinh_special_cases_one_arg_equal_2(arg1): """ Special case test for `asinh(x, /)`: @@ -40,7 +40,7 @@ def test_asinh_special_cases_one_arg_equal_2(arg1): assert_exactly_equal(res[mask], (zero(arg1.shape, arg1.dtype))[mask]) -@given(numeric_arrays) +@given(floating_arrays) def test_asinh_special_cases_one_arg_equal_3(arg1): """ Special case test for `asinh(x, /)`: @@ -53,7 +53,7 @@ def test_asinh_special_cases_one_arg_equal_3(arg1): assert_exactly_equal(res[mask], (-zero(arg1.shape, arg1.dtype))[mask]) -@given(numeric_arrays) +@given(floating_arrays) def test_asinh_special_cases_one_arg_equal_4(arg1): """ Special case test for `asinh(x, /)`: @@ -66,7 +66,7 @@ def test_asinh_special_cases_one_arg_equal_4(arg1): assert_exactly_equal(res[mask], (infinity(arg1.shape, arg1.dtype))[mask]) -@given(numeric_arrays) +@given(floating_arrays) def test_asinh_special_cases_one_arg_equal_5(arg1): """ Special case test for `asinh(x, /)`: diff --git a/array_api_tests/special_cases/test_atan.py b/array_api_tests/special_cases/test_atan.py index 4b6936ed..ab086351 100644 --- a/array_api_tests/special_cases/test_atan.py +++ b/array_api_tests/special_cases/test_atan.py @@ -8,13 +8,13 @@ """ from ..array_helpers import NaN, assert_exactly_equal, exactly_equal, infinity, zero, π -from ..hypothesis_helpers import numeric_arrays +from ..hypothesis_helpers import floating_arrays, broadcastable_floating_array_pairs from .._array_module import atan from hypothesis import given -@given(numeric_arrays) +@given(floating_arrays) def test_atan_special_cases_one_arg_equal_1(arg1): """ Special case test for `atan(x, /)`: @@ -27,7 +27,7 @@ def test_atan_special_cases_one_arg_equal_1(arg1): assert_exactly_equal(res[mask], (NaN(arg1.shape, arg1.dtype))[mask]) -@given(numeric_arrays) +@given(floating_arrays) def test_atan_special_cases_one_arg_equal_2(arg1): """ Special case test for `atan(x, /)`: @@ -40,7 +40,7 @@ def test_atan_special_cases_one_arg_equal_2(arg1): assert_exactly_equal(res[mask], (zero(arg1.shape, arg1.dtype))[mask]) -@given(numeric_arrays) +@given(floating_arrays) def test_atan_special_cases_one_arg_equal_3(arg1): """ Special case test for `atan(x, /)`: @@ -53,7 +53,7 @@ def test_atan_special_cases_one_arg_equal_3(arg1): assert_exactly_equal(res[mask], (-zero(arg1.shape, arg1.dtype))[mask]) -@given(numeric_arrays) +@given(floating_arrays) def test_atan_special_cases_one_arg_equal_4(arg1): """ Special case test for `atan(x, /)`: @@ -66,7 +66,7 @@ def test_atan_special_cases_one_arg_equal_4(arg1): assert_exactly_equal(res[mask], (+π(arg1.shape, arg1.dtype)/2)[mask]) -@given(numeric_arrays) +@given(floating_arrays) def test_atan_special_cases_one_arg_equal_5(arg1): """ Special case test for `atan(x, /)`: diff --git a/array_api_tests/special_cases/test_atan2.py b/array_api_tests/special_cases/test_atan2.py index 9d7452e7..5123877d 100644 --- a/array_api_tests/special_cases/test_atan2.py +++ b/array_api_tests/special_cases/test_atan2.py @@ -9,306 +9,329 @@ from ..array_helpers import (NaN, assert_exactly_equal, exactly_equal, greater, infinity, isfinite, less, logical_and, logical_or, zero, π) -from ..hypothesis_helpers import numeric_arrays +from ..hypothesis_helpers import floating_arrays, broadcastable_floating_array_pairs from .._array_module import atan2 from hypothesis import given -@given(numeric_arrays, numeric_arrays) -def test_atan2_special_cases_two_args_either(arg1, arg2): +@given(broadcastable_floating_array_pairs()) +def test_atan2_special_cases_two_args_either(pair): """ Special case test for `atan2(x1, x2, /)`: - If either `x1_i` or `x2_i` is `NaN`, the result is `NaN`. """ + arg1, arg2 = pair res = atan2(arg1, arg2) mask = logical_or(exactly_equal(arg1, NaN(arg1.shape, arg1.dtype)), exactly_equal(arg2, NaN(arg1.shape, arg1.dtype))) assert_exactly_equal(res[mask], (NaN(arg1.shape, arg1.dtype))[mask]) -@given(numeric_arrays, numeric_arrays) -def test_atan2_special_cases_two_args_greater__equal_1(arg1, arg2): +@given(broadcastable_floating_array_pairs()) +def test_atan2_special_cases_two_args_greater__equal_1(pair): """ Special case test for `atan2(x1, x2, /)`: - If `x1_i` is greater than `0` and `x2_i` is `+0`, the result is an implementation-dependent approximation to `+π/2`. """ + arg1, arg2 = pair res = atan2(arg1, arg2) mask = logical_and(greater(arg1, zero(arg1.shape, arg1.dtype)), exactly_equal(arg2, zero(arg2.shape, arg2.dtype))) assert_exactly_equal(res[mask], (+π(arg1.shape, arg1.dtype)/2)[mask]) -@given(numeric_arrays, numeric_arrays) -def test_atan2_special_cases_two_args_greater__equal_2(arg1, arg2): +@given(broadcastable_floating_array_pairs()) +def test_atan2_special_cases_two_args_greater__equal_2(pair): """ Special case test for `atan2(x1, x2, /)`: - If `x1_i` is greater than `0` and `x2_i` is `-0`, the result is an implementation-dependent approximation to `+π/2`. """ + arg1, arg2 = pair res = atan2(arg1, arg2) mask = logical_and(greater(arg1, zero(arg1.shape, arg1.dtype)), exactly_equal(arg2, -zero(arg2.shape, arg2.dtype))) assert_exactly_equal(res[mask], (+π(arg1.shape, arg1.dtype)/2)[mask]) -@given(numeric_arrays, numeric_arrays) -def test_atan2_special_cases_two_args_equal__greater_1(arg1, arg2): +@given(broadcastable_floating_array_pairs()) +def test_atan2_special_cases_two_args_equal__greater_1(pair): """ Special case test for `atan2(x1, x2, /)`: - If `x1_i` is `+0` and `x2_i` is greater than `0`, the result is `+0`. """ + arg1, arg2 = pair res = atan2(arg1, arg2) mask = logical_and(exactly_equal(arg1, zero(arg1.shape, arg1.dtype)), greater(arg2, zero(arg2.shape, arg2.dtype))) assert_exactly_equal(res[mask], (zero(arg1.shape, arg1.dtype))[mask]) -@given(numeric_arrays, numeric_arrays) -def test_atan2_special_cases_two_args_equal__greater_2(arg1, arg2): +@given(broadcastable_floating_array_pairs()) +def test_atan2_special_cases_two_args_equal__greater_2(pair): """ Special case test for `atan2(x1, x2, /)`: - If `x1_i` is `-0` and `x2_i` is greater than `0`, the result is `-0`. """ + arg1, arg2 = pair res = atan2(arg1, arg2) mask = logical_and(exactly_equal(arg1, -zero(arg1.shape, arg1.dtype)), greater(arg2, zero(arg2.shape, arg2.dtype))) assert_exactly_equal(res[mask], (-zero(arg1.shape, arg1.dtype))[mask]) -@given(numeric_arrays, numeric_arrays) -def test_atan2_special_cases_two_args_equal__equal_1(arg1, arg2): +@given(broadcastable_floating_array_pairs()) +def test_atan2_special_cases_two_args_equal__equal_1(pair): """ Special case test for `atan2(x1, x2, /)`: - If `x1_i` is `+0` and `x2_i` is `+0`, the result is `+0`. """ + arg1, arg2 = pair res = atan2(arg1, arg2) mask = logical_and(exactly_equal(arg1, zero(arg1.shape, arg1.dtype)), exactly_equal(arg2, zero(arg2.shape, arg2.dtype))) assert_exactly_equal(res[mask], (zero(arg1.shape, arg1.dtype))[mask]) -@given(numeric_arrays, numeric_arrays) -def test_atan2_special_cases_two_args_equal__equal_2(arg1, arg2): +@given(broadcastable_floating_array_pairs()) +def test_atan2_special_cases_two_args_equal__equal_2(pair): """ Special case test for `atan2(x1, x2, /)`: - If `x1_i` is `+0` and `x2_i` is `-0`, the result is an implementation-dependent approximation to `+π`. """ + arg1, arg2 = pair res = atan2(arg1, arg2) mask = logical_and(exactly_equal(arg1, zero(arg1.shape, arg1.dtype)), exactly_equal(arg2, -zero(arg2.shape, arg2.dtype))) assert_exactly_equal(res[mask], (+π(arg1.shape, arg1.dtype))[mask]) -@given(numeric_arrays, numeric_arrays) -def test_atan2_special_cases_two_args_equal__equal_3(arg1, arg2): +@given(broadcastable_floating_array_pairs()) +def test_atan2_special_cases_two_args_equal__equal_3(pair): """ Special case test for `atan2(x1, x2, /)`: - If `x1_i` is `-0` and `x2_i` is `+0`, the result is `-0`. """ + arg1, arg2 = pair res = atan2(arg1, arg2) mask = logical_and(exactly_equal(arg1, -zero(arg1.shape, arg1.dtype)), exactly_equal(arg2, zero(arg2.shape, arg2.dtype))) assert_exactly_equal(res[mask], (-zero(arg1.shape, arg1.dtype))[mask]) -@given(numeric_arrays, numeric_arrays) -def test_atan2_special_cases_two_args_equal__equal_4(arg1, arg2): +@given(broadcastable_floating_array_pairs()) +def test_atan2_special_cases_two_args_equal__equal_4(pair): """ Special case test for `atan2(x1, x2, /)`: - If `x1_i` is `-0` and `x2_i` is `-0`, the result is an implementation-dependent approximation to `-π`. """ + arg1, arg2 = pair res = atan2(arg1, arg2) mask = logical_and(exactly_equal(arg1, -zero(arg1.shape, arg1.dtype)), exactly_equal(arg2, -zero(arg2.shape, arg2.dtype))) assert_exactly_equal(res[mask], (-π(arg1.shape, arg1.dtype))[mask]) -@given(numeric_arrays, numeric_arrays) -def test_atan2_special_cases_two_args_equal__equal_5(arg1, arg2): +@given(broadcastable_floating_array_pairs()) +def test_atan2_special_cases_two_args_equal__equal_5(pair): """ Special case test for `atan2(x1, x2, /)`: - If `x1_i` is `+infinity` and `x2_i` is finite, the result is an implementation-dependent approximation to `+π/2`. """ + arg1, arg2 = pair res = atan2(arg1, arg2) mask = logical_and(exactly_equal(arg1, infinity(arg1.shape, arg1.dtype)), isfinite(arg2)) assert_exactly_equal(res[mask], (+π(arg1.shape, arg1.dtype)/2)[mask]) -@given(numeric_arrays, numeric_arrays) -def test_atan2_special_cases_two_args_equal__equal_6(arg1, arg2): +@given(broadcastable_floating_array_pairs()) +def test_atan2_special_cases_two_args_equal__equal_6(pair): """ Special case test for `atan2(x1, x2, /)`: - If `x1_i` is `-infinity` and `x2_i` is finite, the result is an implementation-dependent approximation to `-π/2`. """ + arg1, arg2 = pair res = atan2(arg1, arg2) mask = logical_and(exactly_equal(arg1, -infinity(arg1.shape, arg1.dtype)), isfinite(arg2)) assert_exactly_equal(res[mask], (-π(arg1.shape, arg1.dtype)/2)[mask]) -@given(numeric_arrays, numeric_arrays) -def test_atan2_special_cases_two_args_equal__equal_7(arg1, arg2): +@given(broadcastable_floating_array_pairs()) +def test_atan2_special_cases_two_args_equal__equal_7(pair): """ Special case test for `atan2(x1, x2, /)`: - If `x1_i` is `+infinity` and `x2_i` is `+infinity`, the result is an implementation-dependent approximation to `+π/4`. """ + arg1, arg2 = pair res = atan2(arg1, arg2) mask = logical_and(exactly_equal(arg1, infinity(arg1.shape, arg1.dtype)), exactly_equal(arg2, infinity(arg2.shape, arg2.dtype))) assert_exactly_equal(res[mask], (+π(arg1.shape, arg1.dtype)/4)[mask]) -@given(numeric_arrays, numeric_arrays) -def test_atan2_special_cases_two_args_equal__equal_8(arg1, arg2): +@given(broadcastable_floating_array_pairs()) +def test_atan2_special_cases_two_args_equal__equal_8(pair): """ Special case test for `atan2(x1, x2, /)`: - If `x1_i` is `+infinity` and `x2_i` is `-infinity`, the result is an implementation-dependent approximation to `+3π/4`. """ + arg1, arg2 = pair res = atan2(arg1, arg2) mask = logical_and(exactly_equal(arg1, infinity(arg1.shape, arg1.dtype)), exactly_equal(arg2, -infinity(arg2.shape, arg2.dtype))) assert_exactly_equal(res[mask], (+3*π(arg1.shape, arg1.dtype)/4)[mask]) -@given(numeric_arrays, numeric_arrays) -def test_atan2_special_cases_two_args_equal__equal_9(arg1, arg2): +@given(broadcastable_floating_array_pairs()) +def test_atan2_special_cases_two_args_equal__equal_9(pair): """ Special case test for `atan2(x1, x2, /)`: - If `x1_i` is `-infinity` and `x2_i` is `+infinity`, the result is an implementation-dependent approximation to `-π/4`. """ + arg1, arg2 = pair res = atan2(arg1, arg2) mask = logical_and(exactly_equal(arg1, -infinity(arg1.shape, arg1.dtype)), exactly_equal(arg2, infinity(arg2.shape, arg2.dtype))) assert_exactly_equal(res[mask], (-π(arg1.shape, arg1.dtype)/4)[mask]) -@given(numeric_arrays, numeric_arrays) -def test_atan2_special_cases_two_args_equal__equal_10(arg1, arg2): +@given(broadcastable_floating_array_pairs()) +def test_atan2_special_cases_two_args_equal__equal_10(pair): """ Special case test for `atan2(x1, x2, /)`: - If `x1_i` is `-infinity` and `x2_i` is `-infinity`, the result is an implementation-dependent approximation to `-3π/4`. """ + arg1, arg2 = pair res = atan2(arg1, arg2) mask = logical_and(exactly_equal(arg1, -infinity(arg1.shape, arg1.dtype)), exactly_equal(arg2, -infinity(arg2.shape, arg2.dtype))) assert_exactly_equal(res[mask], (-3*π(arg1.shape, arg1.dtype)/4)[mask]) -@given(numeric_arrays, numeric_arrays) -def test_atan2_special_cases_two_args_equal__less_1(arg1, arg2): +@given(broadcastable_floating_array_pairs()) +def test_atan2_special_cases_two_args_equal__less_1(pair): """ Special case test for `atan2(x1, x2, /)`: - If `x1_i` is `+0` and `x2_i` is less than `0`, the result is an implementation-dependent approximation to `+π`. """ + arg1, arg2 = pair res = atan2(arg1, arg2) mask = logical_and(exactly_equal(arg1, zero(arg1.shape, arg1.dtype)), less(arg2, zero(arg2.shape, arg2.dtype))) assert_exactly_equal(res[mask], (+π(arg1.shape, arg1.dtype))[mask]) -@given(numeric_arrays, numeric_arrays) -def test_atan2_special_cases_two_args_equal__less_2(arg1, arg2): +@given(broadcastable_floating_array_pairs()) +def test_atan2_special_cases_two_args_equal__less_2(pair): """ Special case test for `atan2(x1, x2, /)`: - If `x1_i` is `-0` and `x2_i` is less than `0`, the result is an implementation-dependent approximation to `-π`. """ + arg1, arg2 = pair res = atan2(arg1, arg2) mask = logical_and(exactly_equal(arg1, -zero(arg1.shape, arg1.dtype)), less(arg2, zero(arg2.shape, arg2.dtype))) assert_exactly_equal(res[mask], (-π(arg1.shape, arg1.dtype))[mask]) -@given(numeric_arrays, numeric_arrays) -def test_atan2_special_cases_two_args_less__equal_1(arg1, arg2): +@given(broadcastable_floating_array_pairs()) +def test_atan2_special_cases_two_args_less__equal_1(pair): """ Special case test for `atan2(x1, x2, /)`: - If `x1_i` is less than `0` and `x2_i` is `+0`, the result is an implementation-dependent approximation to `-π/2`. """ + arg1, arg2 = pair res = atan2(arg1, arg2) mask = logical_and(less(arg1, zero(arg1.shape, arg1.dtype)), exactly_equal(arg2, zero(arg2.shape, arg2.dtype))) assert_exactly_equal(res[mask], (-π(arg1.shape, arg1.dtype)/2)[mask]) -@given(numeric_arrays, numeric_arrays) -def test_atan2_special_cases_two_args_less__equal_2(arg1, arg2): +@given(broadcastable_floating_array_pairs()) +def test_atan2_special_cases_two_args_less__equal_2(pair): """ Special case test for `atan2(x1, x2, /)`: - If `x1_i` is less than `0` and `x2_i` is `-0`, the result is an implementation-dependent approximation to `-π/2`. """ + arg1, arg2 = pair res = atan2(arg1, arg2) mask = logical_and(less(arg1, zero(arg1.shape, arg1.dtype)), exactly_equal(arg2, -zero(arg2.shape, arg2.dtype))) assert_exactly_equal(res[mask], (-π(arg1.shape, arg1.dtype)/2)[mask]) -@given(numeric_arrays, numeric_arrays) -def test_atan2_special_cases_two_args_greater_equal__equal_1(arg1, arg2): +@given(broadcastable_floating_array_pairs()) +def test_atan2_special_cases_two_args_greater_equal__equal_1(pair): """ Special case test for `atan2(x1, x2, /)`: - If `x1_i` is greater than `0`, `x1_i` is a finite number, and `x2_i` is `+infinity`, the result is `+0`. """ + arg1, arg2 = pair res = atan2(arg1, arg2) mask = logical_and(logical_and(greater(arg1, zero(arg1.shape, arg1.dtype)), isfinite(arg1)), exactly_equal(arg2, infinity(arg2.shape, arg2.dtype))) assert_exactly_equal(res[mask], (zero(arg1.shape, arg1.dtype))[mask]) -@given(numeric_arrays, numeric_arrays) -def test_atan2_special_cases_two_args_greater_equal__equal_2(arg1, arg2): +@given(broadcastable_floating_array_pairs()) +def test_atan2_special_cases_two_args_greater_equal__equal_2(pair): """ Special case test for `atan2(x1, x2, /)`: - If `x1_i` is greater than `0`, `x1_i` is a finite number, and `x2_i` is `-infinity`, the result is an implementation-dependent approximation to `+π`. """ + arg1, arg2 = pair res = atan2(arg1, arg2) mask = logical_and(logical_and(greater(arg1, zero(arg1.shape, arg1.dtype)), isfinite(arg1)), exactly_equal(arg2, -infinity(arg2.shape, arg2.dtype))) assert_exactly_equal(res[mask], (+π(arg1.shape, arg1.dtype))[mask]) -@given(numeric_arrays, numeric_arrays) -def test_atan2_special_cases_two_args_less_equal__equal_1(arg1, arg2): +@given(broadcastable_floating_array_pairs()) +def test_atan2_special_cases_two_args_less_equal__equal_1(pair): """ Special case test for `atan2(x1, x2, /)`: - If `x1_i` is less than `0`, `x1_i` is a finite number, and `x2_i` is `+infinity`, the result is `-0`. """ + arg1, arg2 = pair res = atan2(arg1, arg2) mask = logical_and(logical_and(less(arg1, zero(arg1.shape, arg1.dtype)), isfinite(arg1)), exactly_equal(arg2, infinity(arg2.shape, arg2.dtype))) assert_exactly_equal(res[mask], (-zero(arg1.shape, arg1.dtype))[mask]) -@given(numeric_arrays, numeric_arrays) -def test_atan2_special_cases_two_args_less_equal__equal_2(arg1, arg2): +@given(broadcastable_floating_array_pairs()) +def test_atan2_special_cases_two_args_less_equal__equal_2(pair): """ Special case test for `atan2(x1, x2, /)`: - If `x1_i` is less than `0`, `x1_i` is a finite number, and `x2_i` is `-infinity`, the result is an implementation-dependent approximation to `-π`. """ + arg1, arg2 = pair res = atan2(arg1, arg2) mask = logical_and(logical_and(less(arg1, zero(arg1.shape, arg1.dtype)), isfinite(arg1)), exactly_equal(arg2, -infinity(arg2.shape, arg2.dtype))) assert_exactly_equal(res[mask], (-π(arg1.shape, arg1.dtype))[mask]) diff --git a/array_api_tests/special_cases/test_atanh.py b/array_api_tests/special_cases/test_atanh.py index 6e26cc99..510ebf2e 100644 --- a/array_api_tests/special_cases/test_atanh.py +++ b/array_api_tests/special_cases/test_atanh.py @@ -9,13 +9,13 @@ from ..array_helpers import (NaN, assert_exactly_equal, exactly_equal, greater, infinity, less, one, zero) -from ..hypothesis_helpers import numeric_arrays +from ..hypothesis_helpers import floating_arrays, broadcastable_floating_array_pairs from .._array_module import atanh from hypothesis import given -@given(numeric_arrays) +@given(floating_arrays) def test_atanh_special_cases_one_arg_equal_1(arg1): """ Special case test for `atanh(x, /)`: @@ -28,7 +28,7 @@ def test_atanh_special_cases_one_arg_equal_1(arg1): assert_exactly_equal(res[mask], (NaN(arg1.shape, arg1.dtype))[mask]) -@given(numeric_arrays) +@given(floating_arrays) def test_atanh_special_cases_one_arg_equal_2(arg1): """ Special case test for `atanh(x, /)`: @@ -41,7 +41,7 @@ def test_atanh_special_cases_one_arg_equal_2(arg1): assert_exactly_equal(res[mask], (-infinity(arg1.shape, arg1.dtype))[mask]) -@given(numeric_arrays) +@given(floating_arrays) def test_atanh_special_cases_one_arg_equal_3(arg1): """ Special case test for `atanh(x, /)`: @@ -54,7 +54,7 @@ def test_atanh_special_cases_one_arg_equal_3(arg1): assert_exactly_equal(res[mask], (infinity(arg1.shape, arg1.dtype))[mask]) -@given(numeric_arrays) +@given(floating_arrays) def test_atanh_special_cases_one_arg_equal_4(arg1): """ Special case test for `atanh(x, /)`: @@ -67,7 +67,7 @@ def test_atanh_special_cases_one_arg_equal_4(arg1): assert_exactly_equal(res[mask], (zero(arg1.shape, arg1.dtype))[mask]) -@given(numeric_arrays) +@given(floating_arrays) def test_atanh_special_cases_one_arg_equal_5(arg1): """ Special case test for `atanh(x, /)`: @@ -80,7 +80,7 @@ def test_atanh_special_cases_one_arg_equal_5(arg1): assert_exactly_equal(res[mask], (-zero(arg1.shape, arg1.dtype))[mask]) -@given(numeric_arrays) +@given(floating_arrays) def test_atanh_special_cases_one_arg_less(arg1): """ Special case test for `atanh(x, /)`: @@ -93,7 +93,7 @@ def test_atanh_special_cases_one_arg_less(arg1): assert_exactly_equal(res[mask], (NaN(arg1.shape, arg1.dtype))[mask]) -@given(numeric_arrays) +@given(floating_arrays) def test_atanh_special_cases_one_arg_greater(arg1): """ Special case test for `atanh(x, /)`: diff --git a/array_api_tests/special_cases/test_ceil.py b/array_api_tests/special_cases/test_ceil.py index 5056db66..25cc49b1 100644 --- a/array_api_tests/special_cases/test_ceil.py +++ b/array_api_tests/special_cases/test_ceil.py @@ -8,13 +8,13 @@ """ from ..array_helpers import assert_exactly_equal, isintegral -from ..hypothesis_helpers import numeric_arrays +from ..hypothesis_helpers import floating_arrays, broadcastable_floating_array_pairs from .._array_module import ceil from hypothesis import given -@given(numeric_arrays) +@given(floating_arrays) def test_ceil_special_cases_one_arg_equal(arg1): """ Special case test for `ceil(x, /)`: diff --git a/array_api_tests/special_cases/test_cos.py b/array_api_tests/special_cases/test_cos.py index e80a7130..592aae5e 100644 --- a/array_api_tests/special_cases/test_cos.py +++ b/array_api_tests/special_cases/test_cos.py @@ -8,13 +8,13 @@ """ from ..array_helpers import NaN, assert_exactly_equal, exactly_equal, infinity, one, zero -from ..hypothesis_helpers import numeric_arrays +from ..hypothesis_helpers import floating_arrays, broadcastable_floating_array_pairs from .._array_module import cos from hypothesis import given -@given(numeric_arrays) +@given(floating_arrays) def test_cos_special_cases_one_arg_equal_1(arg1): """ Special case test for `cos(x, /)`: @@ -27,7 +27,7 @@ def test_cos_special_cases_one_arg_equal_1(arg1): assert_exactly_equal(res[mask], (NaN(arg1.shape, arg1.dtype))[mask]) -@given(numeric_arrays) +@given(floating_arrays) def test_cos_special_cases_one_arg_equal_2(arg1): """ Special case test for `cos(x, /)`: @@ -40,7 +40,7 @@ def test_cos_special_cases_one_arg_equal_2(arg1): assert_exactly_equal(res[mask], (one(arg1.shape, arg1.dtype))[mask]) -@given(numeric_arrays) +@given(floating_arrays) def test_cos_special_cases_one_arg_equal_3(arg1): """ Special case test for `cos(x, /)`: @@ -53,7 +53,7 @@ def test_cos_special_cases_one_arg_equal_3(arg1): assert_exactly_equal(res[mask], (one(arg1.shape, arg1.dtype))[mask]) -@given(numeric_arrays) +@given(floating_arrays) def test_cos_special_cases_one_arg_equal_4(arg1): """ Special case test for `cos(x, /)`: @@ -66,7 +66,7 @@ def test_cos_special_cases_one_arg_equal_4(arg1): assert_exactly_equal(res[mask], (NaN(arg1.shape, arg1.dtype))[mask]) -@given(numeric_arrays) +@given(floating_arrays) def test_cos_special_cases_one_arg_equal_5(arg1): """ Special case test for `cos(x, /)`: diff --git a/array_api_tests/special_cases/test_cosh.py b/array_api_tests/special_cases/test_cosh.py index bdca4a82..8ce52b08 100644 --- a/array_api_tests/special_cases/test_cosh.py +++ b/array_api_tests/special_cases/test_cosh.py @@ -8,13 +8,13 @@ """ from ..array_helpers import NaN, assert_exactly_equal, exactly_equal, infinity, one, zero -from ..hypothesis_helpers import numeric_arrays +from ..hypothesis_helpers import floating_arrays, broadcastable_floating_array_pairs from .._array_module import cosh from hypothesis import given -@given(numeric_arrays) +@given(floating_arrays) def test_cosh_special_cases_one_arg_equal_1(arg1): """ Special case test for `cosh(x, /)`: @@ -27,7 +27,7 @@ def test_cosh_special_cases_one_arg_equal_1(arg1): assert_exactly_equal(res[mask], (NaN(arg1.shape, arg1.dtype))[mask]) -@given(numeric_arrays) +@given(floating_arrays) def test_cosh_special_cases_one_arg_equal_2(arg1): """ Special case test for `cosh(x, /)`: @@ -40,7 +40,7 @@ def test_cosh_special_cases_one_arg_equal_2(arg1): assert_exactly_equal(res[mask], (one(arg1.shape, arg1.dtype))[mask]) -@given(numeric_arrays) +@given(floating_arrays) def test_cosh_special_cases_one_arg_equal_3(arg1): """ Special case test for `cosh(x, /)`: @@ -53,7 +53,7 @@ def test_cosh_special_cases_one_arg_equal_3(arg1): assert_exactly_equal(res[mask], (one(arg1.shape, arg1.dtype))[mask]) -@given(numeric_arrays) +@given(floating_arrays) def test_cosh_special_cases_one_arg_equal_4(arg1): """ Special case test for `cosh(x, /)`: @@ -66,7 +66,7 @@ def test_cosh_special_cases_one_arg_equal_4(arg1): assert_exactly_equal(res[mask], (infinity(arg1.shape, arg1.dtype))[mask]) -@given(numeric_arrays) +@given(floating_arrays) def test_cosh_special_cases_one_arg_equal_5(arg1): """ Special case test for `cosh(x, /)`: diff --git a/array_api_tests/special_cases/test_divide.py b/array_api_tests/special_cases/test_divide.py index fe1596c9..bff9a463 100644 --- a/array_api_tests/special_cases/test_divide.py +++ b/array_api_tests/special_cases/test_divide.py @@ -11,280 +11,301 @@ assert_positive_mathematical_sign, exactly_equal, greater, infinity, isfinite, isnegative, ispositive, less, logical_and, logical_not, logical_or, non_zero, same_sign, zero) -from ..hypothesis_helpers import numeric_arrays +from ..hypothesis_helpers import floating_arrays, broadcastable_floating_array_pairs from .._array_module import divide from hypothesis import given -@given(numeric_arrays, numeric_arrays) -def test_divide_special_cases_two_args_either(arg1, arg2): +@given(broadcastable_floating_array_pairs()) +def test_divide_special_cases_two_args_either(pair): """ Special case test for `divide(x1, x2, /)`: - If either `x1_i` or `x2_i` is `NaN`, the result is `NaN`. """ + arg1, arg2 = pair res = divide(arg1, arg2) mask = logical_or(exactly_equal(arg1, NaN(arg1.shape, arg1.dtype)), exactly_equal(arg2, NaN(arg1.shape, arg1.dtype))) assert_exactly_equal(res[mask], (NaN(arg1.shape, arg1.dtype))[mask]) -@given(numeric_arrays, numeric_arrays) -def test_divide_special_cases_two_args_either__either_1(arg1, arg2): +@given(broadcastable_floating_array_pairs()) +def test_divide_special_cases_two_args_either__either_1(pair): """ Special case test for `divide(x1, x2, /)`: - If `x1_i` is either `+infinity` or `-infinity` and `x2_i` is either `+infinity` or `-infinity`, the result is `NaN`. """ + arg1, arg2 = pair res = divide(arg1, arg2) mask = logical_and(logical_or(exactly_equal(arg1, infinity(arg1.shape, arg1.dtype)), exactly_equal(arg1, -infinity(arg1.shape, arg1.dtype))), logical_or(exactly_equal(arg2, infinity(arg2.shape, arg2.dtype)), exactly_equal(arg2, -infinity(arg2.shape, arg2.dtype)))) assert_exactly_equal(res[mask], (NaN(arg1.shape, arg1.dtype))[mask]) -@given(numeric_arrays, numeric_arrays) -def test_divide_special_cases_two_args_either__either_2(arg1, arg2): +@given(broadcastable_floating_array_pairs()) +def test_divide_special_cases_two_args_either__either_2(pair): """ Special case test for `divide(x1, x2, /)`: - If `x1_i` is either `+0` or `-0` and `x2_i` is either `+0` or `-0`, the result is `NaN`. """ + arg1, arg2 = pair res = divide(arg1, arg2) mask = logical_and(logical_or(exactly_equal(arg1, zero(arg1.shape, arg1.dtype)), exactly_equal(arg1, -zero(arg1.shape, arg1.dtype))), logical_or(exactly_equal(arg2, zero(arg2.shape, arg2.dtype)), exactly_equal(arg2, -zero(arg2.shape, arg2.dtype)))) assert_exactly_equal(res[mask], (NaN(arg1.shape, arg1.dtype))[mask]) -@given(numeric_arrays, numeric_arrays) -def test_divide_special_cases_two_args_equal__greater_1(arg1, arg2): +@given(broadcastable_floating_array_pairs()) +def test_divide_special_cases_two_args_equal__greater_1(pair): """ Special case test for `divide(x1, x2, /)`: - If `x1_i` is `+0` and `x2_i` is greater than `0`, the result is `+0`. """ + arg1, arg2 = pair res = divide(arg1, arg2) mask = logical_and(exactly_equal(arg1, zero(arg1.shape, arg1.dtype)), greater(arg2, zero(arg2.shape, arg2.dtype))) assert_exactly_equal(res[mask], (zero(arg1.shape, arg1.dtype))[mask]) -@given(numeric_arrays, numeric_arrays) -def test_divide_special_cases_two_args_equal__greater_2(arg1, arg2): +@given(broadcastable_floating_array_pairs()) +def test_divide_special_cases_two_args_equal__greater_2(pair): """ Special case test for `divide(x1, x2, /)`: - If `x1_i` is `-0` and `x2_i` is greater than `0`, the result is `-0`. """ + arg1, arg2 = pair res = divide(arg1, arg2) mask = logical_and(exactly_equal(arg1, -zero(arg1.shape, arg1.dtype)), greater(arg2, zero(arg2.shape, arg2.dtype))) assert_exactly_equal(res[mask], (-zero(arg1.shape, arg1.dtype))[mask]) -@given(numeric_arrays, numeric_arrays) -def test_divide_special_cases_two_args_equal__less_1(arg1, arg2): +@given(broadcastable_floating_array_pairs()) +def test_divide_special_cases_two_args_equal__less_1(pair): """ Special case test for `divide(x1, x2, /)`: - If `x1_i` is `+0` and `x2_i` is less than `0`, the result is `-0`. """ + arg1, arg2 = pair res = divide(arg1, arg2) mask = logical_and(exactly_equal(arg1, zero(arg1.shape, arg1.dtype)), less(arg2, zero(arg2.shape, arg2.dtype))) assert_exactly_equal(res[mask], (-zero(arg1.shape, arg1.dtype))[mask]) -@given(numeric_arrays, numeric_arrays) -def test_divide_special_cases_two_args_equal__less_2(arg1, arg2): +@given(broadcastable_floating_array_pairs()) +def test_divide_special_cases_two_args_equal__less_2(pair): """ Special case test for `divide(x1, x2, /)`: - If `x1_i` is `-0` and `x2_i` is less than `0`, the result is `+0`. """ + arg1, arg2 = pair res = divide(arg1, arg2) mask = logical_and(exactly_equal(arg1, -zero(arg1.shape, arg1.dtype)), less(arg2, zero(arg2.shape, arg2.dtype))) assert_exactly_equal(res[mask], (zero(arg1.shape, arg1.dtype))[mask]) -@given(numeric_arrays, numeric_arrays) -def test_divide_special_cases_two_args_greater__equal_1(arg1, arg2): +@given(broadcastable_floating_array_pairs()) +def test_divide_special_cases_two_args_greater__equal_1(pair): """ Special case test for `divide(x1, x2, /)`: - If `x1_i` is greater than `0` and `x2_i` is `+0`, the result is `+infinity`. """ + arg1, arg2 = pair res = divide(arg1, arg2) mask = logical_and(greater(arg1, zero(arg1.shape, arg1.dtype)), exactly_equal(arg2, zero(arg2.shape, arg2.dtype))) assert_exactly_equal(res[mask], (infinity(arg1.shape, arg1.dtype))[mask]) -@given(numeric_arrays, numeric_arrays) -def test_divide_special_cases_two_args_greater__equal_2(arg1, arg2): +@given(broadcastable_floating_array_pairs()) +def test_divide_special_cases_two_args_greater__equal_2(pair): """ Special case test for `divide(x1, x2, /)`: - If `x1_i` is greater than `0` and `x2_i` is `-0`, the result is `-infinity`. """ + arg1, arg2 = pair res = divide(arg1, arg2) mask = logical_and(greater(arg1, zero(arg1.shape, arg1.dtype)), exactly_equal(arg2, -zero(arg2.shape, arg2.dtype))) assert_exactly_equal(res[mask], (-infinity(arg1.shape, arg1.dtype))[mask]) -@given(numeric_arrays, numeric_arrays) -def test_divide_special_cases_two_args_less__equal_1(arg1, arg2): +@given(broadcastable_floating_array_pairs()) +def test_divide_special_cases_two_args_less__equal_1(pair): """ Special case test for `divide(x1, x2, /)`: - If `x1_i` is less than `0` and `x2_i` is `+0`, the result is `-infinity`. """ + arg1, arg2 = pair res = divide(arg1, arg2) mask = logical_and(less(arg1, zero(arg1.shape, arg1.dtype)), exactly_equal(arg2, zero(arg2.shape, arg2.dtype))) assert_exactly_equal(res[mask], (-infinity(arg1.shape, arg1.dtype))[mask]) -@given(numeric_arrays, numeric_arrays) -def test_divide_special_cases_two_args_less__equal_2(arg1, arg2): +@given(broadcastable_floating_array_pairs()) +def test_divide_special_cases_two_args_less__equal_2(pair): """ Special case test for `divide(x1, x2, /)`: - If `x1_i` is less than `0` and `x2_i` is `-0`, the result is `+infinity`. """ + arg1, arg2 = pair res = divide(arg1, arg2) mask = logical_and(less(arg1, zero(arg1.shape, arg1.dtype)), exactly_equal(arg2, -zero(arg2.shape, arg2.dtype))) assert_exactly_equal(res[mask], (infinity(arg1.shape, arg1.dtype))[mask]) -@given(numeric_arrays, numeric_arrays) -def test_divide_special_cases_two_args_equal__equal_1(arg1, arg2): +@given(broadcastable_floating_array_pairs()) +def test_divide_special_cases_two_args_equal__equal_1(pair): """ Special case test for `divide(x1, x2, /)`: - If `x1_i` is `+infinity` and `x2_i` is a positive (i.e., greater than `0`) finite number, the result is `+infinity`. """ + arg1, arg2 = pair res = divide(arg1, arg2) mask = logical_and(exactly_equal(arg1, infinity(arg1.shape, arg1.dtype)), logical_and(isfinite(arg2), ispositive(arg2))) assert_exactly_equal(res[mask], (infinity(arg1.shape, arg1.dtype))[mask]) -@given(numeric_arrays, numeric_arrays) -def test_divide_special_cases_two_args_equal__equal_2(arg1, arg2): +@given(broadcastable_floating_array_pairs()) +def test_divide_special_cases_two_args_equal__equal_2(pair): """ Special case test for `divide(x1, x2, /)`: - If `x1_i` is `+infinity` and `x2_i` is a negative (i.e., less than `0`) finite number, the result is `-infinity`. """ + arg1, arg2 = pair res = divide(arg1, arg2) mask = logical_and(exactly_equal(arg1, infinity(arg1.shape, arg1.dtype)), logical_and(isfinite(arg2), isnegative(arg2))) assert_exactly_equal(res[mask], (-infinity(arg1.shape, arg1.dtype))[mask]) -@given(numeric_arrays, numeric_arrays) -def test_divide_special_cases_two_args_equal__equal_3(arg1, arg2): +@given(broadcastable_floating_array_pairs()) +def test_divide_special_cases_two_args_equal__equal_3(pair): """ Special case test for `divide(x1, x2, /)`: - If `x1_i` is `-infinity` and `x2_i` is a positive (i.e., greater than `0`) finite number, the result is `-infinity`. """ + arg1, arg2 = pair res = divide(arg1, arg2) mask = logical_and(exactly_equal(arg1, -infinity(arg1.shape, arg1.dtype)), logical_and(isfinite(arg2), ispositive(arg2))) assert_exactly_equal(res[mask], (-infinity(arg1.shape, arg1.dtype))[mask]) -@given(numeric_arrays, numeric_arrays) -def test_divide_special_cases_two_args_equal__equal_4(arg1, arg2): +@given(broadcastable_floating_array_pairs()) +def test_divide_special_cases_two_args_equal__equal_4(pair): """ Special case test for `divide(x1, x2, /)`: - If `x1_i` is `-infinity` and `x2_i` is a negative (i.e., less than `0`) finite number, the result is `+infinity`. """ + arg1, arg2 = pair res = divide(arg1, arg2) mask = logical_and(exactly_equal(arg1, -infinity(arg1.shape, arg1.dtype)), logical_and(isfinite(arg2), isnegative(arg2))) assert_exactly_equal(res[mask], (infinity(arg1.shape, arg1.dtype))[mask]) -@given(numeric_arrays, numeric_arrays) -def test_divide_special_cases_two_args_equal__equal_5(arg1, arg2): +@given(broadcastable_floating_array_pairs()) +def test_divide_special_cases_two_args_equal__equal_5(pair): """ Special case test for `divide(x1, x2, /)`: - If `x1_i` is a positive (i.e., greater than `0`) finite number and `x2_i` is `+infinity`, the result is `+0`. """ + arg1, arg2 = pair res = divide(arg1, arg2) mask = logical_and(logical_and(isfinite(arg1), ispositive(arg1)), exactly_equal(arg2, infinity(arg2.shape, arg2.dtype))) assert_exactly_equal(res[mask], (zero(arg1.shape, arg1.dtype))[mask]) -@given(numeric_arrays, numeric_arrays) -def test_divide_special_cases_two_args_equal__equal_6(arg1, arg2): +@given(broadcastable_floating_array_pairs()) +def test_divide_special_cases_two_args_equal__equal_6(pair): """ Special case test for `divide(x1, x2, /)`: - If `x1_i` is a positive (i.e., greater than `0`) finite number and `x2_i` is `-infinity`, the result is `-0`. """ + arg1, arg2 = pair res = divide(arg1, arg2) mask = logical_and(logical_and(isfinite(arg1), ispositive(arg1)), exactly_equal(arg2, -infinity(arg2.shape, arg2.dtype))) assert_exactly_equal(res[mask], (-zero(arg1.shape, arg1.dtype))[mask]) -@given(numeric_arrays, numeric_arrays) -def test_divide_special_cases_two_args_equal__equal_7(arg1, arg2): +@given(broadcastable_floating_array_pairs()) +def test_divide_special_cases_two_args_equal__equal_7(pair): """ Special case test for `divide(x1, x2, /)`: - If `x1_i` is a negative (i.e., less than `0`) finite number and `x2_i` is `+infinity`, the result is `-0`. """ + arg1, arg2 = pair res = divide(arg1, arg2) mask = logical_and(logical_and(isfinite(arg1), isnegative(arg1)), exactly_equal(arg2, infinity(arg2.shape, arg2.dtype))) assert_exactly_equal(res[mask], (-zero(arg1.shape, arg1.dtype))[mask]) -@given(numeric_arrays, numeric_arrays) -def test_divide_special_cases_two_args_equal__equal_8(arg1, arg2): +@given(broadcastable_floating_array_pairs()) +def test_divide_special_cases_two_args_equal__equal_8(pair): """ Special case test for `divide(x1, x2, /)`: - If `x1_i` is a negative (i.e., less than `0`) finite number and `x2_i` is `-infinity`, the result is `+0`. """ + arg1, arg2 = pair res = divide(arg1, arg2) mask = logical_and(logical_and(isfinite(arg1), isnegative(arg1)), exactly_equal(arg2, -infinity(arg2.shape, arg2.dtype))) assert_exactly_equal(res[mask], (zero(arg1.shape, arg1.dtype))[mask]) -@given(numeric_arrays, numeric_arrays) -def test_divide_special_cases_two_args_same_sign_both(arg1, arg2): +@given(broadcastable_floating_array_pairs()) +def test_divide_special_cases_two_args_same_sign_both(pair): """ Special case test for `divide(x1, x2, /)`: - If `x1_i` and `x2_i` have the same mathematical sign and are both nonzero finite numbers, the result has a positive mathematical sign. """ + arg1, arg2 = pair res = divide(arg1, arg2) mask = logical_and(same_sign(arg1, arg2), logical_and(logical_and(isfinite(arg1), non_zero(arg1)), logical_and(isfinite(arg2), non_zero(arg2)))) assert_positive_mathematical_sign(res[mask]) -@given(numeric_arrays, numeric_arrays) -def test_divide_special_cases_two_args_different_signs_both(arg1, arg2): +@given(broadcastable_floating_array_pairs()) +def test_divide_special_cases_two_args_different_signs_both(pair): """ Special case test for `divide(x1, x2, /)`: - If `x1_i` and `x2_i` have different mathematical signs and are both nonzero finite numbers, the result has a negative mathematical sign. """ + arg1, arg2 = pair res = divide(arg1, arg2) mask = logical_and(logical_not(same_sign(arg1, arg2)), logical_and(logical_and(isfinite(arg1), non_zero(arg1)), logical_and(isfinite(arg2), non_zero(arg2)))) assert_negative_mathematical_sign(res[mask]) diff --git a/array_api_tests/special_cases/test_exp.py b/array_api_tests/special_cases/test_exp.py index 47399648..a6377a44 100644 --- a/array_api_tests/special_cases/test_exp.py +++ b/array_api_tests/special_cases/test_exp.py @@ -8,13 +8,13 @@ """ from ..array_helpers import NaN, assert_exactly_equal, exactly_equal, infinity, one, zero -from ..hypothesis_helpers import numeric_arrays +from ..hypothesis_helpers import floating_arrays, broadcastable_floating_array_pairs from .._array_module import exp from hypothesis import given -@given(numeric_arrays) +@given(floating_arrays) def test_exp_special_cases_one_arg_equal_1(arg1): """ Special case test for `exp(x, /)`: @@ -27,7 +27,7 @@ def test_exp_special_cases_one_arg_equal_1(arg1): assert_exactly_equal(res[mask], (NaN(arg1.shape, arg1.dtype))[mask]) -@given(numeric_arrays) +@given(floating_arrays) def test_exp_special_cases_one_arg_equal_2(arg1): """ Special case test for `exp(x, /)`: @@ -40,7 +40,7 @@ def test_exp_special_cases_one_arg_equal_2(arg1): assert_exactly_equal(res[mask], (one(arg1.shape, arg1.dtype))[mask]) -@given(numeric_arrays) +@given(floating_arrays) def test_exp_special_cases_one_arg_equal_3(arg1): """ Special case test for `exp(x, /)`: @@ -53,7 +53,7 @@ def test_exp_special_cases_one_arg_equal_3(arg1): assert_exactly_equal(res[mask], (one(arg1.shape, arg1.dtype))[mask]) -@given(numeric_arrays) +@given(floating_arrays) def test_exp_special_cases_one_arg_equal_4(arg1): """ Special case test for `exp(x, /)`: @@ -66,7 +66,7 @@ def test_exp_special_cases_one_arg_equal_4(arg1): assert_exactly_equal(res[mask], (infinity(arg1.shape, arg1.dtype))[mask]) -@given(numeric_arrays) +@given(floating_arrays) def test_exp_special_cases_one_arg_equal_5(arg1): """ Special case test for `exp(x, /)`: diff --git a/array_api_tests/special_cases/test_expm1.py b/array_api_tests/special_cases/test_expm1.py index d96b742e..2e85f07a 100644 --- a/array_api_tests/special_cases/test_expm1.py +++ b/array_api_tests/special_cases/test_expm1.py @@ -8,13 +8,13 @@ """ from ..array_helpers import NaN, assert_exactly_equal, exactly_equal, infinity, one, zero -from ..hypothesis_helpers import numeric_arrays +from ..hypothesis_helpers import floating_arrays, broadcastable_floating_array_pairs from .._array_module import expm1 from hypothesis import given -@given(numeric_arrays) +@given(floating_arrays) def test_expm1_special_cases_one_arg_equal_1(arg1): """ Special case test for `expm1(x, /)`: @@ -27,7 +27,7 @@ def test_expm1_special_cases_one_arg_equal_1(arg1): assert_exactly_equal(res[mask], (NaN(arg1.shape, arg1.dtype))[mask]) -@given(numeric_arrays) +@given(floating_arrays) def test_expm1_special_cases_one_arg_equal_2(arg1): """ Special case test for `expm1(x, /)`: @@ -40,7 +40,7 @@ def test_expm1_special_cases_one_arg_equal_2(arg1): assert_exactly_equal(res[mask], (zero(arg1.shape, arg1.dtype))[mask]) -@given(numeric_arrays) +@given(floating_arrays) def test_expm1_special_cases_one_arg_equal_3(arg1): """ Special case test for `expm1(x, /)`: @@ -53,7 +53,7 @@ def test_expm1_special_cases_one_arg_equal_3(arg1): assert_exactly_equal(res[mask], (-zero(arg1.shape, arg1.dtype))[mask]) -@given(numeric_arrays) +@given(floating_arrays) def test_expm1_special_cases_one_arg_equal_4(arg1): """ Special case test for `expm1(x, /)`: @@ -66,7 +66,7 @@ def test_expm1_special_cases_one_arg_equal_4(arg1): assert_exactly_equal(res[mask], (infinity(arg1.shape, arg1.dtype))[mask]) -@given(numeric_arrays) +@given(floating_arrays) def test_expm1_special_cases_one_arg_equal_5(arg1): """ Special case test for `expm1(x, /)`: diff --git a/array_api_tests/special_cases/test_floor.py b/array_api_tests/special_cases/test_floor.py index a7a0f473..89742128 100644 --- a/array_api_tests/special_cases/test_floor.py +++ b/array_api_tests/special_cases/test_floor.py @@ -8,13 +8,13 @@ """ from ..array_helpers import assert_exactly_equal, isintegral -from ..hypothesis_helpers import numeric_arrays +from ..hypothesis_helpers import floating_arrays, broadcastable_floating_array_pairs from .._array_module import floor from hypothesis import given -@given(numeric_arrays) +@given(floating_arrays) def test_floor_special_cases_one_arg_equal(arg1): """ Special case test for `floor(x, /)`: diff --git a/array_api_tests/special_cases/test_log.py b/array_api_tests/special_cases/test_log.py index 0ea6cd25..31edeefe 100644 --- a/array_api_tests/special_cases/test_log.py +++ b/array_api_tests/special_cases/test_log.py @@ -9,13 +9,13 @@ from ..array_helpers import (NaN, assert_exactly_equal, exactly_equal, infinity, less, logical_or, one, zero) -from ..hypothesis_helpers import numeric_arrays +from ..hypothesis_helpers import floating_arrays, broadcastable_floating_array_pairs from .._array_module import log from hypothesis import given -@given(numeric_arrays) +@given(floating_arrays) def test_log_special_cases_one_arg_equal_1(arg1): """ Special case test for `log(x, /)`: @@ -28,7 +28,7 @@ def test_log_special_cases_one_arg_equal_1(arg1): assert_exactly_equal(res[mask], (NaN(arg1.shape, arg1.dtype))[mask]) -@given(numeric_arrays) +@given(floating_arrays) def test_log_special_cases_one_arg_equal_2(arg1): """ Special case test for `log(x, /)`: @@ -41,7 +41,7 @@ def test_log_special_cases_one_arg_equal_2(arg1): assert_exactly_equal(res[mask], (zero(arg1.shape, arg1.dtype))[mask]) -@given(numeric_arrays) +@given(floating_arrays) def test_log_special_cases_one_arg_equal_3(arg1): """ Special case test for `log(x, /)`: @@ -54,7 +54,7 @@ def test_log_special_cases_one_arg_equal_3(arg1): assert_exactly_equal(res[mask], (infinity(arg1.shape, arg1.dtype))[mask]) -@given(numeric_arrays) +@given(floating_arrays) def test_log_special_cases_one_arg_less(arg1): """ Special case test for `log(x, /)`: @@ -67,7 +67,7 @@ def test_log_special_cases_one_arg_less(arg1): assert_exactly_equal(res[mask], (NaN(arg1.shape, arg1.dtype))[mask]) -@given(numeric_arrays) +@given(floating_arrays) def test_log_special_cases_one_arg_either(arg1): """ Special case test for `log(x, /)`: diff --git a/array_api_tests/special_cases/test_log10.py b/array_api_tests/special_cases/test_log10.py index 8dc5a5de..c9b4ea91 100644 --- a/array_api_tests/special_cases/test_log10.py +++ b/array_api_tests/special_cases/test_log10.py @@ -9,13 +9,13 @@ from ..array_helpers import (NaN, assert_exactly_equal, exactly_equal, infinity, less, logical_or, one, zero) -from ..hypothesis_helpers import numeric_arrays +from ..hypothesis_helpers import floating_arrays, broadcastable_floating_array_pairs from .._array_module import log10 from hypothesis import given -@given(numeric_arrays) +@given(floating_arrays) def test_log10_special_cases_one_arg_equal_1(arg1): """ Special case test for `log10(x, /)`: @@ -28,7 +28,7 @@ def test_log10_special_cases_one_arg_equal_1(arg1): assert_exactly_equal(res[mask], (NaN(arg1.shape, arg1.dtype))[mask]) -@given(numeric_arrays) +@given(floating_arrays) def test_log10_special_cases_one_arg_equal_2(arg1): """ Special case test for `log10(x, /)`: @@ -41,7 +41,7 @@ def test_log10_special_cases_one_arg_equal_2(arg1): assert_exactly_equal(res[mask], (zero(arg1.shape, arg1.dtype))[mask]) -@given(numeric_arrays) +@given(floating_arrays) def test_log10_special_cases_one_arg_equal_3(arg1): """ Special case test for `log10(x, /)`: @@ -54,7 +54,7 @@ def test_log10_special_cases_one_arg_equal_3(arg1): assert_exactly_equal(res[mask], (infinity(arg1.shape, arg1.dtype))[mask]) -@given(numeric_arrays) +@given(floating_arrays) def test_log10_special_cases_one_arg_less(arg1): """ Special case test for `log10(x, /)`: @@ -67,7 +67,7 @@ def test_log10_special_cases_one_arg_less(arg1): assert_exactly_equal(res[mask], (NaN(arg1.shape, arg1.dtype))[mask]) -@given(numeric_arrays) +@given(floating_arrays) def test_log10_special_cases_one_arg_either(arg1): """ Special case test for `log10(x, /)`: diff --git a/array_api_tests/special_cases/test_log1p.py b/array_api_tests/special_cases/test_log1p.py index 432a761b..ae887a9b 100644 --- a/array_api_tests/special_cases/test_log1p.py +++ b/array_api_tests/special_cases/test_log1p.py @@ -8,13 +8,13 @@ """ from ..array_helpers import NaN, assert_exactly_equal, exactly_equal, infinity, less, one, zero -from ..hypothesis_helpers import numeric_arrays +from ..hypothesis_helpers import floating_arrays, broadcastable_floating_array_pairs from .._array_module import log1p from hypothesis import given -@given(numeric_arrays) +@given(floating_arrays) def test_log1p_special_cases_one_arg_equal_1(arg1): """ Special case test for `log1p(x, /)`: @@ -27,7 +27,7 @@ def test_log1p_special_cases_one_arg_equal_1(arg1): assert_exactly_equal(res[mask], (NaN(arg1.shape, arg1.dtype))[mask]) -@given(numeric_arrays) +@given(floating_arrays) def test_log1p_special_cases_one_arg_equal_2(arg1): """ Special case test for `log1p(x, /)`: @@ -40,7 +40,7 @@ def test_log1p_special_cases_one_arg_equal_2(arg1): assert_exactly_equal(res[mask], (-infinity(arg1.shape, arg1.dtype))[mask]) -@given(numeric_arrays) +@given(floating_arrays) def test_log1p_special_cases_one_arg_equal_3(arg1): """ Special case test for `log1p(x, /)`: @@ -53,7 +53,7 @@ def test_log1p_special_cases_one_arg_equal_3(arg1): assert_exactly_equal(res[mask], (-zero(arg1.shape, arg1.dtype))[mask]) -@given(numeric_arrays) +@given(floating_arrays) def test_log1p_special_cases_one_arg_equal_4(arg1): """ Special case test for `log1p(x, /)`: @@ -66,7 +66,7 @@ def test_log1p_special_cases_one_arg_equal_4(arg1): assert_exactly_equal(res[mask], (zero(arg1.shape, arg1.dtype))[mask]) -@given(numeric_arrays) +@given(floating_arrays) def test_log1p_special_cases_one_arg_equal_5(arg1): """ Special case test for `log1p(x, /)`: @@ -79,7 +79,7 @@ def test_log1p_special_cases_one_arg_equal_5(arg1): assert_exactly_equal(res[mask], (infinity(arg1.shape, arg1.dtype))[mask]) -@given(numeric_arrays) +@given(floating_arrays) def test_log1p_special_cases_one_arg_less(arg1): """ Special case test for `log1p(x, /)`: diff --git a/array_api_tests/special_cases/test_log2.py b/array_api_tests/special_cases/test_log2.py index 41797dd7..581f49ce 100644 --- a/array_api_tests/special_cases/test_log2.py +++ b/array_api_tests/special_cases/test_log2.py @@ -9,13 +9,13 @@ from ..array_helpers import (NaN, assert_exactly_equal, exactly_equal, infinity, less, logical_or, one, zero) -from ..hypothesis_helpers import numeric_arrays +from ..hypothesis_helpers import floating_arrays, broadcastable_floating_array_pairs from .._array_module import log2 from hypothesis import given -@given(numeric_arrays) +@given(floating_arrays) def test_log2_special_cases_one_arg_equal_1(arg1): """ Special case test for `log2(x, /)`: @@ -28,7 +28,7 @@ def test_log2_special_cases_one_arg_equal_1(arg1): assert_exactly_equal(res[mask], (NaN(arg1.shape, arg1.dtype))[mask]) -@given(numeric_arrays) +@given(floating_arrays) def test_log2_special_cases_one_arg_equal_2(arg1): """ Special case test for `log2(x, /)`: @@ -41,7 +41,7 @@ def test_log2_special_cases_one_arg_equal_2(arg1): assert_exactly_equal(res[mask], (zero(arg1.shape, arg1.dtype))[mask]) -@given(numeric_arrays) +@given(floating_arrays) def test_log2_special_cases_one_arg_equal_3(arg1): """ Special case test for `log2(x, /)`: @@ -54,7 +54,7 @@ def test_log2_special_cases_one_arg_equal_3(arg1): assert_exactly_equal(res[mask], (infinity(arg1.shape, arg1.dtype))[mask]) -@given(numeric_arrays) +@given(floating_arrays) def test_log2_special_cases_one_arg_less(arg1): """ Special case test for `log2(x, /)`: @@ -67,7 +67,7 @@ def test_log2_special_cases_one_arg_less(arg1): assert_exactly_equal(res[mask], (NaN(arg1.shape, arg1.dtype))[mask]) -@given(numeric_arrays) +@given(floating_arrays) def test_log2_special_cases_one_arg_either(arg1): """ Special case test for `log2(x, /)`: diff --git a/array_api_tests/special_cases/test_logaddexp.py b/array_api_tests/special_cases/test_logaddexp.py index de8081e7..4f39ed0c 100644 --- a/array_api_tests/special_cases/test_logaddexp.py +++ b/array_api_tests/special_cases/test_logaddexp.py @@ -7,48 +7,36 @@ not modify it directly. """ -from ..array_helpers import (NaN, assert_exactly_equal, exactly_equal, infinity, logical_and, - logical_not, logical_or) -from ..hypothesis_helpers import numeric_arrays +from ..array_helpers import NaN, assert_exactly_equal, exactly_equal, infinity, logical_or +from ..hypothesis_helpers import floating_arrays, broadcastable_floating_array_pairs from .._array_module import logaddexp from hypothesis import given -@given(numeric_arrays, numeric_arrays) -def test_logaddexp_special_cases_two_args_either(arg1, arg2): +@given(broadcastable_floating_array_pairs()) +def test_logaddexp_special_cases_two_args_either_1(pair): """ Special case test for `logaddexp(x1, x2)`: - - If either `x1_i` or `x2_i` is `NaN`, the result is `NaN`. + - If either `x1_i` or `x2_i` is `NaN`, the result is `NaN`. """ + arg1, arg2 = pair res = logaddexp(arg1, arg2) mask = logical_or(exactly_equal(arg1, NaN(arg1.shape, arg1.dtype)), exactly_equal(arg2, NaN(arg1.shape, arg1.dtype))) assert_exactly_equal(res[mask], (NaN(arg1.shape, arg1.dtype))[mask]) -@given(numeric_arrays, numeric_arrays) -def test_logaddexp_special_cases_two_args_equal__notequal(arg1, arg2): +@given(broadcastable_floating_array_pairs()) +def test_logaddexp_special_cases_two_args_either_2(pair): """ Special case test for `logaddexp(x1, x2)`: - - If `x1_i` is `+infinity` and `x2_i` is not `NaN`, the result is `+infinity`. + - If either `x1_i` or `x2_i` is `+infinity`, the result is `+infinity`. """ + arg1, arg2 = pair res = logaddexp(arg1, arg2) - mask = logical_and(exactly_equal(arg1, infinity(arg1.shape, arg1.dtype)), logical_not(exactly_equal(arg2, NaN(arg2.shape, arg2.dtype)))) - assert_exactly_equal(res[mask], (infinity(arg1.shape, arg1.dtype))[mask]) - - -@given(numeric_arrays, numeric_arrays) -def test_logaddexp_special_cases_two_args_notequal__equal(arg1, arg2): - """ - Special case test for `logaddexp(x1, x2)`: - - - If `x1_i` is not `NaN` and `x2_i` is `+infinity`, the result is `+infinity`. - - """ - res = logaddexp(arg1, arg2) - mask = logical_and(logical_not(exactly_equal(arg1, NaN(arg1.shape, arg1.dtype))), exactly_equal(arg2, infinity(arg2.shape, arg2.dtype))) + mask = logical_or(exactly_equal(arg1, infinity(arg1.shape, arg1.dtype)), exactly_equal(arg2, infinity(arg1.shape, arg1.dtype))) assert_exactly_equal(res[mask], (infinity(arg1.shape, arg1.dtype))[mask]) diff --git a/array_api_tests/special_cases/test_multiply.py b/array_api_tests/special_cases/test_multiply.py index 0ab2eec0..25105576 100644 --- a/array_api_tests/special_cases/test_multiply.py +++ b/array_api_tests/special_cases/test_multiply.py @@ -11,111 +11,119 @@ assert_negative_mathematical_sign, assert_positive_mathematical_sign, exactly_equal, infinity, isfinite, logical_and, logical_not, logical_or, non_zero, same_sign, zero) -from ..hypothesis_helpers import numeric_arrays +from ..hypothesis_helpers import floating_arrays, broadcastable_floating_array_pairs from .._array_module import multiply from hypothesis import given -@given(numeric_arrays, numeric_arrays) -def test_multiply_special_cases_two_args_either(arg1, arg2): +@given(broadcastable_floating_array_pairs()) +def test_multiply_special_cases_two_args_either(pair): """ Special case test for `multiply(x1, x2, /)`: - If either `x1_i` or `x2_i` is `NaN`, the result is `NaN`. """ + arg1, arg2 = pair res = multiply(arg1, arg2) mask = logical_or(exactly_equal(arg1, NaN(arg1.shape, arg1.dtype)), exactly_equal(arg2, NaN(arg1.shape, arg1.dtype))) assert_exactly_equal(res[mask], (NaN(arg1.shape, arg1.dtype))[mask]) -@given(numeric_arrays, numeric_arrays) -def test_multiply_special_cases_two_args_either__either_1(arg1, arg2): +@given(broadcastable_floating_array_pairs()) +def test_multiply_special_cases_two_args_either__either_1(pair): """ Special case test for `multiply(x1, x2, /)`: - If `x1_i` is either `+infinity` or `-infinity` and `x2_i` is either `+0` or `-0`, the result is `NaN`. """ + arg1, arg2 = pair res = multiply(arg1, arg2) mask = logical_and(logical_or(exactly_equal(arg1, infinity(arg1.shape, arg1.dtype)), exactly_equal(arg1, -infinity(arg1.shape, arg1.dtype))), logical_or(exactly_equal(arg2, zero(arg2.shape, arg2.dtype)), exactly_equal(arg2, -zero(arg2.shape, arg2.dtype)))) assert_exactly_equal(res[mask], (NaN(arg1.shape, arg1.dtype))[mask]) -@given(numeric_arrays, numeric_arrays) -def test_multiply_special_cases_two_args_either__either_2(arg1, arg2): +@given(broadcastable_floating_array_pairs()) +def test_multiply_special_cases_two_args_either__either_2(pair): """ Special case test for `multiply(x1, x2, /)`: - If `x1_i` is either `+0` or `-0` and `x2_i` is either `+infinity` or `-infinity`, the result is `NaN`. """ + arg1, arg2 = pair res = multiply(arg1, arg2) mask = logical_and(logical_or(exactly_equal(arg1, zero(arg1.shape, arg1.dtype)), exactly_equal(arg1, -zero(arg1.shape, arg1.dtype))), logical_or(exactly_equal(arg2, infinity(arg2.shape, arg2.dtype)), exactly_equal(arg2, -infinity(arg2.shape, arg2.dtype)))) assert_exactly_equal(res[mask], (NaN(arg1.shape, arg1.dtype))[mask]) -@given(numeric_arrays, numeric_arrays) -def test_multiply_special_cases_two_args_either__either_3(arg1, arg2): +@given(broadcastable_floating_array_pairs()) +def test_multiply_special_cases_two_args_either__either_3(pair): """ Special case test for `multiply(x1, x2, /)`: - If `x1_i` is either `+infinity` or `-infinity` and `x2_i` is either `+infinity` or `-infinity`, the result is a signed infinity with the mathematical sign determined by the rule already stated above. """ + arg1, arg2 = pair res = multiply(arg1, arg2) mask = logical_and(logical_or(exactly_equal(arg1, infinity(arg1.shape, arg1.dtype)), exactly_equal(arg1, -infinity(arg1.shape, arg1.dtype))), logical_or(exactly_equal(arg2, infinity(arg2.shape, arg2.dtype)), exactly_equal(arg2, -infinity(arg2.shape, arg2.dtype)))) assert_isinf(res[mask]) -@given(numeric_arrays, numeric_arrays) -def test_multiply_special_cases_two_args_same_sign_except(arg1, arg2): +@given(broadcastable_floating_array_pairs()) +def test_multiply_special_cases_two_args_same_sign_except(pair): """ Special case test for `multiply(x1, x2, /)`: - If `x1_i` and `x2_i` have the same mathematical sign, the result has a positive mathematical sign, unless the result is `NaN`. If the result is `NaN`, the "sign" of `NaN` is implementation-defined. """ + arg1, arg2 = pair res = multiply(arg1, arg2) mask = logical_and(same_sign(arg1, arg2), logical_not(exactly_equal(res, NaN(res.shape, res.dtype)))) assert_positive_mathematical_sign(res[mask]) -@given(numeric_arrays, numeric_arrays) -def test_multiply_special_cases_two_args_different_signs_except(arg1, arg2): +@given(broadcastable_floating_array_pairs()) +def test_multiply_special_cases_two_args_different_signs_except(pair): """ Special case test for `multiply(x1, x2, /)`: - If `x1_i` and `x2_i` have different mathematical signs, the result has a negative mathematical sign, unless the result is `NaN`. If the result is `NaN`, the "sign" of `NaN` is implementation-defined. """ + arg1, arg2 = pair res = multiply(arg1, arg2) mask = logical_and(logical_not(same_sign(arg1, arg2)), logical_not(exactly_equal(res, NaN(res.shape, res.dtype)))) assert_negative_mathematical_sign(res[mask]) -@given(numeric_arrays, numeric_arrays) -def test_multiply_special_cases_two_args_either__equal(arg1, arg2): +@given(broadcastable_floating_array_pairs()) +def test_multiply_special_cases_two_args_either__equal(pair): """ Special case test for `multiply(x1, x2, /)`: - If `x1_i` is either `+infinity` or `-infinity` and `x2_i` is a nonzero finite number, the result is a signed infinity with the mathematical sign determined by the rule already stated above. """ + arg1, arg2 = pair res = multiply(arg1, arg2) mask = logical_and(logical_or(exactly_equal(arg1, infinity(arg1.shape, arg1.dtype)), exactly_equal(arg1, -infinity(arg1.shape, arg1.dtype))), logical_and(isfinite(arg2), non_zero(arg2))) assert_isinf(res[mask]) -@given(numeric_arrays, numeric_arrays) -def test_multiply_special_cases_two_args_equal__either(arg1, arg2): +@given(broadcastable_floating_array_pairs()) +def test_multiply_special_cases_two_args_equal__either(pair): """ Special case test for `multiply(x1, x2, /)`: - If `x1_i` is a nonzero finite number and `x2_i` is either `+infinity` or `-infinity`, the result is a signed infinity with the mathematical sign determined by the rule already stated above. """ + arg1, arg2 = pair res = multiply(arg1, arg2) mask = logical_and(logical_and(isfinite(arg1), non_zero(arg1)), logical_or(exactly_equal(arg2, infinity(arg2.shape, arg2.dtype)), exactly_equal(arg2, -infinity(arg2.shape, arg2.dtype)))) assert_isinf(res[mask]) diff --git a/array_api_tests/special_cases/test_pow.py b/array_api_tests/special_cases/test_pow.py index a422ffd3..11c539ca 100644 --- a/array_api_tests/special_cases/test_pow.py +++ b/array_api_tests/special_cases/test_pow.py @@ -9,319 +9,343 @@ from ..array_helpers import (NaN, assert_exactly_equal, exactly_equal, greater, infinity, isfinite, isintegral, isodd, less, logical_and, logical_not, notequal, one, zero) -from ..hypothesis_helpers import numeric_arrays +from ..hypothesis_helpers import floating_arrays, broadcastable_floating_array_pairs from .._array_module import pow from hypothesis import given -@given(numeric_arrays, numeric_arrays) -def test_pow_special_cases_two_args_notequal__equal(arg1, arg2): +@given(broadcastable_floating_array_pairs()) +def test_pow_special_cases_two_args_notequal__equal(pair): """ Special case test for `pow(x1, x2, /)`: - If `x1_i` is not equal to `1` and `x2_i` is `NaN`, the result is `NaN`. """ + arg1, arg2 = pair res = pow(arg1, arg2) mask = logical_and(logical_not(exactly_equal(arg1, one(arg1.shape, arg1.dtype))), exactly_equal(arg2, NaN(arg2.shape, arg2.dtype))) assert_exactly_equal(res[mask], (NaN(arg1.shape, arg1.dtype))[mask]) -@given(numeric_arrays, numeric_arrays) -def test_pow_special_cases_two_args_even_if_1(arg1, arg2): +@given(broadcastable_floating_array_pairs()) +def test_pow_special_cases_two_args_even_if_1(pair): """ Special case test for `pow(x1, x2, /)`: - If `x2_i` is `+0`, the result is `1`, even if `x1_i` is `NaN`. """ + arg1, arg2 = pair res = pow(arg1, arg2) mask = exactly_equal(arg2, zero(arg2.shape, arg2.dtype)) assert_exactly_equal(res[mask], (one(arg1.shape, arg1.dtype))[mask]) -@given(numeric_arrays, numeric_arrays) -def test_pow_special_cases_two_args_even_if_2(arg1, arg2): +@given(broadcastable_floating_array_pairs()) +def test_pow_special_cases_two_args_even_if_2(pair): """ Special case test for `pow(x1, x2, /)`: - If `x2_i` is `-0`, the result is `1`, even if `x1_i` is `NaN`. """ + arg1, arg2 = pair res = pow(arg1, arg2) mask = exactly_equal(arg2, -zero(arg2.shape, arg2.dtype)) assert_exactly_equal(res[mask], (one(arg1.shape, arg1.dtype))[mask]) -@given(numeric_arrays, numeric_arrays) -def test_pow_special_cases_two_args_equal__notequal_1(arg1, arg2): +@given(broadcastable_floating_array_pairs()) +def test_pow_special_cases_two_args_equal__notequal_1(pair): """ Special case test for `pow(x1, x2, /)`: - If `x1_i` is `NaN` and `x2_i` is not equal to `0`, the result is `NaN`. """ + arg1, arg2 = pair res = pow(arg1, arg2) mask = logical_and(exactly_equal(arg1, NaN(arg1.shape, arg1.dtype)), notequal(arg2, zero(arg2.shape, arg2.dtype))) assert_exactly_equal(res[mask], (NaN(arg1.shape, arg1.dtype))[mask]) -@given(numeric_arrays, numeric_arrays) -def test_pow_special_cases_two_args_equal__notequal_2(arg1, arg2): +@given(broadcastable_floating_array_pairs()) +def test_pow_special_cases_two_args_equal__notequal_2(pair): """ Special case test for `pow(x1, x2, /)`: - If `x1_i` is `1` and `x2_i` is not `NaN`, the result is `1`. """ + arg1, arg2 = pair res = pow(arg1, arg2) mask = logical_and(exactly_equal(arg1, one(arg1.shape, arg1.dtype)), logical_not(exactly_equal(arg2, NaN(arg2.shape, arg2.dtype)))) assert_exactly_equal(res[mask], (one(arg1.shape, arg1.dtype))[mask]) -@given(numeric_arrays, numeric_arrays) -def test_pow_special_cases_two_args_absgreater__equal_1(arg1, arg2): +@given(broadcastable_floating_array_pairs()) +def test_pow_special_cases_two_args_absgreater__equal_1(pair): """ Special case test for `pow(x1, x2, /)`: - If `abs(x1_i)` is greater than `1` and `x2_i` is `+infinity`, the result is `+infinity`. """ + arg1, arg2 = pair res = pow(arg1, arg2) mask = logical_and(greater(abs(arg1), one(arg1.shape, arg1.dtype)), exactly_equal(arg2, infinity(arg2.shape, arg2.dtype))) assert_exactly_equal(res[mask], (infinity(arg1.shape, arg1.dtype))[mask]) -@given(numeric_arrays, numeric_arrays) -def test_pow_special_cases_two_args_absgreater__equal_2(arg1, arg2): +@given(broadcastable_floating_array_pairs()) +def test_pow_special_cases_two_args_absgreater__equal_2(pair): """ Special case test for `pow(x1, x2, /)`: - If `abs(x1_i)` is greater than `1` and `x2_i` is `-infinity`, the result is `+0`. """ + arg1, arg2 = pair res = pow(arg1, arg2) mask = logical_and(greater(abs(arg1), one(arg1.shape, arg1.dtype)), exactly_equal(arg2, -infinity(arg2.shape, arg2.dtype))) assert_exactly_equal(res[mask], (zero(arg1.shape, arg1.dtype))[mask]) -@given(numeric_arrays, numeric_arrays) -def test_pow_special_cases_two_args_absequal__equal_1(arg1, arg2): +@given(broadcastable_floating_array_pairs()) +def test_pow_special_cases_two_args_absequal__equal_1(pair): """ Special case test for `pow(x1, x2, /)`: - If `abs(x1_i)` is `1` and `x2_i` is `+infinity`, the result is `1`. """ + arg1, arg2 = pair res = pow(arg1, arg2) mask = logical_and(exactly_equal(abs(arg1), one(arg1.shape, arg1.dtype)), exactly_equal(arg2, infinity(arg2.shape, arg2.dtype))) assert_exactly_equal(res[mask], (one(arg1.shape, arg1.dtype))[mask]) -@given(numeric_arrays, numeric_arrays) -def test_pow_special_cases_two_args_absequal__equal_2(arg1, arg2): +@given(broadcastable_floating_array_pairs()) +def test_pow_special_cases_two_args_absequal__equal_2(pair): """ Special case test for `pow(x1, x2, /)`: - If `abs(x1_i)` is `1` and `x2_i` is `-infinity`, the result is `1`. """ + arg1, arg2 = pair res = pow(arg1, arg2) mask = logical_and(exactly_equal(abs(arg1), one(arg1.shape, arg1.dtype)), exactly_equal(arg2, -infinity(arg2.shape, arg2.dtype))) assert_exactly_equal(res[mask], (one(arg1.shape, arg1.dtype))[mask]) -@given(numeric_arrays, numeric_arrays) -def test_pow_special_cases_two_args_absless__equal_1(arg1, arg2): +@given(broadcastable_floating_array_pairs()) +def test_pow_special_cases_two_args_absless__equal_1(pair): """ Special case test for `pow(x1, x2, /)`: - If `abs(x1_i)` is less than `1` and `x2_i` is `+infinity`, the result is `+0`. """ + arg1, arg2 = pair res = pow(arg1, arg2) mask = logical_and(less(abs(arg1), one(arg1.shape, arg1.dtype)), exactly_equal(arg2, infinity(arg2.shape, arg2.dtype))) assert_exactly_equal(res[mask], (zero(arg1.shape, arg1.dtype))[mask]) -@given(numeric_arrays, numeric_arrays) -def test_pow_special_cases_two_args_absless__equal_2(arg1, arg2): +@given(broadcastable_floating_array_pairs()) +def test_pow_special_cases_two_args_absless__equal_2(pair): """ Special case test for `pow(x1, x2, /)`: - If `abs(x1_i)` is less than `1` and `x2_i` is `-infinity`, the result is `+infinity`. """ + arg1, arg2 = pair res = pow(arg1, arg2) mask = logical_and(less(abs(arg1), one(arg1.shape, arg1.dtype)), exactly_equal(arg2, -infinity(arg2.shape, arg2.dtype))) assert_exactly_equal(res[mask], (infinity(arg1.shape, arg1.dtype))[mask]) -@given(numeric_arrays, numeric_arrays) -def test_pow_special_cases_two_args_equal__greater_1(arg1, arg2): +@given(broadcastable_floating_array_pairs()) +def test_pow_special_cases_two_args_equal__greater_1(pair): """ Special case test for `pow(x1, x2, /)`: - If `x1_i` is `+infinity` and `x2_i` is greater than `0`, the result is `+infinity`. """ + arg1, arg2 = pair res = pow(arg1, arg2) mask = logical_and(exactly_equal(arg1, infinity(arg1.shape, arg1.dtype)), greater(arg2, zero(arg2.shape, arg2.dtype))) assert_exactly_equal(res[mask], (infinity(arg1.shape, arg1.dtype))[mask]) -@given(numeric_arrays, numeric_arrays) -def test_pow_special_cases_two_args_equal__greater_2(arg1, arg2): +@given(broadcastable_floating_array_pairs()) +def test_pow_special_cases_two_args_equal__greater_2(pair): """ Special case test for `pow(x1, x2, /)`: - If `x1_i` is `+0` and `x2_i` is greater than `0`, the result is `+0`. """ + arg1, arg2 = pair res = pow(arg1, arg2) mask = logical_and(exactly_equal(arg1, zero(arg1.shape, arg1.dtype)), greater(arg2, zero(arg2.shape, arg2.dtype))) assert_exactly_equal(res[mask], (zero(arg1.shape, arg1.dtype))[mask]) -@given(numeric_arrays, numeric_arrays) -def test_pow_special_cases_two_args_equal__less_1(arg1, arg2): +@given(broadcastable_floating_array_pairs()) +def test_pow_special_cases_two_args_equal__less_1(pair): """ Special case test for `pow(x1, x2, /)`: - If `x1_i` is `+infinity` and `x2_i` is less than `0`, the result is `+0`. """ + arg1, arg2 = pair res = pow(arg1, arg2) mask = logical_and(exactly_equal(arg1, infinity(arg1.shape, arg1.dtype)), less(arg2, zero(arg2.shape, arg2.dtype))) assert_exactly_equal(res[mask], (zero(arg1.shape, arg1.dtype))[mask]) -@given(numeric_arrays, numeric_arrays) -def test_pow_special_cases_two_args_equal__less_2(arg1, arg2): +@given(broadcastable_floating_array_pairs()) +def test_pow_special_cases_two_args_equal__less_2(pair): """ Special case test for `pow(x1, x2, /)`: - If `x1_i` is `+0` and `x2_i` is less than `0`, the result is `+infinity`. """ + arg1, arg2 = pair res = pow(arg1, arg2) mask = logical_and(exactly_equal(arg1, zero(arg1.shape, arg1.dtype)), less(arg2, zero(arg2.shape, arg2.dtype))) assert_exactly_equal(res[mask], (infinity(arg1.shape, arg1.dtype))[mask]) -@given(numeric_arrays, numeric_arrays) -def test_pow_special_cases_two_args_equal__greater_equal_1(arg1, arg2): +@given(broadcastable_floating_array_pairs()) +def test_pow_special_cases_two_args_equal__greater_equal_1(pair): """ Special case test for `pow(x1, x2, /)`: - If `x1_i` is `-infinity`, `x2_i` is greater than `0`, and `x2_i` is an odd integer value, the result is `-infinity`. """ + arg1, arg2 = pair res = pow(arg1, arg2) mask = logical_and(exactly_equal(arg1, -infinity(arg1.shape, arg1.dtype)), logical_and(greater(arg2, zero(arg2.shape, arg2.dtype)), isodd(arg2))) assert_exactly_equal(res[mask], (-infinity(arg1.shape, arg1.dtype))[mask]) -@given(numeric_arrays, numeric_arrays) -def test_pow_special_cases_two_args_equal__greater_equal_2(arg1, arg2): +@given(broadcastable_floating_array_pairs()) +def test_pow_special_cases_two_args_equal__greater_equal_2(pair): """ Special case test for `pow(x1, x2, /)`: - If `x1_i` is `-0`, `x2_i` is greater than `0`, and `x2_i` is an odd integer value, the result is `-0`. """ + arg1, arg2 = pair res = pow(arg1, arg2) mask = logical_and(exactly_equal(arg1, -zero(arg1.shape, arg1.dtype)), logical_and(greater(arg2, zero(arg2.shape, arg2.dtype)), isodd(arg2))) assert_exactly_equal(res[mask], (-zero(arg1.shape, arg1.dtype))[mask]) -@given(numeric_arrays, numeric_arrays) -def test_pow_special_cases_two_args_equal__greater_notequal_1(arg1, arg2): +@given(broadcastable_floating_array_pairs()) +def test_pow_special_cases_two_args_equal__greater_notequal_1(pair): """ Special case test for `pow(x1, x2, /)`: - If `x1_i` is `-infinity`, `x2_i` is greater than `0`, and `x2_i` is not an odd integer value, the result is `+infinity`. """ + arg1, arg2 = pair res = pow(arg1, arg2) mask = logical_and(exactly_equal(arg1, -infinity(arg1.shape, arg1.dtype)), logical_and(greater(arg2, zero(arg2.shape, arg2.dtype)), logical_not(isodd(arg2)))) assert_exactly_equal(res[mask], (infinity(arg1.shape, arg1.dtype))[mask]) -@given(numeric_arrays, numeric_arrays) -def test_pow_special_cases_two_args_equal__greater_notequal_2(arg1, arg2): +@given(broadcastable_floating_array_pairs()) +def test_pow_special_cases_two_args_equal__greater_notequal_2(pair): """ Special case test for `pow(x1, x2, /)`: - If `x1_i` is `-0`, `x2_i` is greater than `0`, and `x2_i` is not an odd integer value, the result is `+0`. """ + arg1, arg2 = pair res = pow(arg1, arg2) mask = logical_and(exactly_equal(arg1, -zero(arg1.shape, arg1.dtype)), logical_and(greater(arg2, zero(arg2.shape, arg2.dtype)), logical_not(isodd(arg2)))) assert_exactly_equal(res[mask], (zero(arg1.shape, arg1.dtype))[mask]) -@given(numeric_arrays, numeric_arrays) -def test_pow_special_cases_two_args_equal__less_equal_1(arg1, arg2): +@given(broadcastable_floating_array_pairs()) +def test_pow_special_cases_two_args_equal__less_equal_1(pair): """ Special case test for `pow(x1, x2, /)`: - If `x1_i` is `-infinity`, `x2_i` is less than `0`, and `x2_i` is an odd integer value, the result is `-0`. """ + arg1, arg2 = pair res = pow(arg1, arg2) mask = logical_and(exactly_equal(arg1, -infinity(arg1.shape, arg1.dtype)), logical_and(less(arg2, zero(arg2.shape, arg2.dtype)), isodd(arg2))) assert_exactly_equal(res[mask], (-zero(arg1.shape, arg1.dtype))[mask]) -@given(numeric_arrays, numeric_arrays) -def test_pow_special_cases_two_args_equal__less_equal_2(arg1, arg2): +@given(broadcastable_floating_array_pairs()) +def test_pow_special_cases_two_args_equal__less_equal_2(pair): """ Special case test for `pow(x1, x2, /)`: - If `x1_i` is `-0`, `x2_i` is less than `0`, and `x2_i` is an odd integer value, the result is `-infinity`. """ + arg1, arg2 = pair res = pow(arg1, arg2) mask = logical_and(exactly_equal(arg1, -zero(arg1.shape, arg1.dtype)), logical_and(less(arg2, zero(arg2.shape, arg2.dtype)), isodd(arg2))) assert_exactly_equal(res[mask], (-infinity(arg1.shape, arg1.dtype))[mask]) -@given(numeric_arrays, numeric_arrays) -def test_pow_special_cases_two_args_equal__less_notequal_1(arg1, arg2): +@given(broadcastable_floating_array_pairs()) +def test_pow_special_cases_two_args_equal__less_notequal_1(pair): """ Special case test for `pow(x1, x2, /)`: - If `x1_i` is `-infinity`, `x2_i` is less than `0`, and `x2_i` is not an odd integer value, the result is `+0`. """ + arg1, arg2 = pair res = pow(arg1, arg2) mask = logical_and(exactly_equal(arg1, -infinity(arg1.shape, arg1.dtype)), logical_and(less(arg2, zero(arg2.shape, arg2.dtype)), logical_not(isodd(arg2)))) assert_exactly_equal(res[mask], (zero(arg1.shape, arg1.dtype))[mask]) -@given(numeric_arrays, numeric_arrays) -def test_pow_special_cases_two_args_equal__less_notequal_2(arg1, arg2): +@given(broadcastable_floating_array_pairs()) +def test_pow_special_cases_two_args_equal__less_notequal_2(pair): """ Special case test for `pow(x1, x2, /)`: - If `x1_i` is `-0`, `x2_i` is less than `0`, and `x2_i` is not an odd integer value, the result is `+infinity`. """ + arg1, arg2 = pair res = pow(arg1, arg2) mask = logical_and(exactly_equal(arg1, -zero(arg1.shape, arg1.dtype)), logical_and(less(arg2, zero(arg2.shape, arg2.dtype)), logical_not(isodd(arg2)))) assert_exactly_equal(res[mask], (infinity(arg1.shape, arg1.dtype))[mask]) -@given(numeric_arrays, numeric_arrays) -def test_pow_special_cases_two_args_less_equal__equal_notequal(arg1, arg2): +@given(broadcastable_floating_array_pairs()) +def test_pow_special_cases_two_args_less_equal__equal_notequal(pair): """ Special case test for `pow(x1, x2, /)`: - If `x1_i` is less than `0`, `x1_i` is a finite number, `x2_i` is a finite number, and `x2_i` is not an integer value, the result is `NaN`. """ + arg1, arg2 = pair res = pow(arg1, arg2) mask = logical_and(logical_and(less(arg1, zero(arg1.shape, arg1.dtype)), isfinite(arg1)), logical_and(isfinite(arg2), logical_not(isintegral(arg2)))) assert_exactly_equal(res[mask], (NaN(arg1.shape, arg1.dtype))[mask]) diff --git a/array_api_tests/special_cases/test_round.py b/array_api_tests/special_cases/test_round.py index 89b66db0..0b9f1b59 100644 --- a/array_api_tests/special_cases/test_round.py +++ b/array_api_tests/special_cases/test_round.py @@ -9,13 +9,13 @@ from ..array_helpers import (assert_exactly_equal, assert_iseven, assert_positive, ceil, equal, floor, isintegral, logical_and, not_equal, one, subtract) -from ..hypothesis_helpers import numeric_arrays +from ..hypothesis_helpers import floating_arrays, broadcastable_floating_array_pairs from .._array_module import round from hypothesis import given -@given(numeric_arrays) +@given(floating_arrays) def test_round_special_cases_one_arg_equal(arg1): """ Special case test for `round(x, /)`: @@ -28,7 +28,7 @@ def test_round_special_cases_one_arg_equal(arg1): assert_exactly_equal(res[mask], (arg1)[mask]) -@given(numeric_arrays) +@given(floating_arrays) def test_round_special_cases_one_arg_two_integers_equally_close(arg1): """ Special case test for `round(x, /)`: diff --git a/array_api_tests/special_cases/test_sign.py b/array_api_tests/special_cases/test_sign.py index dd661811..4e7314e0 100644 --- a/array_api_tests/special_cases/test_sign.py +++ b/array_api_tests/special_cases/test_sign.py @@ -8,13 +8,13 @@ """ from ..array_helpers import assert_exactly_equal, exactly_equal, greater, less, logical_or, one, zero -from ..hypothesis_helpers import numeric_arrays +from ..hypothesis_helpers import floating_arrays, broadcastable_floating_array_pairs from .._array_module import sign from hypothesis import given -@given(numeric_arrays) +@given(floating_arrays) def test_sign_special_cases_one_arg_less(arg1): """ Special case test for `sign(x, /)`: @@ -27,7 +27,7 @@ def test_sign_special_cases_one_arg_less(arg1): assert_exactly_equal(res[mask], (-one(arg1.shape, arg1.dtype))[mask]) -@given(numeric_arrays) +@given(floating_arrays) def test_sign_special_cases_one_arg_either(arg1): """ Special case test for `sign(x, /)`: @@ -40,7 +40,7 @@ def test_sign_special_cases_one_arg_either(arg1): assert_exactly_equal(res[mask], (zero(arg1.shape, arg1.dtype))[mask]) -@given(numeric_arrays) +@given(floating_arrays) def test_sign_special_cases_one_arg_greater(arg1): """ Special case test for `sign(x, /)`: diff --git a/array_api_tests/special_cases/test_sin.py b/array_api_tests/special_cases/test_sin.py index 4af01736..659782e7 100644 --- a/array_api_tests/special_cases/test_sin.py +++ b/array_api_tests/special_cases/test_sin.py @@ -8,13 +8,13 @@ """ from ..array_helpers import NaN, assert_exactly_equal, exactly_equal, infinity, logical_or, zero -from ..hypothesis_helpers import numeric_arrays +from ..hypothesis_helpers import floating_arrays, broadcastable_floating_array_pairs from .._array_module import sin from hypothesis import given -@given(numeric_arrays) +@given(floating_arrays) def test_sin_special_cases_one_arg_equal_1(arg1): """ Special case test for `sin(x, /)`: @@ -27,7 +27,7 @@ def test_sin_special_cases_one_arg_equal_1(arg1): assert_exactly_equal(res[mask], (NaN(arg1.shape, arg1.dtype))[mask]) -@given(numeric_arrays) +@given(floating_arrays) def test_sin_special_cases_one_arg_equal_2(arg1): """ Special case test for `sin(x, /)`: @@ -40,7 +40,7 @@ def test_sin_special_cases_one_arg_equal_2(arg1): assert_exactly_equal(res[mask], (zero(arg1.shape, arg1.dtype))[mask]) -@given(numeric_arrays) +@given(floating_arrays) def test_sin_special_cases_one_arg_equal_3(arg1): """ Special case test for `sin(x, /)`: @@ -53,7 +53,7 @@ def test_sin_special_cases_one_arg_equal_3(arg1): assert_exactly_equal(res[mask], (-zero(arg1.shape, arg1.dtype))[mask]) -@given(numeric_arrays) +@given(floating_arrays) def test_sin_special_cases_one_arg_either(arg1): """ Special case test for `sin(x, /)`: diff --git a/array_api_tests/special_cases/test_sinh.py b/array_api_tests/special_cases/test_sinh.py index 4d2ff217..d4101ea9 100644 --- a/array_api_tests/special_cases/test_sinh.py +++ b/array_api_tests/special_cases/test_sinh.py @@ -8,13 +8,13 @@ """ from ..array_helpers import NaN, assert_exactly_equal, exactly_equal, infinity, zero -from ..hypothesis_helpers import numeric_arrays +from ..hypothesis_helpers import floating_arrays, broadcastable_floating_array_pairs from .._array_module import sinh from hypothesis import given -@given(numeric_arrays) +@given(floating_arrays) def test_sinh_special_cases_one_arg_equal_1(arg1): """ Special case test for `sinh(x, /)`: @@ -27,7 +27,7 @@ def test_sinh_special_cases_one_arg_equal_1(arg1): assert_exactly_equal(res[mask], (NaN(arg1.shape, arg1.dtype))[mask]) -@given(numeric_arrays) +@given(floating_arrays) def test_sinh_special_cases_one_arg_equal_2(arg1): """ Special case test for `sinh(x, /)`: @@ -40,7 +40,7 @@ def test_sinh_special_cases_one_arg_equal_2(arg1): assert_exactly_equal(res[mask], (zero(arg1.shape, arg1.dtype))[mask]) -@given(numeric_arrays) +@given(floating_arrays) def test_sinh_special_cases_one_arg_equal_3(arg1): """ Special case test for `sinh(x, /)`: @@ -53,7 +53,7 @@ def test_sinh_special_cases_one_arg_equal_3(arg1): assert_exactly_equal(res[mask], (-zero(arg1.shape, arg1.dtype))[mask]) -@given(numeric_arrays) +@given(floating_arrays) def test_sinh_special_cases_one_arg_equal_4(arg1): """ Special case test for `sinh(x, /)`: @@ -66,7 +66,7 @@ def test_sinh_special_cases_one_arg_equal_4(arg1): assert_exactly_equal(res[mask], (infinity(arg1.shape, arg1.dtype))[mask]) -@given(numeric_arrays) +@given(floating_arrays) def test_sinh_special_cases_one_arg_equal_5(arg1): """ Special case test for `sinh(x, /)`: diff --git a/array_api_tests/special_cases/test_sqrt.py b/array_api_tests/special_cases/test_sqrt.py index 18244755..6b48658c 100644 --- a/array_api_tests/special_cases/test_sqrt.py +++ b/array_api_tests/special_cases/test_sqrt.py @@ -8,13 +8,13 @@ """ from ..array_helpers import NaN, assert_exactly_equal, exactly_equal, infinity, less, zero -from ..hypothesis_helpers import numeric_arrays +from ..hypothesis_helpers import floating_arrays, broadcastable_floating_array_pairs from .._array_module import sqrt from hypothesis import given -@given(numeric_arrays) +@given(floating_arrays) def test_sqrt_special_cases_one_arg_equal_1(arg1): """ Special case test for `sqrt(x, /)`: @@ -27,7 +27,7 @@ def test_sqrt_special_cases_one_arg_equal_1(arg1): assert_exactly_equal(res[mask], (NaN(arg1.shape, arg1.dtype))[mask]) -@given(numeric_arrays) +@given(floating_arrays) def test_sqrt_special_cases_one_arg_equal_2(arg1): """ Special case test for `sqrt(x, /)`: @@ -40,7 +40,7 @@ def test_sqrt_special_cases_one_arg_equal_2(arg1): assert_exactly_equal(res[mask], (zero(arg1.shape, arg1.dtype))[mask]) -@given(numeric_arrays) +@given(floating_arrays) def test_sqrt_special_cases_one_arg_equal_3(arg1): """ Special case test for `sqrt(x, /)`: @@ -53,7 +53,7 @@ def test_sqrt_special_cases_one_arg_equal_3(arg1): assert_exactly_equal(res[mask], (-zero(arg1.shape, arg1.dtype))[mask]) -@given(numeric_arrays) +@given(floating_arrays) def test_sqrt_special_cases_one_arg_equal_4(arg1): """ Special case test for `sqrt(x, /)`: @@ -66,7 +66,7 @@ def test_sqrt_special_cases_one_arg_equal_4(arg1): assert_exactly_equal(res[mask], (infinity(arg1.shape, arg1.dtype))[mask]) -@given(numeric_arrays) +@given(floating_arrays) def test_sqrt_special_cases_one_arg_less(arg1): """ Special case test for `sqrt(x, /)`: diff --git a/array_api_tests/special_cases/test_tan.py b/array_api_tests/special_cases/test_tan.py index ec09878d..fa35e535 100644 --- a/array_api_tests/special_cases/test_tan.py +++ b/array_api_tests/special_cases/test_tan.py @@ -8,13 +8,13 @@ """ from ..array_helpers import NaN, assert_exactly_equal, exactly_equal, infinity, logical_or, zero -from ..hypothesis_helpers import numeric_arrays +from ..hypothesis_helpers import floating_arrays, broadcastable_floating_array_pairs from .._array_module import tan from hypothesis import given -@given(numeric_arrays) +@given(floating_arrays) def test_tan_special_cases_one_arg_equal_1(arg1): """ Special case test for `tan(x, /)`: @@ -27,7 +27,7 @@ def test_tan_special_cases_one_arg_equal_1(arg1): assert_exactly_equal(res[mask], (NaN(arg1.shape, arg1.dtype))[mask]) -@given(numeric_arrays) +@given(floating_arrays) def test_tan_special_cases_one_arg_equal_2(arg1): """ Special case test for `tan(x, /)`: @@ -40,7 +40,7 @@ def test_tan_special_cases_one_arg_equal_2(arg1): assert_exactly_equal(res[mask], (zero(arg1.shape, arg1.dtype))[mask]) -@given(numeric_arrays) +@given(floating_arrays) def test_tan_special_cases_one_arg_equal_3(arg1): """ Special case test for `tan(x, /)`: @@ -53,7 +53,7 @@ def test_tan_special_cases_one_arg_equal_3(arg1): assert_exactly_equal(res[mask], (-zero(arg1.shape, arg1.dtype))[mask]) -@given(numeric_arrays) +@given(floating_arrays) def test_tan_special_cases_one_arg_either(arg1): """ Special case test for `tan(x, /)`: diff --git a/array_api_tests/special_cases/test_tanh.py b/array_api_tests/special_cases/test_tanh.py index 91304c2f..784f63d7 100644 --- a/array_api_tests/special_cases/test_tanh.py +++ b/array_api_tests/special_cases/test_tanh.py @@ -8,13 +8,13 @@ """ from ..array_helpers import NaN, assert_exactly_equal, exactly_equal, infinity, one, zero -from ..hypothesis_helpers import numeric_arrays +from ..hypothesis_helpers import floating_arrays, broadcastable_floating_array_pairs from .._array_module import tanh from hypothesis import given -@given(numeric_arrays) +@given(floating_arrays) def test_tanh_special_cases_one_arg_equal_1(arg1): """ Special case test for `tanh(x, /)`: @@ -27,7 +27,7 @@ def test_tanh_special_cases_one_arg_equal_1(arg1): assert_exactly_equal(res[mask], (NaN(arg1.shape, arg1.dtype))[mask]) -@given(numeric_arrays) +@given(floating_arrays) def test_tanh_special_cases_one_arg_equal_2(arg1): """ Special case test for `tanh(x, /)`: @@ -40,7 +40,7 @@ def test_tanh_special_cases_one_arg_equal_2(arg1): assert_exactly_equal(res[mask], (zero(arg1.shape, arg1.dtype))[mask]) -@given(numeric_arrays) +@given(floating_arrays) def test_tanh_special_cases_one_arg_equal_3(arg1): """ Special case test for `tanh(x, /)`: @@ -53,7 +53,7 @@ def test_tanh_special_cases_one_arg_equal_3(arg1): assert_exactly_equal(res[mask], (-zero(arg1.shape, arg1.dtype))[mask]) -@given(numeric_arrays) +@given(floating_arrays) def test_tanh_special_cases_one_arg_equal_4(arg1): """ Special case test for `tanh(x, /)`: @@ -66,7 +66,7 @@ def test_tanh_special_cases_one_arg_equal_4(arg1): assert_exactly_equal(res[mask], (one(arg1.shape, arg1.dtype))[mask]) -@given(numeric_arrays) +@given(floating_arrays) def test_tanh_special_cases_one_arg_equal_5(arg1): """ Special case test for `tanh(x, /)`: diff --git a/array_api_tests/special_cases/test_trunc.py b/array_api_tests/special_cases/test_trunc.py index c6a11c6e..4919c1f6 100644 --- a/array_api_tests/special_cases/test_trunc.py +++ b/array_api_tests/special_cases/test_trunc.py @@ -8,13 +8,13 @@ """ from ..array_helpers import assert_exactly_equal, isintegral -from ..hypothesis_helpers import numeric_arrays +from ..hypothesis_helpers import floating_arrays, broadcastable_floating_array_pairs from .._array_module import trunc from hypothesis import given -@given(numeric_arrays) +@given(floating_arrays) def test_trunc_special_cases_one_arg_equal(arg1): """ Special case test for `trunc(x, /)`: diff --git a/array_api_tests/test_creation_functions.py b/array_api_tests/test_creation_functions.py index cc97c649..497d11c3 100644 --- a/array_api_tests/test_creation_functions.py +++ b/array_api_tests/test_creation_functions.py @@ -1,13 +1,14 @@ -from ._array_module import (asarray, arange, ceil, empty, eye, full, -equal, all, linspace, ones, zeros, isnan) +from hypothesis.strategies._internal.core import sampled_from +from ._array_module import (asarray, arange, ceil, empty, eye, full, full_like, + equal, all, linspace, ones, zeros, isnan) from .array_helpers import (is_integer_dtype, dtype_ranges, assert_exactly_equal, isintegral, is_float_dtype) from .hypothesis_helpers import (numeric_dtypes, dtypes, MAX_ARRAY_SIZE, shapes, sizes, sqrt_sizes, shared_dtypes, - scalars) + scalars, xps) from hypothesis import assume, given -from hypothesis.strategies import integers, floats, one_of, none, booleans, just +from hypothesis.strategies import integers, floats, one_of, none, booleans, just, data int_range = integers(-MAX_ARRAY_SIZE, MAX_ARRAY_SIZE) float_range = floats(-MAX_ARRAY_SIZE, MAX_ARRAY_SIZE, @@ -125,14 +126,32 @@ def test_full(shape, fill_value, dtype): assert a.dtype == dtype assert a.shape == shape, "full() produced an array with incorrect shape" + if is_float_dtype(a.dtype) and isnan(asarray(fill_value)): assert all(isnan(a)), "full() array did not equal the fill value" else: assert all(equal(a, asarray(fill_value, **kwargs))), "full() array did not equal the fill value" -# TODO: implement full_like (requires hypothesis arrays support) -def test_full_like(): - pass +@given(xps.scalar_dtypes(), xps.array_shapes(), data()) +def test_full_like(dtype, shape, data): + a = data.draw(xps.arrays(dtype, shape)) + fill_value = data.draw(xps.from_dtype(dtype)) + kwargs = data.draw(sampled_from([{}, {'dtype': dtype}])) + + a_like = full_like(a, fill_value, **kwargs) + + if dtype is None: + pass # TODO: Should it actually match the fill_value? + else: + assert a_like.dtype == dtype + + assert a_like.shape == shape, "full_like() produced an array with incorrect shape" + + if is_float_dtype(a_like.dtype) and isnan(asarray(fill_value)): + assert all(isnan(a_like)), "full_like() array did not equal the fill value" + else: + assert all(equal(a_like, asarray(fill_value, dtype=dtype))), "full_like() array did not equal the fill value" + @given(scalars(shared_dtypes, finite=True), scalars(shared_dtypes, finite=True), diff --git a/generate_stubs.py b/generate_stubs.py index deaab424..f5b5a6bc 100755 --- a/generate_stubs.py +++ b/generate_stubs.py @@ -75,7 +75,7 @@ """ from ..array_helpers import * -from ..hypothesis_helpers import numeric_arrays +from ..hypothesis_helpers import floating_arrays, broadcastable_floating_array_pairs from .._array_module import {func} from hypothesis import given @@ -475,8 +475,9 @@ def test_{func}_special_cases_{test_name_extra}(arg1): TWO_ARGS_TEMPLATE = """ {decorator} -def test_{func}_special_cases_{test_name_extra}(arg1, arg2): +def test_{func}_special_cases_{test_name_extra}(pair): {doc} + arg1, arg2 = pair res = {func}(arg1, arg2) mask = {mask} {assertion} @@ -495,7 +496,7 @@ def generate_special_case_test(func, typ, m, test_name_extra, sigs): """''' if typ.startswith("ONE_ARG"): - decorator = "@given(numeric_arrays)" + decorator = "@given(floating_arrays)" if typ == "ONE_ARG_EQUAL": value1, result = m.groups() value1 = parse_value(value1, 'arg1') @@ -534,7 +535,7 @@ def generate_special_case_test(func, typ, m, test_name_extra, sigs): ) elif typ.startswith("TWO_ARGS"): - decorator = "@given(numeric_arrays, numeric_arrays)" + decorator = "@given(broadcastable_floating_array_pairs())" if typ in [ "TWO_ARGS_EQUAL__EQUAL", "TWO_ARGS_GREATER__EQUAL", diff --git a/requirements.txt b/requirements.txt index f22f1570..daa9a889 100644 --- a/requirements.txt +++ b/requirements.txt @@ -2,3 +2,4 @@ pytest hypothesis regex removestar +hypothesis-array-api==0.1.2