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

Move float, integer, string, byte, and boolean drawing logic into PrimitiveProvider #3788

Merged
merged 45 commits into from
Nov 19, 2023
Merged
Show file tree
Hide file tree
Changes from 40 commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
941f265
first impleemntation of primitive provider draw_integer
tybug Nov 10, 2023
1bfc303
migrate biased_coin to PrimitiveProvider
tybug Nov 10, 2023
e308f08
remove forced in PrimitiveProvider where unused
tybug Nov 10, 2023
71658a1
remove now-inlined biased_coin
tybug Nov 11, 2023
afd80e0
implement PrimitiveProvider.draw_bytes
tybug Nov 11, 2023
b71a520
remove duplicate draw_bytes definition
tybug Nov 11, 2023
237fd1f
move integer_range and unbounded_integers to ConjetureData
tybug Nov 11, 2023
b0af75e
remove unused forced arguments
tybug Nov 11, 2023
d56d01f
move FloatsStrategy implementation to PrimitiveProvider
tybug Nov 11, 2023
fe9e33b
linting
tybug Nov 11, 2023
1cae2e2
fix SIGNALING_NAN import
tybug Nov 11, 2023
4ff8488
add type annotations to PrimitiveProvider methods
tybug Nov 11, 2023
2433380
move INT_SIZES back to utils
tybug Nov 11, 2023
42b5857
move comment
tybug Nov 12, 2023
a0ba893
move OneCharStringStrategy to PrimitiveProvider.draw_string
tybug Nov 12, 2023
5537e89
linting
tybug Nov 12, 2023
ff973b7
fix accidentally modified test
tybug Nov 13, 2023
f4689f2
Add changelog, fix typo, move test
Zac-HD Nov 16, 2023
1de1035
use data.draw_string in TextStrategy
tybug Nov 15, 2023
09d0c20
move util methods to PrimitiveProvider
tybug Nov 15, 2023
552989c
change chr return type to str
tybug Nov 15, 2023
164376f
add issue link comment
tybug Nov 15, 2023
49a990d
move char rewriting to IntervalSet
tybug Nov 15, 2023
6d464da
linting
tybug Nov 15, 2023
93fefdb
use _calc_p_continue in _array_helper
tybug Nov 15, 2023
ab973c7
Update test_text.py
Zac-HD Nov 16, 2023
7719411
Merge branch 'master' into lowlevel-provider
Zac-HD Nov 15, 2023
84b6a1a
remove trailing period
tybug Nov 17, 2023
3e02efd
move integer bound bias back to IntegerStrategy
tybug Nov 17, 2023
7edbb8b
migrate integer_range to draw_integer
tybug Nov 17, 2023
550eb39
Merge branch 'lowlevel-provider' of https://github.com/tybug/hypothes…
tybug Nov 17, 2023
c521c4d
split assertion
tybug Nov 17, 2023
1f6c69a
add some type annotations
tybug Nov 17, 2023
17bd416
fix float draw/write tests
tybug Nov 17, 2023
230c906
guard max_size in draw_string
tybug Nov 17, 2023
68178d8
add some assertions for mypy
tybug Nov 18, 2023
c6953a2
some more type hint adjustments
tybug Nov 18, 2023
72b12dc
older type union syntax
tybug Nov 18, 2023
690732b
cache float initialization logic
tybug Nov 18, 2023
8f69bb2
remove old upper/lower keywords
tybug Nov 18, 2023
b2fd82b
Delete some dead code
Zac-HD Nov 18, 2023
03f9eb6
Remove draw_bits uses
Zac-HD Nov 18, 2023
71f38a3
More coverage
Zac-HD Nov 19, 2023
ec7d78d
Coverage + shrinking fixes
Zac-HD Nov 19, 2023
f4c221b
final fixes I hope
Zac-HD Nov 19, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 8 additions & 0 deletions hypothesis-python/RELEASE.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
RELEASE_TYPE: patch

This patch refactors some internals. There is no user-visible change,
but we hope to improve performance and unlock support for alternative
backends such as :pypi:`symbolic execution with crosshair <crosshair-tool>`
in future (:issue:`3086`).

Thanks to Liam DeVoe for this fantastic contribution!
9 changes: 5 additions & 4 deletions hypothesis-python/src/hypothesis/extra/_array_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

from hypothesis import assume, strategies as st
from hypothesis.errors import InvalidArgument
from hypothesis.internal.conjecture import utils as cu
from hypothesis.internal.conjecture.utils import _calc_p_continue
from hypothesis.internal.coverage import check_function
from hypothesis.internal.validation import check_type, check_valid_interval
from hypothesis.strategies._internal.utils import defines_strategy
Expand Down Expand Up @@ -562,6 +562,9 @@ def _draw_loop_dimensions(self, data, use=None):
assert len(use) == self.num_shapes
assert all(isinstance(x, bool) for x in use)

_gap = self.max_dims - self.min_dims
p_keep_extending_shape = _calc_p_continue(desired_avg=_gap / 2, max_size=_gap)

for dim_count in range(1, self.max_dims + 1):
dim = dim_count - 1

Expand Down Expand Up @@ -596,9 +599,7 @@ def _draw_loop_dimensions(self, data, use=None):
# shape-tuple even if it is no longer being added to.
# This helps to ensure more stable shrinking behavior.
if self.min_dims < dim_count:
use[shape_id] &= cu.biased_coin(
data, 1 - 1 / (1 + self.max_dims - dim)
)
use[shape_id] &= data.draw_boolean(p_keep_extending_shape)

if use[shape_id]:
shape.append(side)
Expand Down
2 changes: 1 addition & 1 deletion hypothesis-python/src/hypothesis/extra/array_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,7 @@ def do_draw(self, data):
seen = set()

while elements.more():
i = cu.integer_range(data, 0, self.array_size - 1)
i = data.draw_integer(0, self.array_size - 1)
if i in assigned:
elements.reject()
continue
Expand Down
2 changes: 1 addition & 1 deletion hypothesis-python/src/hypothesis/extra/numpy.py
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ def do_draw(self, data):
seen = set()

while elements.more():
i = cu.integer_range(data, 0, self.array_size - 1)
i = data.draw_integer(0, self.array_size - 1)
if not needs_fill[i]:
elements.reject()
continue
Expand Down