Skip to content

Commit

Permalink
Merge pull request data-apis#246 from honno/faster-default-runs
Browse files Browse the repository at this point in the history
Faster default runs
  • Loading branch information
honno authored Apr 3, 2024
2 parents a168e5a + ae1605f commit 3cf8ef6
Show file tree
Hide file tree
Showing 5 changed files with 91 additions and 148 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ jobs:
> There are several ways to avoid this problem:
>
> - Increase the maximum number of examples, e.g., by adding `--max-examples
> 200` to the test command (the default is `100`, see below). This will
> 200` to the test command (the default is `20`, see below). This will
> make it more likely that the failing case will be found, but it will also
> make the tests take longer to run.
> - Don't use `-o xfail_strict=True`. This will make it so that if an XFAIL
Expand All @@ -275,7 +275,7 @@ jobs:
The tests make heavy use
[Hypothesis](https://hypothesis.readthedocs.io/en/latest/). You can configure
how many examples are generated using the `--max-examples` flag, which
defaults to `100`. Lower values can be useful for quick checks, and larger
defaults to `20`. Lower values can be useful for quick checks, and larger
values should result in more rigorous runs. For example, `--max-examples
10_000` may find bugs where default runs don't but will take much longer to
run.
Expand Down
25 changes: 25 additions & 0 deletions array_api_tests/test_linalg.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ def _test_namedtuple(res, fields, func_name):
assert hasattr(res, field), f"{func_name}() result namedtuple doesn't have the '{field}' field"
assert res[i] is getattr(res, field), f"{func_name}() result namedtuple '{field}' field is not in position {i}"

@pytest.mark.unvectorized
@pytest.mark.xp_extension('linalg')
@given(
x=positive_definite_matrices(),
Expand Down Expand Up @@ -175,6 +176,7 @@ def cross_args(draw, dtype_objects=dh.real_dtypes):
)
return draw(arrays1), draw(arrays2), kw

@pytest.mark.unvectorized
@pytest.mark.xp_extension('linalg')
@given(
cross_args()
Expand Down Expand Up @@ -209,6 +211,7 @@ def exact_cross(a, b):
# vectors.
_test_stacks(linalg.cross, x1, x2, dims=1, matrix_axes=(axis,), res=res, true_val=exact_cross)

@pytest.mark.unvectorized
@pytest.mark.xp_extension('linalg')
@given(
x=arrays(dtype=all_floating_dtypes(), shape=square_matrix_shapes),
Expand All @@ -224,6 +227,7 @@ def test_det(x):

# TODO: Test that res actually corresponds to the determinant of x

@pytest.mark.unvectorized
@pytest.mark.xp_extension('linalg')
@given(
x=arrays(dtype=xps.scalar_dtypes(), shape=matrix_shapes()),
Expand Down Expand Up @@ -261,6 +265,7 @@ def true_diag(x_stack, offset=0):

_test_stacks(linalg.diagonal, x, **kw, res=res, dims=1, true_val=true_diag)

@pytest.mark.unvectorized
@pytest.mark.xp_extension('linalg')
@given(x=symmetric_matrices(finite=True))
def test_eigh(x):
Expand Down Expand Up @@ -299,6 +304,7 @@ def test_eigh(x):
# TODO: Test that res actually corresponds to the eigenvalues and
# eigenvectors of x

@pytest.mark.unvectorized
@pytest.mark.xp_extension('linalg')
@given(x=symmetric_matrices(finite=True))
def test_eigvalsh(x):
Expand All @@ -319,6 +325,7 @@ def test_eigvalsh(x):

# TODO: Test that res actually corresponds to the eigenvalues of x

@pytest.mark.unvectorized
@pytest.mark.xp_extension('linalg')
@given(x=invertible_matrices())
def test_inv(x):
Expand Down Expand Up @@ -372,19 +379,22 @@ def _test_matmul(namespace, x1, x2):
expected=stack_shape + (x1.shape[-2], x2.shape[-1]))
_test_stacks(matmul, x1, x2, res=res)

@pytest.mark.unvectorized
@pytest.mark.xp_extension('linalg')
@given(
*two_mutual_arrays(dh.real_dtypes)
)
def test_linalg_matmul(x1, x2):
return _test_matmul(linalg, x1, x2)

@pytest.mark.unvectorized
@given(
*two_mutual_arrays(dh.real_dtypes)
)
def test_matmul(x1, x2):
return _test_matmul(_array_module, x1, x2)

@pytest.mark.unvectorized
@pytest.mark.xp_extension('linalg')
@given(
x=finite_matrices(),
Expand All @@ -410,6 +420,7 @@ def test_matrix_norm(x, kw):
res=res)

matrix_power_n = shared(integers(-100, 100), key='matrix_power n')
@pytest.mark.unvectorized
@pytest.mark.xp_extension('linalg')
@given(
# Generate any square matrix if n >= 0 but only invertible matrices if n < 0
Expand All @@ -433,6 +444,7 @@ def test_matrix_power(x, n):
func = lambda x: linalg.matrix_power(x, n)
_test_stacks(func, x, res=res, true_val=true_val)

@pytest.mark.unvectorized
@pytest.mark.xp_extension('linalg')
@given(
x=finite_matrices(shape=rtol_shared_matrix_shapes),
Expand All @@ -457,13 +469,15 @@ def _test_matrix_transpose(namespace, x):

_test_stacks(matrix_transpose, x, res=res, true_val=true_val)

@pytest.mark.unvectorized
@pytest.mark.xp_extension('linalg')
@given(
x=arrays(dtype=xps.scalar_dtypes(), shape=matrix_shapes()),
)
def test_linalg_matrix_transpose(x):
return _test_matrix_transpose(linalg, x)

@pytest.mark.unvectorized
@given(
x=arrays(dtype=xps.scalar_dtypes(), shape=matrix_shapes()),
)
Expand Down Expand Up @@ -503,6 +517,7 @@ def test_outer(x1, x2):
def test_pinv(x, kw):
linalg.pinv(x, **kw)

@pytest.mark.unvectorized
@pytest.mark.xp_extension('linalg')
@given(
x=arrays(dtype=all_floating_dtypes(), shape=matrix_shapes()),
Expand Down Expand Up @@ -545,6 +560,7 @@ def test_qr(x, kw):
# Check that R is upper-triangular.
assert_exactly_equal(R, _array_module.triu(R))

@pytest.mark.unvectorized
@pytest.mark.xp_extension('linalg')
@given(
x=arrays(dtype=all_floating_dtypes(), shape=square_matrix_shapes),
Expand Down Expand Up @@ -617,6 +633,7 @@ def _x2_shapes(draw):
x2 = arrays(shape=x2_shapes, dtype=mutual_dtypes.map(lambda pair: pair[1]))
return x1, x2

@pytest.mark.unvectorized
@pytest.mark.xp_extension('linalg')
@given(*solve_args())
def test_solve(x1, x2):
Expand All @@ -635,6 +652,7 @@ def test_solve(x1, x2):
ph.assert_result_shape("solve", in_shapes=[x1.shape, x2.shape],
out_shape=res.shape, expected=expected_shape)

@pytest.mark.unvectorized
@pytest.mark.xp_extension('linalg')
@given(
x=finite_matrices(),
Expand Down Expand Up @@ -685,6 +703,7 @@ def test_svd(x, kw):
_test_stacks(lambda x: linalg.svd(x, **kw).S, x, dims=1, res=S)
_test_stacks(lambda x: linalg.svd(x, **kw).Vh, x, res=Vh)

@pytest.mark.unvectorized
@pytest.mark.xp_extension('linalg')
@given(
x=finite_matrices(),
Expand Down Expand Up @@ -818,6 +837,7 @@ def _test_tensordot(namespace, x1, x2, kw):
expected=result_shape)
_test_tensordot_stacks(x1, x2, kw, res)

@pytest.mark.unvectorized
@pytest.mark.xp_extension('linalg')
@given(
*two_mutual_arrays(dh.numeric_dtypes, two_shapes=tensordot_shapes()),
Expand All @@ -826,13 +846,15 @@ def _test_tensordot(namespace, x1, x2, kw):
def test_linalg_tensordot(x1, x2, kw):
_test_tensordot(linalg, x1, x2, kw)

@pytest.mark.unvectorized
@given(
*two_mutual_arrays(dh.numeric_dtypes, two_shapes=tensordot_shapes()),
tensordot_kw,
)
def test_tensordot(x1, x2, kw):
_test_tensordot(_array_module, x1, x2, kw)

@pytest.mark.unvectorized
@pytest.mark.xp_extension('linalg')
@given(
x=arrays(dtype=xps.numeric_dtypes(), shape=matrix_shapes()),
Expand Down Expand Up @@ -910,6 +932,7 @@ def true_val(x, y, axis=-1):
matrix_axes=(axis,), true_val=true_val)


@pytest.mark.unvectorized
@pytest.mark.xp_extension('linalg')
@given(
*two_mutual_arrays(dh.numeric_dtypes, mutually_broadcastable_shapes(2, min_dims=1)),
Expand All @@ -918,6 +941,7 @@ def true_val(x, y, axis=-1):
def test_linalg_vecdot(x1, x2, data):
_test_vecdot(linalg, x1, x2, data)

@pytest.mark.unvectorized
@given(
*two_mutual_arrays(dh.numeric_dtypes, mutually_broadcastable_shapes(2, min_dims=1)),
data(),
Expand All @@ -929,6 +953,7 @@ def test_vecdot(x1, x2, data):
# spec, so we just limit to reasonable values here.
max_ord = 100

@pytest.mark.unvectorized
@pytest.mark.xp_extension('linalg')
@given(
x=arrays(dtype=all_floating_dtypes(), shape=shapes(min_side=1)),
Expand Down
1 change: 1 addition & 0 deletions array_api_tests/test_manipulation_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ def assert_array_ndindex(
assert out[out_idx] == x[x_idx], msg


@pytest.mark.unvectorized
@given(
dtypes=hh.mutually_promotable_dtypes(None, dtypes=dh.numeric_dtypes),
base_shape=hh.shapes(),
Expand Down
Loading

0 comments on commit 3cf8ef6

Please sign in to comment.