pytorch
25 строк · 797.0 Байт
1
2
3
4
5import numpy as np6from hypothesis import given, settings7import hypothesis.strategies as st8from caffe2.python import core9import caffe2.python.hypothesis_test_util as hu10
11
12class TestAssert(hu.HypothesisTestCase):13@given(14dtype=st.sampled_from(['bool_', 'int32', 'int64']),15shape=st.lists(elements=st.integers(1, 10), min_size=1, max_size=4),16**hu.gcs)17@settings(deadline=10000)18def test_assert(self, dtype, shape, gc, dc):19test_tensor = np.random.rand(*shape).astype(np.dtype(dtype))20
21op = core.CreateOperator('Assert', ['X'], [])22
23def assert_ref(X):24return []25
26try:27self.assertReferenceChecks(gc, op, [test_tensor], assert_ref)28except Exception:29assert(not np.all(test_tensor))30