2020-09-24 00:55:24 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2017-12-07 01:11:20 +00:00
|
|
|
|
|
|
|
|
import numpy as np
|
2020-08-08 19:10:52 +00:00
|
|
|
from hypothesis import given, settings
|
2017-12-07 01:11:20 +00:00
|
|
|
import hypothesis.strategies as st
|
|
|
|
|
from caffe2.python import core
|
|
|
|
|
import caffe2.python.hypothesis_test_util as hu
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class TestAssert(hu.HypothesisTestCase):
|
|
|
|
|
@given(
|
|
|
|
|
dtype=st.sampled_from(['bool_', 'int32', 'int64']),
|
|
|
|
|
shape=st.lists(elements=st.integers(1, 10), min_size=1, max_size=4),
|
|
|
|
|
**hu.gcs)
|
2021-05-25 22:53:44 +00:00
|
|
|
@settings(deadline=10000)
|
2017-12-07 01:11:20 +00:00
|
|
|
def test_assert(self, dtype, shape, gc, dc):
|
|
|
|
|
test_tensor = np.random.rand(*shape).astype(np.dtype(dtype))
|
|
|
|
|
|
|
|
|
|
op = core.CreateOperator('Assert', ['X'], [])
|
|
|
|
|
|
|
|
|
|
def assert_ref(X):
|
|
|
|
|
return []
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
self.assertReferenceChecks(gc, op, [test_tensor], assert_ref)
|
|
|
|
|
except Exception:
|
|
|
|
|
assert(not np.all(test_tensor))
|