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

Extend tests to include newly-added data types #759

Draft
wants to merge 7 commits into
base: main
Choose a base branch
from
Draft
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
8 changes: 4 additions & 4 deletions thinc/tests/backends/test_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -787,11 +787,11 @@ def test_gemm_out_used(cpu_ops):


@pytest.mark.parametrize("cpu_ops", CPU_OPS)
@settings(max_examples=MAX_EXAMPLES, deadline=None)
@given(X=strategies.arrays_BI())
def test_flatten_unflatten_roundtrip(cpu_ops, X):
@settings(max_examples=MAX_EXAMPLES * 2, deadline=None)
@given(X=strategies.arrays_BI(dtype="i") | strategies.arrays_BI(dtype="f"))
def test_flatten_unflatten_roundtrip(cpu_ops: NumpyOps, X: numpy.ndarray):
flat = cpu_ops.flatten([x for x in X])
assert flat.ndim == 1
assert flat.ndim == X.ndim - 1
unflat = cpu_ops.unflatten(flat, [len(x) for x in X])
assert_allclose(X, unflat)
flat2 = cpu_ops.flatten([x for x in X], pad=1, dtype="f")
Expand Down
13 changes: 7 additions & 6 deletions thinc/tests/strategies.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from hypothesis.strategies import floats, integers, just, tuples

from thinc.api import Linear, NumpyOps
from thinc.types import DTypes


def get_ops():
Expand Down Expand Up @@ -34,8 +35,8 @@ def shapes(min_rows=1, max_rows=100, min_cols=1, max_cols=100):
return tuples(lengths(lo=min_rows, hi=max_rows), lengths(lo=min_cols, hi=max_cols))


def ndarrays_of_shape(shape, lo=-10.0, hi=10.0, dtype="float32", width=32):
if dtype.startswith("float"):
def ndarrays_of_shape(shape, lo=-10.0, hi=10.0, dtype: DTypes = "float32", width=32):
if dtype.startswith("f"):
return arrays(
dtype, shape=shape, elements=floats(min_value=lo, max_value=hi, width=width)
)
Expand All @@ -49,18 +50,18 @@ def ndarrays(min_len=0, max_len=10, min_val=-10.0, max_val=10.0):
)


def arrays_BI(min_B=1, max_B=10, min_I=1, max_I=100):
def arrays_BI(min_B=1, max_B=10, min_I=1, max_I=100, dtype: DTypes = "float32"):
shapes = tuples(lengths(lo=min_B, hi=max_B), lengths(lo=min_I, hi=max_I))
return shapes.flatmap(ndarrays_of_shape)
return shapes.flatmap(lambda shape: ndarrays_of_shape(shape, dtype=dtype))


def arrays_BOP(min_B=1, max_B=10, min_O=1, max_O=100, min_P=1, max_P=5):
def arrays_BOP(min_B=1, max_B=10, min_O=1, max_O=100, min_P=1, max_P=5, dtype: DTypes = "float32"):
shapes = tuples(
lengths(lo=min_B, hi=max_B),
lengths(lo=min_O, hi=max_O),
lengths(lo=min_P, hi=max_P),
)
return shapes.flatmap(ndarrays_of_shape)
return shapes.flatmap(lambda shape: ndarrays_of_shape(shape, dtype=dtype))


def arrays_BOP_BO(min_B=1, max_B=10, min_O=1, max_O=100, min_P=1, max_P=5):
Expand Down
Loading