Exemple #1
0
 def test_doesnt_raise_when_zero_and_negative(self):
     with self.test_session():
         tom = constant_op.constant([0, -2], name="tom")
         with ops.control_dependencies([check_ops.assert_non_positive(tom)
                                        ]):
             out = array_ops.identity(tom)
         out.eval()
 def test_raises_when_positive(self):
   with self.test_session():
     rachel = constant_op.constant([0, 2], name="rachel")
     with ops.control_dependencies([check_ops.assert_non_positive(rachel)]):
       out = array_ops.identity(rachel)
     with self.assertRaisesOpError("rachel"):
       out.eval()
 def _assert_valid_sample(self, x):
     if not self.validate_args: return x
     return control_flow_ops.with_dependencies([
         check_ops.assert_non_positive(x),
         distribution_util.assert_close(
             array_ops.zeros((), dtype=self.dtype),
             math_ops.reduce_logsumexp(x, reduction_indices=[-1])),
     ], x)
 def _assert_valid_sample(self, x):
   if not self.validate_args: return x
   return control_flow_ops.with_dependencies([
       check_ops.assert_non_positive(x),
       distribution_util.assert_close(
           array_ops.zeros((), dtype=self.dtype),
           math_ops.reduce_logsumexp(x, reduction_indices=[-1])),
   ], x)
Exemple #5
0
 def _assert_valid_sample(self, x):
     if not self.validate_args:
         return x
     return control_flow_ops.with_dependencies([
         check_ops.assert_non_positive(x),
         check_ops.assert_near(array_ops.zeros([], dtype=self.dtype),
                               math_ops.reduce_logsumexp(x, axis=[-1])),
     ], x)
 def _assert_valid_sample(self, x):
   if not self.validate_args:
     return x
   return control_flow_ops.with_dependencies([
       check_ops.assert_non_positive(x),
       check_ops.assert_near(
           array_ops.zeros([], dtype=self.dtype),
           math_ops.reduce_logsumexp(x, axis=[-1])),
   ], x)
 def test_empty_tensor_doesnt_raise(self):
   # A tensor is non-positive when it satisfies:
   #   For every element x_i in x, x_i <= 0
   # and an empty tensor has no elements, so this is trivially satisfied.
   # This is standard set theory.
   empty = constant_op.constant([], name="empty")
   with ops.control_dependencies([check_ops.assert_non_positive(empty)]):
     out = array_ops.identity(empty)
   self.evaluate(out)
 def test_empty_tensor_doesnt_raise(self):
   # A tensor is non-positive when it satisfies:
   #   For every element x_i in x, x_i <= 0
   # and an empty tensor has no elements, so this is trivially satisfied.
   # This is standard set theory.
   with self.test_session():
     empty = constant_op.constant([], name="empty")
     with ops.control_dependencies([check_ops.assert_non_positive(empty)]):
       out = array_ops.identity(empty)
     out.eval()
 def test_doesnt_raise_when_zero_and_negative(self):
   with self.test_session():
     tom = constant_op.constant([0, -2], name="tom")
     with ops.control_dependencies([check_ops.assert_non_positive(tom)]):
       out = array_ops.identity(tom)
     out.eval()
 def test_raises_when_positive(self):
   rachel = constant_op.constant([0, 2], name="rachel")
   with self.assertRaisesOpError("x <= 0 did not hold"):
     with ops.control_dependencies([check_ops.assert_non_positive(rachel)]):
       out = array_ops.identity(rachel)
     self.evaluate(out)