Commit 18133649 authored by René Fritze's avatar René Fritze Committed by René Fritze

[tests] adjust hypo data generation to more closely match previous

parent 6585b847
......@@ -8,13 +8,13 @@ import os
from csv import DictWriter
from hypothesis import settings, Verbosity, HealthCheck
settings.register_profile("ci_large", max_examples=5000,
settings.register_profile("ci_large", max_examples=5000,print_blob=True,
suppress_health_check=(HealthCheck.too_slow, HealthCheck.data_too_large,))
settings.register_profile("ci", max_examples=100,verbosity=Verbosity.verbose,
settings.register_profile("ci", max_examples=100,verbosity=Verbosity.verbose,print_blob=True,
suppress_health_check=(HealthCheck.too_slow, HealthCheck.data_too_large,))
settings.register_profile("dev", max_examples=10,
settings.register_profile("dev", max_examples=10,print_blob=True,
suppress_health_check=(HealthCheck.too_slow, HealthCheck.data_too_large,))
settings.register_profile("debug", max_examples=10, verbosity=Verbosity.verbose)
settings.register_profile("debug", max_examples=10, print_blob=True, verbosity=Verbosity.verbose)
settings.load_profile(os.getenv(u'PYMOR_HYPOTHESIS_PROFILE', 'dev'))
class ExecutionTimeCSV:
......
......@@ -39,12 +39,15 @@ def hy_tria_grid(draw):
return RectGrid(**hy_rect_tria_kwargs(draw))
# TODO negative Domain values produce centers outside bounding box
@hyst.composite
def hy_oned_grid(draw):
identify_left_right = draw(hyst.booleans())
interval_i = hyst.integers(min_value=1, max_value=10000)
num_intervals = draw(interval_i.filter(lambda x: (not identify_left_right) or x > 1))
domain_point = hyst.floats(allow_infinity=False, allow_nan=False)
# domain points are limited to allow their norm2 computations
domain_point = hyst.floats(allow_infinity=False, allow_nan=False, min_value=0,
max_value=np.math.sqrt(np.finfo(float).max))
domain = draw(hyst.tuples(domain_point, domain_point).filter(lambda d: d[0] < d[1]))
return OnedGrid(num_intervals=num_intervals, domain=domain, identify_left_right=identify_left_right)
......
......@@ -299,6 +299,30 @@ def valid_inds_of_different_length(v1, v2):
list(np.random.randint(-len(v2), len(v2), size=count2)))
@hyst.composite
def st_valid_inds_of_different_length(draw, v1, v2):
len1, len2 = len(v1), len(v2)
ret = nothing()
# TODO we should include integer arrays here
val = hynp.basic_indices(shape=(len1,), allow_ellipsis=False) # | hynp.integer_array_indices(shape=(len1,))
if len1 != len2:
ret = ret | hyst.just((slice(None), slice(None))) \
| hyst.tuples(hyst.shared(val, key="indfl"), hyst.shared(val, key="indfl"))
if len1 > 0 and len2 > 0:
ret = ret | hyst.tuples(val, val).filter(lambda x: len(x[0])!=len(x[1]))
# values are always tuples
return [d[0] for d in draw(ret)]
@hyst.composite
def vector_arrays_with_valid_inds_of_different_length(draw, count=2):
val = draw(hyst.integers(min_value=1, max_value=MAX_LENGTH))
length = hyst.tuples(*[hyst.just(val) for _ in range(count)])
vectors = draw(vector_arrays(count=count, length=length, compatible=True))
ind = draw(st_valid_inds_of_different_length(*vectors))
return vectors, ind
@hyst.composite
def vector_array_with_ind(draw, ind_length=None, count=1, dtype=None, length=None):
assert count == 1
......@@ -399,4 +423,26 @@ def invalid_ind_pairs(v1, v2):
yield ind1, ind2
for ind2 in valid_inds(v2):
for ind1 in invalid_inds(v1, length=v2.len_ind(ind2)):
yield ind1, ind2
\ No newline at end of file
yield ind1, ind2
def st_invalid_ind_pairs(v1, v2):
# for inds in valid_inds_of_different_length(v1, v2):
# yield inds
# for ind1 in valid_inds(v1):
# for ind2 in invalid_inds(v2, length=v1.len_ind(ind1)):
# yield ind1, ind2
# for ind2 in valid_inds(v2):
# for ind1 in invalid_inds(v1, length=v2.len_ind(ind2)):
# yield ind1, ind2
return hyst.sampled_from(list(valid_inds_of_different_length(v1, v2))) | \
hyst.sampled_from([(i1, i2) for i1 in valid_inds(v1) for i2 in invalid_inds(v2, length=v1.len_ind(i1)) ])
@hyst.composite
def vector_arrays_with_invalid_inds(draw, count=2):
val = draw(hyst.integers(min_value=1, max_value=MAX_LENGTH))
length = hyst.tuples(*[hyst.just(val) for _ in range(count)])
vectors = draw(vector_arrays(count=count, length=length, compatible=True))
ind = draw(st_invalid_ind_pairs(*vectors))
return vectors, ind
\ No newline at end of file
......@@ -577,12 +577,16 @@ def test_pairwise_dot_self(vector_array_inds):
@settings(deadline=None, print_blob=True)
@given(pyst.vector_arrays_with_valid_inds_of_same_length(count=2))
@given(pyst.vector_arrays_with_valid_inds_of_same_length(count=2)
| pyst.vector_arrays_with_valid_inds_of_different_length(count=2))
def test_dot(vectors_indices):
vectors, indices = vectors_indices
v1, v2 = vectors
ind1, ind2 = indices
# for ind1, ind2 in chain(pyst.valid_inds_of_different_length(v1, v2), pyst.valid_inds_of_same_length(v1, v2)):
# TODO
assume_old_slicing(indices)
r = v1[ind1].dot(v2[ind2])
assert isinstance(r, np.ndarray)
assert r.shape == (v1.len_ind(ind1), v2.len_ind(ind2))
......@@ -595,6 +599,17 @@ def test_dot(vectors_indices):
pass
def assume_old_slicing(indices):
# TODO old data input did not have None as X in slices, only slice(None)
for ind in indices:
if ind is slice(None):
continue
if isinstance(ind, slice):
for p in ('step', 'start', 'stop'):
assume(getattr(ind, p) is not None)
@settings(deadline=None)
@given(pyst.vector_arrays_with_ind_pairs_both_lengths())
def test_dot_self(vector_array_inds):
v, (ind1, ind2) = vector_array_inds
......
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