Example #1
0
 def testControlFlowWhile(self):
     predicate = array_ops.placeholder(dtypes.bool, shape=[])
     _ = control_flow_ops.while_loop(lambda _: predicate,
                                     lambda _: constant_op.constant([37.]),
                                     [constant_op.constant([42.])])
     with self.assertRaisesRegexp(
             ValueError,
             r"`tf\.add_check_numerics_ops\(\) is not compatible with "
             r"TensorFlow control flow operations such as `tf\.cond\(\)` "
             r"or `tf.while_loop\(\)`\."):
         numerics.add_check_numerics_ops()
 def testControlFlowWhile(self):
   predicate = array_ops.placeholder(dtypes.bool, shape=[])
   _ = control_flow_ops.while_loop(lambda _: predicate,
                                   lambda _: constant_op.constant([37.]),
                                   [constant_op.constant([42.])])
   with self.assertRaisesRegexp(
       ValueError,
       r"`tf\.add_check_numerics_ops\(\) is not compatible with "
       r"TensorFlow control flow operations such as `tf\.cond\(\)` "
       r"or `tf.while_loop\(\)`\."):
     numerics.add_check_numerics_ops()
 def _testClipByNorm(self, inputs, max_norm, expected):
   with self.test_session() as sess:
     input_op = constant_op.constant(inputs)
     clipped = clip_ops.clip_by_norm(input_op, max_norm)
     check_op = numerics.add_check_numerics_ops()
     result, _ = sess.run([clipped, check_op])
   self.assertAllClose(result, expected)
Example #4
0
 def _testClipByNorm(self, inputs, max_norm, expected):
     with self.cached_session() as sess:
         input_op = constant_op.constant(inputs)
         clipped = clip_ops.clip_by_norm(input_op, max_norm)
         check_op = numerics.add_check_numerics_ops()
         result, _ = sess.run([clipped, check_op])
     self.assertAllClose(result, expected)
Example #5
0
 def testBoth(self):
     with self.session(graph=ops.Graph()):
         t1 = constant_op.constant([1.0, 0.0])
         t2 = constant_op.constant([0.0, 0.0])
         a = math_ops.div(t1, t2)
         check = numerics.add_check_numerics_ops()
         a = control_flow_ops.with_dependencies([check], a)
         with self.assertRaisesOpError("Inf and NaN"):
             self.evaluate(a)
 def testBoth(self):
   with self.session(graph=ops.Graph()):
     t1 = constant_op.constant([1.0, 0.0])
     t2 = constant_op.constant([0.0, 0.0])
     a = math_ops.div(t1, t2)
     check = numerics.add_check_numerics_ops()
     a = control_flow_ops.with_dependencies([check], a)
     with self.assertRaisesOpError("Inf and NaN"):
       self.evaluate(a)
Example #7
0
 def testNaN(self):
     with self.session(graph=ops.Graph()):
         t1 = constant_op.constant(0.0)
         t2 = constant_op.constant(0.0)
         a = math_ops.div(t1, t2)
         check = numerics.add_check_numerics_ops()
         a = control_flow_ops.with_dependencies([check], a)
         with self.assertRaisesOpError("NaN"):
             a.eval()
 def testNaN(self):
   with self.session(graph=ops.Graph()):
     t1 = constant_op.constant(0.0)
     t2 = constant_op.constant(0.0)
     a = math_ops.div(t1, t2)
     check = numerics.add_check_numerics_ops()
     a = control_flow_ops.with_dependencies([check], a)
     with self.assertRaisesOpError("NaN"):
       a.eval()
Example #9
0
 def testAddCheckNumericsOpsRaisesError(self):
   with self.assertRaisesRegexp(
       RuntimeError,
       r'add_check_numerics_ops\(\) is not compatible with eager execution'):
     numerics.add_check_numerics_ops()
Example #10
0
 def testAddCheckNumericsOpsRaisesError(self):
     with self.assertRaisesRegexp(
             RuntimeError,
             r'add_check_numerics_ops\(\) is not compatible with eager execution'
     ):
         numerics.add_check_numerics_ops()
Example #11
0
 def _testClipTensorByNorm(self, inputs, max_norm, expected):
     input_op = constant_op.constant(inputs)
     clipped = clip_ops.clip_by_norm(input_op, max_norm)
     check_op = numerics.add_check_numerics_ops()
     result, _ = self.evaluate([clipped, check_op])
     self.assertAllClose(result, expected)