def test_errstate_nesting(self): with execution_callbacks.errstate(inf_or_nan=RAISE): with execution_callbacks.errstate(inf_or_nan=IGNORE): self.assertEqual(-float("inf"), log_zero().numpy()) with self.assertRaises(execution_callbacks.InfOrNanError): log_zero()
def test_errstate_nesting(self): with execution_callbacks.errstate(inf_or_nan=RAISE): with execution_callbacks.errstate(inf_or_nan=IGNORE): self.assertEqual(-float("inf"), log_zero().numpy()) with self.assertRaises(execution_callbacks.InfOrNanError): log_zero()
def test_zero_grad_tape(self): with execution_callbacks.errstate(inf_or_nan=RAISE): x = constant_op.constant([-1, 0., 1.]) with backprop.GradientTape() as tape: tape.watch(x) g = tape.gradient(math_ops.pow(x, 2), x) g = self.evaluate(g) self.assertAllClose([-2., 0., 2.], g)
def test_errstate_inf_ignore(self): with execution_callbacks.errstate(inf_or_nan=IGNORE): self.assertEqual(-float("inf"), log_zero().numpy())
def test_errstate_inf_raise(self): with execution_callbacks.errstate(inf_or_nan=RAISE): with self.assertRaises(execution_callbacks.InfOrNanError): log_zero()
def test_errstate_inf_ignore(self): with execution_callbacks.errstate( inf_or_nan=execution_callbacks.IGNORE): self.assertEqual(-float("inf"), log_zero().numpy())
def test_errstate_inf_raise(self): with execution_callbacks.errstate( inf_or_nan=execution_callbacks.RAISE): with self.assertRaises(execution_callbacks.InfOrNanError): log_zero()