Skip to content

Fix test_solve generating arrays larger than our max array size #242

New issue

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

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

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Mar 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion array_api_tests/hypothesis_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -312,8 +312,8 @@ def positive_definite_matrices(draw, dtypes=xps.floating_dtypes()):
@composite
def invertible_matrices(draw, dtypes=xps.floating_dtypes(), stack_shapes=shapes()):
# For now, just generate stacks of diagonal matrices.
n = draw(integers(0, SQRT_MAX_ARRAY_SIZE),)
stack_shape = draw(stack_shapes)
n = draw(integers(0, SQRT_MAX_ARRAY_SIZE // max(math.prod(stack_shape), 1)),)
dtype = draw(dtypes)
elements = one_of(
from_dtype(dtype, min_value=0.5, allow_nan=False, allow_infinity=False),
Expand Down
12 changes: 8 additions & 4 deletions array_api_tests/test_linalg.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,14 @@
data)
from ndindex import iter_indices

import math
import itertools
from typing import Tuple

from .array_helpers import assert_exactly_equal, asarray
from .hypothesis_helpers import (arrays, all_floating_dtypes, xps, shapes,
kwargs, matrix_shapes, square_matrix_shapes,
symmetric_matrices,
symmetric_matrices, SearchStrategy,
positive_definite_matrices, MAX_ARRAY_SIZE,
invertible_matrices, two_mutual_arrays,
mutually_promotable_dtypes, one_d_shapes,
Expand All @@ -35,6 +37,7 @@
from . import dtype_helpers as dh
from . import pytest_helpers as ph
from . import shape_helpers as sh
from .typing import Array

from . import _array_module
from . import _array_module as xp
Expand Down Expand Up @@ -589,7 +592,7 @@ def test_slogdet(x):
# TODO: Test this when we have tests for floating-point values.
# assert all(abs(linalg.det(x) - sign*exp(logabsdet)) < eps)

def solve_args():
def solve_args() -> Tuple[SearchStrategy[Array], SearchStrategy[Array]]:
"""
Strategy for the x1 and x2 arguments to test_solve()

Expand All @@ -608,8 +611,9 @@ def solve_args():

@composite
def _x2_shapes(draw):
end = draw(integers(0, SQRT_MAX_ARRAY_SIZE))
return draw(stack_shapes)[1] + draw(x1).shape[-1:] + (end,)
base_shape = draw(stack_shapes)[1] + draw(x1).shape[-1:]
end = draw(integers(0, SQRT_MAX_ARRAY_SIZE // max(math.prod(base_shape), 1)))
return base_shape + (end,)

x2_shapes = one_of(x1.map(lambda x: (x.shape[-1],)), _x2_shapes())
x2 = arrays(shape=x2_shapes, dtype=mutual_dtypes.map(lambda pair: pair[1]))
Expand Down