本文整理汇总了Python中testing_helpers.expect函数的典型用法代码示例。如果您正苦于以下问题:Python expect函数的具体用法?Python expect怎么用?Python expect使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了expect函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_set_idx_1d
def test_set_idx_1d():
idx = 10
for vec in vecs:
vec1, vec2 = vec.copy(), vec.copy()
val = -vec[idx]
vec2[idx] = val
expect(set_idx_1d, [vec1, idx, val], vec2)
示例2: test_constants_across_control_flow
def test_constants_across_control_flow():
testing_helpers.expect(const_across_control_flow, [True], 1)
typed_fn = parakeet.typed_repr(const_across_control_flow, [True])
assert len(typed_fn.body) == 1, "Fn body too long: " + str(typed_fn.body)
stmt = typed_fn.body[0]
assert isinstance(stmt, syntax.Return)
assert isinstance(stmt.value, syntax.Const)
示例3: test_always_true
def test_always_true():
testing_helpers.expect(always_true_branch, [], 0)
typed_fn = parakeet.typed_repr(always_true_branch, [])
assert len(typed_fn.body) == 1, "Fn body too long: " + str(typed_fn.body)
stmt = typed_fn.body[0]
assert isinstance(stmt, syntax.Return)
assert isinstance(stmt.value, syntax.Const)
示例4: test_set_idx_2d
def test_set_idx_2d():
i = 2
j = 2
for mat in matrices:
mat1, mat2 = mat.copy(), mat.copy()
val = -mat[i,j]
mat2[i,j] = val
expect(set_idx_2d, [mat1, i, j, val], mat2)
示例5: test_set_idx_3d
def test_set_idx_3d():
i = 2
j = 3
k = 1
for x in tensors:
x1, x2 = x.copy(), x.copy()
val = -x[i, j, k]
x2[i, j, k] = val
expect(set_idx_3d, [x1, i, j, k, val], x2)
示例6: test_assign_slices
def test_assign_slices():
for m in matrices:
m_expect = m.copy()
m_input = m.copy()
(i,j,k,l) = (0,2,0,4)
(a,b,c,d) = (1,3,5,9)
m_expect[i:j, k:l] = m_expect[a:b, c:d]
expect(assign_slices, [m_input, (i,j,k,l), (a,b,c,d)], m_expect)
expect(assign_slices, [m_input, (i,j,k,l), (a,b,c,d)], m_expect)
示例7: test_copy_elimination
def test_copy_elimination():
x = np.array([[1,2,3],[4,5,6]])
expect(nested_add1, [x], x + 1.0)
typed_fn = parakeet.typed_repr(nested_add1, [x])
lowered = lowering.apply(typed_fn)
n_loops = count_loops(lowered)
n_expected = 3 if config.opt_loop_unrolling else 2
assert n_loops <= n_expected, \
"Too many loops generated! Expected at most 2, got %d" % n_loops
示例8: all_tuples
def all_tuples(f, unpack_args = True):
"""
Given a function which should act as the identity, test it on multiple tuples
"""
for t in [ints, mixed, nested2, nested2]:
if unpack_args:
expect(f, t, t)
else:
expect(f, [t], t)
示例9: test_implicit_to_float
def test_implicit_to_float():
expect(implicit_to_float, [1], 1.5)
expect(implicit_to_float, [True], 1.5)
示例10: test_float_sum
def test_float_sum():
testing_helpers.expect(my_sum, [float_vec], np.sum(float_vec))
示例11: test_bool_sum
def test_bool_sum():
testing_helpers.expect(my_sum, [bool_vec], np.sum(bool_vec))
示例12: test_if_true_const
def test_if_true_const():
expect(if_true_const, [], 1)
示例13: test_int_sum
def test_int_sum():
testing_helpers.expect(my_sum, [int_vec], np.sum(int_vec))
示例14: test_assign_first_axis
def test_assign_first_axis():
for m in matrices:
m_expect = m.copy()
m_input = m.copy()
m_expect[1] = m_expect[2]
expect(assign_first_axis, [m_input, 1, 2], m_expect)
示例15: test_varargs_return
def test_varargs_return():
expect(varargs_return, [1,2], (1,2))