()
| 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]) |
nothing calls this directly
no test coverage detected