Commit 781dfe63 authored by René Fritze's avatar René Fritze Committed by René Fritze

[test] do not reseed in hypothesis controlled indices generators

parent 74454058
Pipeline #61267 passed with stages
in 51 minutes and 52 seconds
......@@ -202,7 +202,7 @@ def given_vector_arrays(which='all', count=1, dtype=None, length=None, compatibl
# TODO match st_valid_inds results to this
def valid_inds(v, length=None):
def valid_inds(v, length=None, random_module=None):
if length is None:
yield []
yield slice(None)
......@@ -221,7 +221,9 @@ def valid_inds(v, length=None):
yield ind
if len(v) == length:
yield slice(None)
np.random.seed(len(v) * length)
# this avoids managing random state "against" hypothesis when this function is used in a strategy
if random_module is None:
np.random.seed(len(v) * length)
yield list(np.random.randint(-len(v), len(v), size=length))
else:
if len(v) == 0:
......@@ -236,7 +238,7 @@ def valid_indices(draw, array_strategy):
# TODO match st_valid_inds_of_same_length results to this
def valid_inds_of_same_length(v1, v2):
def valid_inds_of_same_length(v1, v2, random_module=None):
if len(v1) == len(v2):
yield slice(None), slice(None)
yield list(range(len(v1))), list(range(len(v1)))
......@@ -252,7 +254,9 @@ def valid_inds_of_same_length(v1, v2):
yield -len(v1), -len(v2)
yield [0], 0
yield (list(range(min(len(v1), len(v2))//2)),) * 2
np.random.seed(len(v1) * len(v2))
# this avoids managing random state "against" hypothesis when this function is used in a strategy
if random_module is None:
np.random.seed(len(v1) * len(v2))
for count in np.linspace(0, min(len(v1), len(v2)), 3).astype(int):
yield (list(np.random.randint(-len(v1), len(v1), size=count)),
list(np.random.randint(-len(v2), len(v2), size=count)))
......@@ -275,7 +279,7 @@ def st_valid_inds_of_same_length(draw, v1, v2):
# TODO match st_valid_inds_of_different_length results to this
def valid_inds_of_different_length(v1, v2):
def valid_inds_of_different_length(v1, v2, random_module):
# note this potentially yields no result at all for dual 0 length inputs
if len(v1) != len(v2):
yield slice(None), slice(None)
......@@ -289,7 +293,9 @@ def valid_inds_of_different_length(v1, v2):
if len(v2) > 1:
yield 0, [0, 1]
yield [0], [0, 1]
np.random.seed(len(v1) * len(v2))
# this avoids managing random state "against" hypothesis when this function is used in a strategy
if random_module is None:
np.random.seed(len(v1) * len(v2))
for count1 in np.linspace(0, len(v1), 3).astype(int):
count2 = np.random.randint(0, len(v2))
if count2 == count1:
......@@ -320,10 +326,10 @@ def same_and_different_length(draw, array_strategy):
v = draw(array_strategy)
if isinstance(v, list):
# TODO this should use the st_valid_inds forms directly instead
return v, draw(hyst.one_of(hyst.sampled_from(list(valid_inds_of_same_length(*v))),
hyst.sampled_from(list(valid_inds_of_different_length(*v)))))
return v, draw(hyst.one_of(hyst.sampled_from(list(valid_inds_of_same_length(v, v))),
hyst.sampled_from(list(valid_inds_of_different_length(v, v)))))
return v, draw(hyst.one_of(hyst.sampled_from(list(valid_inds_of_same_length(*v, random_module=False))),
hyst.sampled_from(list(valid_inds_of_different_length(*v, random_module=False)))))
return v, draw(hyst.one_of(hyst.sampled_from(list(valid_inds_of_same_length(v, v, random_module=False))),
hyst.sampled_from(list(valid_inds_of_different_length(v, v, random_module=False)))))
@hyst.composite
......@@ -331,8 +337,8 @@ def pairs_same_length(draw, array_strategy):
v = draw(array_strategy)
if isinstance(v, list):
# TODO this should use the st_valid_inds forms directly instead
return v, draw(hyst.sampled_from(list(valid_inds_of_same_length(*v))))
return v, draw(hyst.sampled_from(list(valid_inds_of_same_length(v, v))))
return v, draw(hyst.sampled_from(list(valid_inds_of_same_length(*v, random_module=False))))
return v, draw(hyst.sampled_from(list(valid_inds_of_same_length(v, v, random_module=False))))
@hyst.composite
......@@ -340,9 +346,9 @@ def pairs_diff_length(draw, array_strategy):
v = draw(array_strategy)
# TODO this should use the st_valid_inds forms directly instead
if isinstance(v, list):
ind_list = list(valid_inds_of_different_length(*v))
ind_list = list(valid_inds_of_different_length(*v, random_module=False))
else:
ind_list = list(valid_inds_of_different_length(v, v))
ind_list = list(valid_inds_of_different_length(v, v, random_module=False))
# the consuming tests do not work for None as index
assume(len(ind_list))
return v, draw(hyst.sampled_from(ind_list))
......
......@@ -235,7 +235,7 @@ def test_getitem_repeated(vectors_and_indices):
v_ind = v[ind]
v_ind_copy = v_ind.copy()
assert not v_ind_copy.is_view
for ind_ind in pyst.valid_inds(v_ind):
for ind_ind in pyst.valid_inds(v_ind, random_module=False):
v_ind_ind = v_ind[ind_ind]
assert np.all(almost_equal(v_ind_ind, v_ind_copy[ind_ind]))
......@@ -291,7 +291,7 @@ def test_copy_repeated_index(vector_array):
def test_append(vector_arrays):
v1, v2 = vector_arrays
len_v1, len_v2 = len(v1), len(v2)
for ind in pyst.valid_inds(v2):
for ind in pyst.valid_inds(v2, random_module=False):
c1, c2 = v1.copy(), v2.copy()
c1.append(c2[ind])
len_ind = v2.len_ind(ind)
......@@ -388,7 +388,7 @@ def test_scla(vectors_and_indices):
def test_axpy(vector_arrays, random):
v1, v2 = vector_arrays
for ind1, ind2 in pyst.valid_inds_of_same_length(v1, v2):
for ind1, ind2 in pyst.valid_inds_of_same_length(v1, v2, random_module=False):
if v1.len_ind(ind1) != v1.len_ind_unique(ind1):
with pytest.raises(Exception):
c1, c2 = v1.copy(), v2.copy()
......@@ -433,7 +433,7 @@ def test_axpy(vector_arrays, random):
@settings(deadline=None, suppress_health_check=(HealthCheck.filter_too_much,HealthCheck.too_slow))
def test_axpy_one_x(vector_arrays, random):
v1, v2 = vector_arrays
for ind1, ind2 in product(pyst.valid_inds(v1), pyst.valid_inds(v2, 1)):
for ind1, ind2 in product(pyst.valid_inds(v1, random_module=False), pyst.valid_inds(v2, 1, random_module=False)):
assert v1.check_ind(ind1)
assert v2.check_ind(ind2)
if v1.len_ind(ind1) != v1.len_ind_unique(ind1):
......@@ -940,7 +940,7 @@ def test_append_incompatible(vector_arrays):
@pyst.given_vector_arrays(count=2, compatible=False)
def test_axpy_incompatible(vector_arrays):
v1, v2 = vector_arrays
for ind1, ind2 in pyst.valid_inds_of_same_length(v1, v2):
for ind1, ind2 in pyst.valid_inds_of_same_length(v1, v2, random_module=False):
c1, c2 = v1.copy(), v2.copy()
with pytest.raises(Exception):
c1[ind1].axpy(0., c2[ind2])
......@@ -958,7 +958,7 @@ def test_axpy_incompatible(vector_arrays):
@pyst.given_vector_arrays(count=2, compatible=False)
def test_dot_incompatible(vector_arrays):
v1, v2 = vector_arrays
for ind1, ind2 in pyst.valid_inds_of_same_length(v1, v2):
for ind1, ind2 in pyst.valid_inds_of_same_length(v1, v2, random_module=False):
c1, c2 = v1.copy(), v2.copy()
with pytest.raises(Exception):
c1[ind1].dot(c2[ind2])
......@@ -967,7 +967,7 @@ def test_dot_incompatible(vector_arrays):
@pyst.given_vector_arrays(count=2, compatible=False)
def test_pairwise_dot_incompatible(vector_arrays):
v1, v2 = vector_arrays
for ind1, ind2 in pyst.valid_inds_of_same_length(v1, v2):
for ind1, ind2 in pyst.valid_inds_of_same_length(v1, v2, random_module=False):
c1, c2 = v1.copy(), v2.copy()
with pytest.raises(Exception):
c1[ind1].pairwise_dot(c2[ind2])
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment