Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Faster default runs #246

Merged
merged 10 commits into from
Apr 3, 2024
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,6 @@ jobs:
env:
ARRAY_API_TESTS_MODULE: array_api_strict
run: |
pytest -v -rxXfE --skips-file array-api-strict-skips.txt array_api_tests/
pytest -v -rxXfE --skips-file array-api-strict-skips.txt array_api_tests/ --hypothesis-disable-deadline
# We also have internal tests that isn't really necessary for adopters
pytest -v -rxXfE meta_tests/
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
Loading