(self)
| 132 | self.assertAllClose(result, [10, 7], rtol=1e-3) |
| 133 | |
| 134 | def _testMaxItersSimple(self): |
| 135 | if is_compile_on_demand(): |
| 136 | self.skipTest("list_ops are not supported in cpu_ondemand") |
| 137 | with self.session() as sess, self.test_scope(): |
| 138 | xla_context = control_flow_ops.XLAControlFlowContext() |
| 139 | xla_context.Enter() |
| 140 | v = constant_op.constant(1.0) |
| 141 | p = array_ops.placeholder(dtype=dtypes.int32) |
| 142 | |
| 143 | def create_while_loop(): |
| 144 | iterations = array_ops.size(p, name="iterations") |
| 145 | r = control_flow_ops.while_loop( |
| 146 | lambda *_: True, |
| 147 | lambda i, x: (i + 1, v * x), (0, 1.0), |
| 148 | maximum_iterations=iterations, |
| 149 | name="outer") |
| 150 | return array_ops.identity(r[1]) |
| 151 | |
| 152 | output = create_while_loop() |
| 153 | output = gradients_impl.gradients(output, v)[0] |
| 154 | |
| 155 | result = sess.run(output, feed_dict={p: [0, 0, 0]}) |
| 156 | print(result) |
| 157 | xla_context.Exit() |
| 158 | |
| 159 | def testMaxItersSimple(self): |
| 160 | self.skipTest("Fails with v1 control flow") |
no test coverage detected