MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / f

Method f

tensorflow/python/kernel_tests/cond_v2_test.py:1075–1094  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

1073
1074 @function.defun
1075 def f():
1076 x = math_ops.range(-5, 5)
1077 output = tensor_array_ops.TensorArray(dtype=dtypes.int32, size=x.shape[0])
1078
1079 def loop_body(i, output):
1080
1081 def if_true():
1082 return output.write(i, x[i]**2)
1083
1084 def if_false():
1085 return output.write(i, x[i])
1086
1087 output = control_flow_ops.cond(x[i] > 0, if_true, if_false)
1088 return i + 1, output
1089
1090 _, output = control_flow_ops.while_loop(
1091 lambda i, arr: i < x.shape[0],
1092 loop_body,
1093 loop_vars=(constant_op.constant(0), output))
1094 return output.stack()
1095
1096 output_t = f()
1097 self.assertAllEqual(output_t, [-5, -4, -3, -2, -1, 0, 1, 4, 9, 16])

Callers

nothing calls this directly

Calls 5

stackMethod · 0.95
TensorArrayMethod · 0.80
rangeMethod · 0.45
while_loopMethod · 0.45
constantMethod · 0.45

Tested by

no test coverage detected