repo_id stringclasses 409
values | prefix large_stringlengths 34 36.3k | target large_stringlengths 1 498 | assertion_type stringclasses 31
values | difficulty stringclasses 8
values | test_file stringlengths 10 121 | test_function stringlengths 1 104 | test_class stringlengths 0 51 | lineno int32 2 11.3k | commit_idx int32 |
|---|---|---|---|---|---|---|---|---|---|
explosion/thinc | import contextlib
import shutil
import tempfile
from pathlib import Path
import numpy
import pytest
from thinc.api import ArgsKwargs, Linear, Padded, Ragged
from thinc.util import has_cupy, is_cupy_array, is_numpy_array
def make_tempdir():
d = Path(tempfile.mkdtemp())
yield d
shutil.rmtree(str(d))
def g... | y) | assert_* | variable | thinc/tests/util.py | assert_lists_match | 62 | null | |
explosion/thinc | from typing import cast
import numpy
import pytest
from thinc.api import (
Adam,
ArgsKwargs,
Model,
MXNetWrapper,
Ops,
get_current_ops,
mxnet2xp,
xp2mxnet,
)
from thinc.compat import has_cupy_gpu, has_mxnet
from thinc.types import Array1d, Array2d, IntsXd
from thinc.util import to_cate... | answer | assert | variable | thinc/tests/layers/test_mxnet_wrapper.py | test_mxnet_wrapper_train_overfits | 126 | null | |
explosion/thinc | from unittest.mock import MagicMock
import numpy
import pytest
from hypothesis import given, settings
from numpy.testing import assert_allclose
from thinc.api import SGD, Dropout, Linear, chain
from ..strategies import arrays_OI_O_BI
from ..util import get_model, get_shape
def model():
model = Linear()
retu... | None | assert | none_literal | thinc/tests/layers/test_linear.py | test_linear_dimensions_on_data | 34 | null | |
explosion/thinc | import pytest
import srsly
from thinc.api import (
Linear,
Maxout,
Model,
Shim,
chain,
deserialize_attr,
serialize_attr,
with_array,
)
def linear():
return Linear(5, 3)
def test_simple_model_roundtrip_bytes_serializable_attrs():
fwd = lambda model, X, is_train: (X, lambda dY: ... | model.attrs | assert | complex_expr | thinc/tests/test_serialize.py | test_simple_model_roundtrip_bytes_serializable_attrs | 97 | null | |
explosion/thinc | from functools import partial
import numpy
import pytest
from numpy.testing import assert_allclose
from thinc.api import Linear, NumpyOps, Relu, chain
def nB(request):
return request.param
def nI(request):
return request.param
def nH(request):
return request.param
def nO(request):
return request.p... | 2 | assert | numeric_literal | thinc/tests/layers/test_feed_forward.py | test_infer_output_shape | 94 | null | |
explosion/thinc | from unittest.mock import MagicMock
from thinc.api import Linear, with_debug
def test_with_debug():
on_init = MagicMock()
on_forward = MagicMock()
on_backprop = MagicMock()
model = with_debug(
Linear(), on_init=on_init, on_forward=on_forward, on_backprop=on_backprop
)
on_init.assert_no... | True) | assert_* | bool_literal | thinc/tests/layers/test_with_debug.py | test_with_debug | 23 | null | |
explosion/thinc | import numpy
import pytest
from thinc.api import (
Adam,
ArgsKwargs,
Linear,
Model,
TensorFlowWrapper,
get_current_ops,
keras_subclass,
tensorflow2xp,
xp2tensorflow,
)
from thinc.compat import has_cupy_gpu, has_tensorflow
from thinc.util import to_categorical
from ..util import che... | True | assert | bool_literal | thinc/tests/layers/test_tensorflow_wrapper.py | test_tensorflow_wrapper_accumulate_gradients | 159 | null | |
explosion/thinc | import numpy
import pytest
from numpy.testing import assert_allclose
from thinc.types import Pairs, Ragged
def ragged():
data = numpy.zeros((20, 4), dtype="f")
lengths = numpy.array([4, 2, 8, 1, 4], dtype="i")
data[0] = 0
data[1] = 1
data[2] = 2
data[3] = 3
data[4] = 4
data[5] = 5
... | (1, 12) | assert | collection | thinc/tests/test_indexing.py | test_pairs_arrays | 66 | null | |
explosion/thinc | import numpy
import pytest
from numpy.testing import assert_allclose
from thinc.api import (
Dropout,
Linear,
Model,
NumpyOps,
add,
clone,
concatenate,
map_list,
noop,
)
from thinc.layers import chain, tuplify
def nB(request):
return request.param
def nI(request):
return r... | 2 | assert | numeric_literal | thinc/tests/layers/test_combinators.py | test_tuplify_two | 66 | null | |
explosion/thinc | import platform
import pytest
from thinc.api import (
Adam,
PyTorchWrapper,
Relu,
Softmax,
TensorFlowWrapper,
chain,
clone,
get_current_ops,
)
from thinc.compat import has_tensorflow, has_torch
def mnist(limit=5000):
pytest.importorskip("ml_datasets")
import ml_datasets
(... | scores[0] | assert | complex_expr | thinc/tests/layers/test_mnist.py | test_small_end_to_end | 122 | null | |
explosion/thinc | from functools import partial
import numpy
import pytest
from numpy.testing import assert_allclose
from thinc.api import Linear, NumpyOps, Relu, chain
def nB(request):
return request.param
def nI(request):
return request.param
def nH(request):
return request.param
def nO(request):
return request.p... | (nO, nH) | assert | collection | thinc/tests/layers/test_feed_forward.py | test_models_have_shape | 77 | null | |
explosion/thinc | from thinc.api import Linear, chain
def test_issue208():
"""Test issue that was caused by trying to flatten nested chains."""
layer1 = Linear(nO=9, nI=3)
layer2 = Linear(nO=12, nI=9)
layer3 = Linear(nO=5, nI=12)
model = chain(layer1, chain(layer2, layer3)).initialize()
assert model.get_dim("nO... | 5 | assert | numeric_literal | thinc/tests/regression/test_issue208.py | test_issue208 | 10 | null | |
explosion/thinc | import timeit
import numpy
import pytest
from thinc.api import LSTM, NumpyOps, Ops, PyTorchLSTM, fix_random_seed, with_padded
from thinc.compat import has_torch
def nI(request):
return request.param
def nO(request):
return request.param
def test_LSTM_learns():
fix_random_seed(0)
nO = 2
nI = 2
... | loss2 | assert | variable | thinc/tests/layers/test_lstm.py | test_LSTM_learns | 125 | null | |
explosion/thinc | import contextlib
import shutil
import tempfile
from pathlib import Path
import numpy
import pytest
from thinc.api import ArgsKwargs, Linear, Padded, Ragged
from thinc.util import has_cupy, is_cupy_array, is_numpy_array
def make_tempdir():
d = Path(tempfile.mkdtemp())
yield d
shutil.rmtree(str(d))
def g... | kwargs_keys | assert | variable | thinc/tests/util.py | check_input_converters | 97 | null | |
explosion/thinc | import numpy
import pytest
from hypothesis import given
from thinc.api import Padded, Ragged, get_width
from thinc.types import ArgsKwargs
from thinc.util import (
convert_recursive,
get_array_module,
is_cupy_array,
is_numpy_array,
to_categorical,
)
from . import strategies
ALL_XP = [numpy]
@pyt... | xp | assert | variable | thinc/tests/test_util.py | test_array_module_cpu_gpu_helpers | 68 | null | |
explosion/thinc | import timeit
import numpy
import pytest
from thinc.api import LSTM, NumpyOps, Ops, PyTorchLSTM, fix_random_seed, with_padded
from thinc.compat import has_torch
def nI(request):
return request.param
def nO(request):
return request.param
def test_list2padded():
ops = NumpyOps()
seqs = [numpy.zeros((... | 2 | assert | numeric_literal | thinc/tests/layers/test_lstm.py | test_list2padded | 29 | null | |
explosion/thinc | import numpy
import pytest
from thinc.api import reduce_first, reduce_last, reduce_max, reduce_mean, reduce_sum
from thinc.types import Ragged
def Xs():
seqs = [numpy.zeros((10, 8), dtype="f"), numpy.zeros((4, 8), dtype="f")]
for x in seqs:
x[0] = 1
x[1] = 2 # so max != first
x[-1] = ... | Xs[0].dtype | assert | complex_expr | thinc/tests/layers/test_reduce.py | test_reduce_first | 45 | null | |
explosion/thinc | import random
import pytest
from thinc.api import (
Adam,
HashEmbed,
Model,
Relu,
Softmax,
chain,
expand_window,
strings2arrays,
with_array,
)
def ancora():
pytest.importorskip("ml_datasets")
import ml_datasets
return ml_datasets.ud_ancora_pos_tags()
def create_embed... | scores[0] | assert | complex_expr | thinc/tests/layers/test_basic_tagger.py | test_small_end_to_end | 86 | null | |
explosion/thinc | from functools import partial
import numpy
import pytest
from numpy.testing import assert_allclose
from thinc.api import Linear, NumpyOps, Relu, chain
def nB(request):
return request.param
def nI(request):
return request.param
def nH(request):
return request.param
def nO(request):
return request.p... | via_update) | assert_* | variable | thinc/tests/layers/test_feed_forward.py | test_predict_and_begin_update_match | 101 | null | |
explosion/thinc | import inspect
import platform
from typing import Tuple, cast
import numpy
import pytest
from hypothesis import given, settings
from hypothesis.strategies import composite, integers
from numpy.testing import assert_allclose
from packaging.version import Version
from thinc.api import (
LSTM,
CupyOps,
Numpy... | Y) | assert_* | variable | thinc/tests/backends/test_ops.py | test_gemm_computes_correctly | 788 | null | |
explosion/thinc | from typing import List, Optional
import numpy
import pytest
import srsly
from numpy.testing import assert_almost_equal
from thinc.api import Dropout, Model, NumpyOps, registry, with_padded
from thinc.backends import NumpyOps
from thinc.compat import has_torch
from thinc.types import Array2d, Floats2d, FloatsXd, Padd... | type(out_data) | assert | func_call | thinc/tests/layers/test_layers_api.py | assert_data_match | 39 | null | |
explosion/thinc | import math
import numpy
import pytest
from thinc.api import SGD, SparseLinear, SparseLinear_v2, to_categorical
def instances():
lengths = numpy.asarray([5, 4], dtype="int32")
keys = numpy.arange(9, dtype="uint64")
values = numpy.ones(9, dtype="float32")
X = (keys, values, lengths)
y = numpy.asar... | 3 | assert | numeric_literal | thinc/tests/layers/test_sparse_linear.py | test_init | 47 | null | |
explosion/thinc | import math
import numpy
import pytest
from thinc.api import SGD, SparseLinear, SparseLinear_v2, to_categorical
def instances():
lengths = numpy.asarray([5, 4], dtype="int32")
keys = numpy.arange(9, dtype="uint64")
values = numpy.ones(9, dtype="float32")
X = (keys, values, lengths)
y = numpy.asar... | loss1 | assert | variable | thinc/tests/layers/test_sparse_linear.py | test_basic | 34 | null | |
explosion/thinc | import numpy
import pytest
from thinc import registry
from thinc.api import (
CategoricalCrossentropy,
CosineDistance,
L2Distance,
SequenceCategoricalCrossentropy,
)
scores0 = numpy.zeros((3, 3), dtype="f")
labels0 = numpy.asarray([0, 1, 1], dtype="i")
guesses1 = numpy.asarray([[0.1, 0.5, 0.6], [0.4,... | 0 | assert | numeric_literal | thinc/tests/test_loss.py | test_cosine_orthogonal | 262 | null | |
explosion/thinc | import numpy
import pytest
from thinc import registry
from thinc.api import (
CategoricalCrossentropy,
CosineDistance,
L2Distance,
SequenceCategoricalCrossentropy,
)
scores0 = numpy.zeros((3, 3), dtype="f")
labels0 = numpy.asarray([0, 1, 1], dtype="i")
guesses1 = numpy.asarray([[0.1, 0.5, 0.6], [0.4,... | 2) | pytest.approx | numeric_literal | thinc/tests/test_loss.py | test_cosine_orthogonal | 268 | null | |
explosion/thinc | from typing import List
from thinc.api import Model, with_flatten_v2
INPUT = [[1, 2, 3], [4, 5], [], [6, 7, 8]]
INPUT_FLAT = [1, 2, 3, 4, 5, 6, 7, 8]
OUTPUT = [[2, 3, 4], [5, 6], [], [7, 8, 9]]
BACKPROP_OUTPUT = [[3, 4, 5], [6, 7], [], [8, 9, 10]]
def _memoize_input() -> Model[List[int], List[int]]:
return Model... | OUTPUT | assert | variable | thinc/tests/layers/test_with_flatten.py | test_with_flatten | 29 | null | |
explosion/thinc | import numpy
import pytest
from thinc.api import (
SGD,
ArgsKwargs,
CupyOps,
Linear,
MPSOps,
NumpyOps,
PyTorchWrapper,
PyTorchWrapper_v2,
PyTorchWrapper_v3,
Relu,
chain,
get_current_ops,
torch2xp,
use_ops,
xp2torch,
)
from thinc.backends import context_pools
... | context_pools.get() | assert | func_call | thinc/tests/layers/test_pytorch_wrapper.py | test_pytorch_wrapper_thinc_input | 127 | null | |
explosion/thinc | import numpy
import pytest
from hypothesis import given
from thinc.api import Padded, Ragged, get_width
from thinc.types import ArgsKwargs
from thinc.util import (
convert_recursive,
get_array_module,
is_cupy_array,
is_numpy_array,
to_categorical,
)
from . import strategies
ALL_XP = [numpy]
@pyt... | ValueError, match=error) | pytest.raises | complex_expr | thinc/tests/test_util.py | test_array_module_cpu_gpu_helpers | 64 | null | |
explosion/thinc | from functools import partial
import numpy
import pytest
from numpy.testing import assert_allclose
from thinc.api import Linear, NumpyOps, Relu, chain
def nB(request):
return request.param
def nI(request):
return request.param
def nH(request):
return request.param
def nO(request):
return request.p... | ngrad) | assert_* | variable | thinc/tests/layers/test_feed_forward.py | test_gradient | 158 | null | |
explosion/thinc | import platform
import pytest
from thinc.api import (
Adam,
PyTorchWrapper,
Relu,
Softmax,
TensorFlowWrapper,
chain,
clone,
get_current_ops,
)
from thinc.compat import has_tensorflow, has_torch
def mnist(limit=5000):
pytest.importorskip("ml_datasets")
import ml_datasets
(... | losses[0] | assert | complex_expr | thinc/tests/layers/test_mnist.py | test_small_end_to_end | 120 | null | |
explosion/thinc | import contextlib
import shutil
import tempfile
from pathlib import Path
import numpy
import pytest
from thinc.api import ArgsKwargs, Linear, Padded, Ragged
from thinc.util import has_cupy, is_cupy_array, is_numpy_array
def make_tempdir():
d = Path(tempfile.mkdtemp())
yield d
shutil.rmtree(str(d))
def g... | Y.data) | assert_* | complex_expr | thinc/tests/util.py | assert_raggeds_match | 70 | null | |
explosion/thinc | from thinc.layers.gelu import Gelu
from thinc.layers.parametricattention_v2 import (
KEY_TRANSFORM_REF,
ParametricAttention_v2,
)
def test_key_transform_used():
attn = ParametricAttention_v2(key_transform=Gelu())
assert attn.get_ref(KEY_TRANSFORM_REF).name == | "gelu" | assert | string_literal | thinc/tests/layers/test_parametric_attention_v2.py | test_key_transform_used | 10 | null | |
explosion/thinc | import inspect
import platform
from typing import Tuple, cast
import numpy
import pytest
from hypothesis import given, settings
from hypothesis.strategies import composite, integers
from numpy.testing import assert_allclose
from packaging.version import Version
from thinc.api import (
LSTM,
CupyOps,
Numpy... | 2 | assert | numeric_literal | thinc/tests/backends/test_ops.py | test_minibatch | 1,456 | null | |
explosion/thinc | from thinc.api import (
compounding,
constant,
constant_then,
cyclic_triangular,
decaying,
slanted_triangular,
warmup_linear,
)
def test_slanted_triangular_rate():
rates = slanted_triangular(1.0, 20.0, ratio=10)
rate0 = next(rates)
assert rate0 < 1.0
rate1 = next(rates)
... | rate1 | assert | variable | thinc/tests/test_schedules.py | test_slanted_triangular_rate | 40 | null | |
explosion/thinc | import numpy
import pytest
from thinc import registry
from thinc.api import (
CategoricalCrossentropy,
CosineDistance,
L2Distance,
SequenceCategoricalCrossentropy,
)
scores0 = numpy.zeros((3, 3), dtype="f")
labels0 = numpy.asarray([0, 1, 1], dtype="i")
guesses1 = numpy.asarray([[0.1, 0.5, 0.6], [0.4,... | 2 | assert | numeric_literal | thinc/tests/test_loss.py | test_loss_from_config | 330 | null | |
explosion/thinc | from typing import List, Optional
import numpy
import pytest
import srsly
from numpy.testing import assert_almost_equal
from thinc.api import Dropout, Model, NumpyOps, registry, with_padded
from thinc.backends import NumpyOps
from thinc.compat import has_torch
from thinc.types import Array2d, Floats2d, FloatsXd, Padd... | out_data) | assert_* | variable | thinc/tests/layers/test_layers_api.py | test_layers_with_residual | 173 | null | |
explosion/thinc | import numpy
from thinc.backends._param_server import ParamServer
def test_param_server_init():
array = numpy.zeros((5,), dtype="f")
params = {("a", 1): array, ("b", 2): array}
grads = {("a", 1): array, ("c", 3): array}
ps = ParamServer(params, grads)
assert ps.param_keys == | (("a", 1), ("b", 2)) | assert | collection | thinc/tests/backends/test_mem.py | test_param_server_init | 11 | null | |
explosion/thinc | import os
import re
import shutil
import sys
from pathlib import Path
import pytest
mypy = pytest.importorskip("mypy")
GENERATE = False
cases = [
("mypy-plugin.ini", "success_plugin.py", "success-plugin.txt"),
("mypy-plugin.ini", "fail_plugin.py", "fail-plugin.txt"),
("mypy-default.ini", "success_no_plu... | expected_err | assert | variable | thinc/tests/mypy/test_mypy.py | test_mypy_results | 80 | null | |
explosion/thinc | import platform
import threading
import time
from collections import Counter
import numpy
import pytest
from thinc.api import (
Adam,
CupyOps,
Dropout,
Linear,
Model,
Relu,
Shim,
Softmax,
chain,
change_attr_values,
concatenate,
set_dropout_rate,
use_ops,
with_de... | 3 | assert | numeric_literal | thinc/tests/model/test_model.py | test_recursive_double_wrap | 598 | null | |
explosion/thinc | from functools import partial
import numpy
import pytest
from numpy.testing import assert_allclose
from thinc.api import Linear, NumpyOps, Relu, chain
def nB(request):
return request.param
def nI(request):
return request.param
def nH(request):
return request.param
def nO(request):
return request.p... | (nH,) | assert | collection | thinc/tests/layers/test_feed_forward.py | test_models_have_shape | 76 | null | |
explosion/thinc | import contextlib
import shutil
import tempfile
from pathlib import Path
import numpy
import pytest
from thinc.api import ArgsKwargs, Linear, Padded, Ragged
from thinc.util import has_cupy, is_cupy_array, is_numpy_array
def make_tempdir():
d = Path(tempfile.mkdtemp())
yield d
shutil.rmtree(str(d))
def g... | Y.data.shape[1] | assert | complex_expr | thinc/tests/util.py | assert_paddeds_match | 81 | null | |
explosion/thinc | import pytest
from hypothesis import given, settings
from hypothesis.strategies import lists, one_of, tuples
from thinc.api import PyTorchGradScaler
from thinc.compat import has_torch, has_torch_amp, has_torch_cuda_gpu, torch
from thinc.util import is_torch_array
from ..strategies import ndarrays
def tensors():
... | ValueError) | pytest.raises | variable | thinc/tests/shims/test_pytorch_grad_scaler.py | test_grad_scaler | 60 | null | |
explosion/thinc | import pytest
import srsly
from thinc.api import (
Linear,
Maxout,
Model,
Shim,
chain,
deserialize_attr,
serialize_attr,
with_array,
)
def linear():
return Linear(5, 3)
def test_serialize_refs_roundtrip_bytes():
fwd = lambda model, X, is_train: (X, lambda dY: dY)
model_a =... | ("a", "b") | assert | collection | thinc/tests/test_serialize.py | test_serialize_refs_roundtrip_bytes | 154 | null | |
explosion/thinc | import pytest
import srsly
from thinc.api import (
Linear,
Maxout,
Model,
Shim,
chain,
deserialize_attr,
serialize_attr,
with_array,
)
def linear():
return Linear(5, 3)
def test_pickle_with_flatten(linear):
Xs = [linear.ops.alloc2f(2, 3), linear.ops.alloc2f(4, 3)]
model = ... | 2 | assert | numeric_literal | thinc/tests/test_serialize.py | test_pickle_with_flatten | 50 | null | |
explosion/thinc | import numpy
from thinc.api import HashEmbed
def test_seed_changes_bucket():
model1 = HashEmbed(64, 1000, seed=2).initialize()
model2 = HashEmbed(64, 1000, seed=1).initialize()
arr = numpy.ones((1,), dtype="uint64")
vector1 = model1.predict(arr)
vector2 = model2.predict(arr)
assert vector1.su... | vector2.sum() | assert | func_call | thinc/tests/layers/test_hash_embed.py | test_seed_changes_bucket | 19 | null | |
explosion/thinc | from thinc.api import (
compounding,
constant,
constant_then,
cyclic_triangular,
decaying,
slanted_triangular,
warmup_linear,
)
def test_decaying_rate():
rates = decaying(0.001, 1e-4)
rate = next(rates)
assert rate == 0.001
next_rate = next(rates)
assert next_rate < | rate | assert | variable | thinc/tests/test_schedules.py | test_decaying_rate | 17 | null | |
explosion/thinc | from typing import Tuple, cast
import numpy
import pytest
from numpy.testing import assert_allclose
from thinc.api import Model, NumpyOps, Softmax_v2
from thinc.types import Floats2d, Ints1d
from thinc.util import has_torch, torch2xp, xp2torch
OPS = NumpyOps()
inputs = OPS.xp.asarray([[4, 2, 3, 4], [1, 5, 3, 1], [9... | dXt) | assert_* | variable | thinc/tests/layers/test_softmax.py | test_softmax_temperature | 81 | null | |
explosion/thinc | from functools import partial
import numpy
import pytest
from numpy.testing import assert_allclose
from thinc.api import Linear, NumpyOps, Relu, chain
def nB(request):
return request.param
def nI(request):
return request.param
def nH(request):
return request.param
def nO(request):
return request.p... | expected) | assert_* | variable | thinc/tests/layers/test_feed_forward.py | test_predict_and_begin_update_match | 107 | null | |
explosion/thinc | from typing import List
from thinc.shims.shim import Shim
from ..util import make_tempdir
def test_shim_can_roundtrip_with_path():
with make_tempdir() as path:
shim_path = path / "cool_shim.data"
shim = MockShim([1, 2, 3])
shim.to_disk(shim_path)
copy_shim = shim.from_disk(shim_p... | shim.to_bytes() | assert | func_call | thinc/tests/layers/test_shim.py | test_shim_can_roundtrip_with_path | 27 | null | |
explosion/thinc | import numpy
import pytest
from numpy.testing import assert_allclose
from thinc.types import Pairs, Ragged
def ragged():
data = numpy.zeros((20, 4), dtype="f")
lengths = numpy.array([4, 2, 8, 1, 4], dtype="i")
data[0] = 0
data[1] = 1
data[2] = 2
data[3] = 3
data[4] = 4
data[5] = 5
... | ragged.data) | assert_* | complex_expr | thinc/tests/test_indexing.py | test_ragged_empty | 25 | null | |
explosion/thinc | from unittest.mock import MagicMock
import numpy
import pytest
from hypothesis import given, settings
from numpy.testing import assert_allclose
from thinc.api import SGD, Dropout, Linear, chain
from ..strategies import arrays_OI_O_BI
from ..util import get_model, get_shape
def model():
model = Linear()
retu... | 1.0 | assert | numeric_literal | thinc/tests/layers/test_linear.py | test_update | 221 | null | |
explosion/thinc | import timeit
import numpy
import pytest
from thinc.api import LSTM, NumpyOps, Ops, PyTorchLSTM, fix_random_seed, with_padded
from thinc.compat import has_torch
def nI(request):
return request.param
def nO(request):
return request.param
@pytest.mark.parametrize("ops", [Ops(), NumpyOps()])
def test_LSTM_fwd... | numpy.vstack([X]).shape | assert | func_call | thinc/tests/layers/test_lstm.py | test_LSTM_fwd_bwd_shapes_simple | 72 | null | |
explosion/thinc | from typing import cast
import numpy
import pytest
from thinc.api import (
Adam,
ArgsKwargs,
Model,
MXNetWrapper,
Ops,
get_current_ops,
mxnet2xp,
xp2mxnet,
)
from thinc.compat import has_cupy_gpu, has_mxnet
from thinc.types import Array1d, Array2d, IntsXd
from thinc.util import to_cate... | "cool" | assert | string_literal | thinc/tests/layers/test_mxnet_wrapper.py | test_mxnet_wrapper_thinc_set_model_name | 216 | null | |
beartype/plum | import builtins
import inspect
import typing
import pytest
from rich.text import Text
from .util import rich_render
from plum.repr import _repr_mimebundle_from_rich_, _safe_getfile, repr_type
def test_repr_type():
assert rich_render(repr_type(int)).strip() == "int"
assert rich_render(repr_type(A)).strip() =... | "tests.test_repr.A" | assert | string_literal | tests/test_repr.py | test_repr_type | 18 | null | |
beartype/plum | import abc
from numbers import Number
from typing import Union
import numpy as np
import pytest
import plum
from plum import Val
from plum._parametric import is_concrete, is_type
@pytest.mark.parametrize("metaclass", [type, MyType])
def test_parametric(metaclass):
class Base1:
pass
class Base2:
... | a1 | assert | variable | tests/test_parametric.py | test_parametric | 77 | null | |
beartype/plum | import abc
from numbers import Number
from typing import Union
import numpy as np
import pytest
import plum
from plum import Val
from plum._parametric import is_concrete, is_type
def test_parametric_constructor():
@plum.parametric
class A:
def __init__(self, x, *, y=3):
self.x = x
... | 5.0 | assert | numeric_literal | tests/test_parametric.py | test_parametric_constructor | 241 | null | |
beartype/plum | import pytest
import plum
dispatch = plum.Dispatcher()
def test_method_dispatch():
device = Device()
assert device.do() == "doing nothing"
assert device.do(Rat(), Rat()) == "doing a real and a number"
assert device.do(Re(), Re()) == "doing a real and a number"
assert device.do(Num(), Re()) == | "doing two numbers" | assert | string_literal | tests/advanced/test_cases.py | test_method_dispatch | 103 | null | |
beartype/plum | import inspect
import operator
from numbers import Number as Num, Real as Re
from typing import Any, Union
import pytest
from beartype.door import TypeHint
import plum
from plum import Signature as Sig
from plum._util import Missing
def test_instantiation_copy():
s = Sig(
int,
int,
varar... | 1 | assert | numeric_literal | tests/test_signature.py | test_instantiation_copy | 26 | null | |
beartype/plum | import abc
import os
import textwrap
import typing
import pytest
import plum
from plum._function import Function, _convert, _owner_transfer
from plum._method import Method
from plum._resolver import (
AmbiguousLookupError,
NotFoundLookupError,
_change_function_name,
_unwrap_invoked_methods,
)
from plu... | B | assert | variable | tests/test_function.py | test_owner_transfer | 137 | null | |
beartype/plum | from typing import Union
import pytest
from plum import activate_union_aliases, deactivate_union_aliases, set_union_alias
from plum._alias import _ALIASED_UNIONS
def union_aliases():
"""Activate union aliases during the test and remove all aliases after the test
finishes."""
activate_union_aliases()
... | "typing.Union[IntStr]" | assert | string_literal | tests/test_alias.py | test_union_alias | 29 | null | |
beartype/plum | import collections
import math
import operator
from functools import wraps
from typing import Union
import pytest
import plum
def test_invoke(dispatch: plum.Dispatcher):
@dispatch()
def f():
return "fallback"
@dispatch
def f(x: int):
return "int"
@dispatch
def f(x: str):
... | "str" | assert | string_literal | tests/advanced/test_advanced.py | test_invoke | 137 | null | |
beartype/plum | import abc
from numbers import Number
from typing import Union
import numpy as np
import pytest
import plum
from plum import Val
from plum._parametric import is_concrete, is_type
def test_parametric_covariance_test_case(dispatch: plum.Dispatcher):
@plum.parametric
class A:
def __init__(self, x):
... | "A" | assert | string_literal | tests/test_parametric.py | test_parametric_covariance_test_case | 216 | null | |
beartype/plum | from typing import Union
import pytest
import plum
def test_return_type(dispatch: plum.Dispatcher):
@dispatch
def f(x: int | str) -> int:
return x
assert f(1) == 1
assert f.invoke(int)(1) == 1
with pytest.raises( | TypeError) | pytest.raises | variable | tests/advanced/test_return_type.py | test_return_type | 15 | null | |
beartype/plum | from typing import Union
import pytest
from plum import activate_union_aliases, deactivate_union_aliases, set_union_alias
from plum._alias import _ALIASED_UNIONS
def union_aliases():
"""Activate union aliases during the test and remove all aliases after the test
finishes."""
activate_union_aliases()
... | RuntimeError, match=r"already has alias") | pytest.raises | complex_expr | tests/test_alias.py | test_double_registration | 67 | null | |
beartype/plum | import pytest
import plum
import plum._autoreload as ar
def test_autoreload_activate_deactivate():
# We shouldn't be able to deactivate before activation.
with pytest.raises(
RuntimeError,
match=r"(?i)plum autoreload module was never activated",
):
plum.deactivate_autoreload()
... | "IPython.extensions.autoreload" | assert | string_literal | tests/test_autoreload.py | test_autoreload_activate_deactivate | 21 | null | |
beartype/plum | import pytest
import plum
dispatch = plum.Dispatcher()
def test_method_dispatch():
device = Device()
assert device.do() == | "doing nothing" | assert | string_literal | tests/advanced/test_cases.py | test_method_dispatch | 100 | null | |
beartype/plum | import platform
import textwrap
from copy import copy
import plum
from .util import rich_render
from plum._method import Method
from plum._signature import Signature
def test_equality():
m = Method(int, Signature(int), function_name="int", return_type=int)
assert m == Method(int, Signature(int), function_name... | Method(float, Signature(int), function_name="int", return_type=int) | assert | func_call | tests/test_method.py | test_equality | 89 | null | |
beartype/plum | import abc
import os
import textwrap
import typing
import pytest
import plum
from plum._function import Function, _convert, _owner_transfer
from plum._method import Method
from plum._resolver import (
AmbiguousLookupError,
NotFoundLookupError,
_change_function_name,
_unwrap_invoked_methods,
)
from plu... | "C" | assert | string_literal | tests/test_function.py | test_call_mro | 455 | null | |
beartype/plum | import abc
from numbers import Number
from typing import Union
import numpy as np
import pytest
import plum
from plum import Val
from plum._parametric import is_concrete, is_type
@pytest.mark.filterwarnings("ignore::DeprecationWarning")
def test_val():
# Check some cases.
for T, v in [
(Val[3], Val(3... | T | assert | variable | tests/test_parametric.py | test_val | 535 | null | |
beartype/plum | import pytest
import plum
from plum._signature import Signature as Sig
def test_dispatch_class(dispatch: plum.Dispatcher):
class A:
@dispatch
def f(x: int):
pass
class B:
@dispatch(precedence=1)
def g(x: float):
pass
a = "tests.test_dispatcher.test... | {a, b} | assert | collection | tests/test_dispatcher.py | test_dispatch_class | 34 | null | |
beartype/plum | from typing import Union
import pytest
from plum import activate_union_aliases, deactivate_union_aliases, set_union_alias
from plum._alias import _ALIASED_UNIONS
def union_aliases():
"""Activate union aliases during the test and remove all aliases after the test
finishes."""
activate_union_aliases()
... | "typing.Optional[int]" | assert | string_literal | tests/test_alias.py | test_optional | 57 | null | |
beartype/plum | from __future__ import annotations
import math
from typing import Union
import pytest
import plum
dispatch = plum.Dispatcher()
def test_forward_reference():
one = Number(1)
two = Number(2)
three = one + two
assert isinstance(three, Number)
assert three.value == 3
three = one + 2
assert... | plum.NotFoundLookupError) | pytest.raises | complex_expr | tests/advanced/test_future_annotations.py | test_forward_reference | 44 | null | |
beartype/plum | import inspect
import operator
from numbers import Number as Num, Real as Re
from typing import Any, Union
import pytest
from beartype.door import TypeHint
import plum
from plum import Signature as Sig
from plum._util import Missing
def _impl(x, y, *z):
return str(x)
def assert_signature(f, *types, varargs=Mis... | int) | assert_* | variable | tests/test_signature.py | test_signature_from_callable | 425 | null | |
beartype/plum | import typing
import warnings
from numbers import Number
from typing import Union
import pytest
import plum
from plum import add_conversion_method, add_promotion_rule, conversion_method
from plum._promotion import _promotion_rule
def test_convert(convert):
# Test basic conversion.
assert convert(1.0, float)... | 1.0 | assert | numeric_literal | tests/test_promotion.py | test_convert | 27 | null | |
beartype/plum | import pytest
import plum
def test_overload(dispatch: plum.Dispatcher) -> None:
@plum.overload
def f(x: int) -> int:
return x
@plum.overload
def f(x: str) -> str:
return x
@dispatch
def f(x):
pass
assert f(1) == 1
assert f("1") == "1"
with pytest.raises( | plum.NotFoundLookupError) | pytest.raises | complex_expr | tests/test_overload.py | test_overload | 21 | null | |
beartype/plum | import abc
from numbers import Number
from typing import Union
import numpy as np
import pytest
import plum
from plum import Val
from plum._parametric import is_concrete, is_type
def test_parametric_constructor():
@plum.parametric
class A:
def __init__(self, x, *, y=3):
self.x = x
... | 3 | assert | numeric_literal | tests/test_parametric.py | test_parametric_constructor | 243 | null | |
beartype/plum | from __future__ import annotations
import math
from typing import Union
import pytest
import plum
dispatch = plum.Dispatcher()
def test_extension(dispatch: plum.Dispatcher):
@dispatch
def f(x: int):
return "int"
assert f(1) == "int"
with pytest.raises(plum.NotFoundLookupError):
f("... | "str" | assert | string_literal | tests/advanced/test_future_annotations.py | test_extension | 76 | null | |
beartype/plum | import pytest
import plum
dispatch = plum.Dispatcher()
def test_method_dispatch():
device = Device()
assert device.do() == "doing nothing"
assert device.do(Rat(), Rat()) == "doing a real and a number"
assert device.do(Re(), Re()) == "doing a real and a number"
assert device.do(Num(), Re()) == "d... | "doing a device" | assert | string_literal | tests/advanced/test_cases.py | test_method_dispatch | 104 | null | |
beartype/plum | import builtins
import inspect
import typing
import pytest
from rich.text import Text
from .util import rich_render
from plum.repr import _repr_mimebundle_from_rich_, _safe_getfile, repr_type
def test_repr_mimebundle_from_rich():
class A:
def __rich_console__(self, console, options):
yield Te... | {"text/plain"} | assert | collection | tests/test_repr.py | test_repr_mimebundle_from_rich | 29 | null | |
beartype/plum | import sys
import textwrap
import warnings
import pytest
import plum
from plum._method import Method
from plum._resolver import (
MethodRedefinitionWarning,
Resolver,
_document,
_render_function_call,
)
def test_resolve():
class A:
pass
class B1(A):
pass
class B2(A):
... | m_u | assert | variable | tests/test_resolver.py | test_resolve | 224 | null | |
beartype/plum | import typing
import warnings
from numbers import Number
from typing import Union
import pytest
import plum
from plum import add_conversion_method, add_promotion_rule, conversion_method
from plum._promotion import _promotion_rule
def test_convert_resolve_type_hints(convert):
add_conversion_method(int, float, lam... | 2.0 | assert | numeric_literal | tests/test_promotion.py | test_convert_resolve_type_hints | 62 | null | |
beartype/plum | import pytest
import plum
from plum._signature import Signature as Sig
def test_dispatch_function(dispatch: plum.Dispatcher):
@dispatch
def f(x: int):
pass
@dispatch(precedence=1)
def g(x: float):
pass
assert set(dispatch.functions.keys()) == {"f", "g"}
assert dispatch.functi... | Sig(float, precedence=1) | assert | func_call | tests/test_dispatcher.py | test_dispatch_function | 18 | null | |
beartype/plum | from typing import Union
import pytest
import plum
def test_return_type(dispatch: plum.Dispatcher):
@dispatch
def f(x: int | str) -> int:
return x
assert f(1) == | 1 | assert | numeric_literal | tests/advanced/test_return_type.py | test_return_type | 13 | null | |
beartype/plum | import abc
import os
import textwrap
import typing
import pytest
import plum
from plum._function import Function, _convert, _owner_transfer
from plum._method import Method
from plum._resolver import (
AmbiguousLookupError,
NotFoundLookupError,
_change_function_name,
_unwrap_invoked_methods,
)
from plu... | a | assert | variable | tests/test_function.py | test_convert_reference | 25 | null | |
beartype/plum | import sys
import textwrap
import warnings
import pytest
import plum
from plum._method import Method
from plum._resolver import (
MethodRedefinitionWarning,
Resolver,
_document,
_render_function_call,
)
def test_len():
def f(x):
return x
r = Resolver()
assert len(r) == | 0 | assert | numeric_literal | tests/test_resolver.py | test_len | 165 | null | |
beartype/plum | import abc
import sys
import typing
from typing import Literal
import pytest
from plum._type import (
ModuleType,
PromisedType,
ResolvableType,
_is_hint,
is_faithful,
resolve_type_hint,
type_mapping,
)
from plum._util import Callable
skip_if_less_than_py310 = pytest.mark.skipif(
sys.v... | a | assert | variable | tests/test_type.py | test_resolve_type_hint | 193 | null | |
beartype/plum | import pytest
import plum
def test_overload(dispatch: plum.Dispatcher) -> None:
@plum.overload
def f(x: int) -> int:
return x
@plum.overload
def f(x: str) -> str:
return x
@dispatch
def f(x):
pass
assert f(1) == | 1 | assert | numeric_literal | tests/test_overload.py | test_overload | 19 | null | |
beartype/plum | import sys
import textwrap
import warnings
import pytest
import plum
from plum._method import Method
from plum._resolver import (
MethodRedefinitionWarning,
Resolver,
_document,
_render_function_call,
)
def test_register():
r = Resolver()
def f(*xs):
return xs
# Test that faithf... | 3 | assert | numeric_literal | tests/test_resolver.py | test_register | 145 | null | |
beartype/plum | import sys
from typing import Union
import numpy as np
import pytest
from plum._util import (
Comparable,
Missing,
get_class,
get_context,
is_in_class,
wrap_lambda,
)
from plum.repr import repr_short
def f(self):
pass
def test_get_context():
assert get_context(A.f) == "tests.test_uti... | "tests.test_util.test_get_context.<locals>" | assert | string_literal | tests/test_util.py | test_get_context | 94 | null | |
beartype/plum | import plum
from .util import benchmark
def assert_cache_performance(f, f_native):
# Time the performance of a native call.
dur_native = benchmark(f_native, (1,), n=250, burn=10)
def resolve_registrations():
for f in plum.Function._instances:
f._resolve_pending_registrations()
def... | a_native) | assert_* | variable | tests/test_cache.py | test_cache_class | 111 | null | |
beartype/plum | import sys
import textwrap
import warnings
import pytest
import plum
from plum._method import Method
from plum._resolver import (
MethodRedefinitionWarning,
Resolver,
_document,
_render_function_call,
)
def test_render_function_call():
assert _render_function_call("f", (1,)) == "f(1)"
assert... | "f(1, 1)" | assert | string_literal | tests/test_resolver.py | test_render_function_call | 19 | null | |
beartype/plum | import inspect
import operator
from numbers import Number as Num, Real as Re
from typing import Any, Union
import pytest
from beartype.door import TypeHint
import plum
from plum import Signature as Sig
from plum._util import Missing
def _impl(x, y, *z):
return str(x)
def test_compute_distance():
assert Si... | 2 | assert | numeric_literal | tests/test_signature.py | test_compute_distance | 352 | null | |
beartype/plum | import pytest
import plum
from plum._signature import Signature as Sig
def test_bound_function_attributes(dispatch: plum.Dispatcher):
"""Test the attributes on a bound function."""
class A:
@dispatch
def f(self, x: int):
pass
a = A()
# The 'methods' should point to those... | a.f._f.methods | assert | complex_expr | tests/test_dispatcher.py | test_bound_function_attributes | 51 | null | |
beartype/plum | from typing import Union
import pytest
import plum
def test_inheritance_self_return():
a = A2()
assert a.do(a) is | a | assert | variable | tests/advanced/test_return_type.py | test_inheritance_self_return | 59 | null | |
beartype/plum | import abc
import sys
import typing
from typing import Literal
import pytest
from plum._type import (
ModuleType,
PromisedType,
ResolvableType,
_is_hint,
is_faithful,
resolve_type_hint,
type_mapping,
)
from plum._util import Callable
skip_if_less_than_py310 = pytest.mark.skipif(
sys.v... | t | assert | variable | tests/test_type.py | test_resolvabletype | 28 | null | |
beartype/plum | import pytest
import plum
dispatch = plum.Dispatcher()
def test_method_dispatch():
device = Device()
assert device.do() == "doing nothing"
assert device.do(Rat(), Rat()) == | "doing a real and a number" | assert | string_literal | tests/advanced/test_cases.py | test_method_dispatch | 101 | null | |
beartype/plum | import builtins
import inspect
import typing
import pytest
from rich.text import Text
from .util import rich_render
from plum.repr import _repr_mimebundle_from_rich_, _safe_getfile, repr_type
def test_safe_getfile(monkeypatch):
assert _safe_getfile(A) == inspect.getfile(A)
with pytest.raises( | OSError, match="(?i)source code not available") | pytest.raises | func_call | tests/test_repr.py | test_safe_getfile | 35 | null | |
beartype/plum | import plum
from .util import benchmark
def assert_cache_performance(f, f_native):
# Time the performance of a native call.
dur_native = benchmark(f_native, (1,), n=250, burn=10)
def resolve_registrations():
for f in plum.Function._instances:
f._resolve_pending_registrations()
def... | f_native) | assert_* | variable | tests/test_cache.py | test_cache_function | 52 | null | |
beartype/plum | import abc
import sys
import typing
from typing import Literal
import pytest
from plum._type import (
ModuleType,
PromisedType,
ResolvableType,
_is_hint,
is_faithful,
resolve_type_hint,
type_mapping,
)
from plum._util import Callable
skip_if_less_than_py310 = pytest.mark.skipif(
sys.v... | "int" | assert | string_literal | tests/test_type.py | test_resolvabletype | 27 | null | |
beartype/plum | import builtins
import inspect
import typing
import pytest
from rich.text import Text
from .util import rich_render
from plum.repr import _repr_mimebundle_from_rich_, _safe_getfile, repr_type
def test_repr_mimebundle_from_rich():
class A:
def __rich_console__(self, console, options):
yield Te... | {"text/html"} | assert | collection | tests/test_repr.py | test_repr_mimebundle_from_rich | 30 | null |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.