-
Notifications
You must be signed in to change notification settings - Fork 45
test_reshape only tests zero-dim arrays #307
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
Comments
The first question I would try to answer for this particular issue is why the test is being skipped. If you just remove the flaky decorator, how does the test fail? You might have to run it many times, or run with many examples, using something like |
More generally speaking, something to be aware of with hypothesis, is that it has two different ways of limiting the scope of input examples to tests: filtering and changing generation. Filtering means you explicitly tell hypothesis to reject whatever case you don't want, using either The alternative is to change the test so that it can only generate the examples you want to see. The difference here is that you never actually filter out examples you don't want. This approach is generally better because you hypothesis doesn't ever waste time generating examples you don't want to see. And if hypothesis generates too many examples that get filtered out, it will issue a health warning like the one you saw. To take an example, let's say you wanted to generate only even integers. There are two ways you might do this. The first is to take @given(integers().filter(lambda n: n % 2 == 0))
def test_even(n):
assert n % 2 == 0 This works, but the problem here is that A better approach would be to only generate even integers by taking the input and multiplying it by 2. This will still generate all even integers, but it will never generate an odd integer: @given(integers().map(lambda n: n * 2))
def test_even(n):
assert n % 2 == 0 The downside to this though is that sometimes it is very complicated to only generate the types of examples you want. So we do use filtering (typically using To take this test itself, test_reshape, as a more concrete example, there are two inputs, the array and the shape. Now @given(arrays(), shapes()) # shapes will generate tuples of positive integers
def test_reshape(a, shape):
assume(prod(a.shape) == prod(shape)) However, this will reject almost all generated examples! Only when the array shape and the generated array-api-tests/array_api_tests/test_manipulation_functions.py Lines 351 to 359 in 393b69b
This works by using (and as an aside, this strategy is itself using |
Absolutely, yes. My confusion is I guess that this (wrong) assumption makes it consistently generate 0 examples. So all examples hypothesis otherwise generated (IOW, generates on main) are 0D? |
It's looking like test_reshape is going to be much harder to fix. I'm going to give it a try at #319 |
Applying
produces
The text was updated successfully, but these errors were encountered: