MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / test_sum

Method test_sum

tensorflow/python/keras/metrics_test.py:50–75  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

48class KerasSumTest(test.TestCase):
49
50 def test_sum(self):
51 m = metrics.Sum(name='my_sum')
52
53 # check config
54 self.assertEqual(m.name, 'my_sum')
55 self.assertTrue(m.stateful)
56 self.assertEqual(m.dtype, dtypes.float32)
57 self.assertEqual(len(m.variables), 1)
58 self.evaluate(variables.variables_initializer(m.variables))
59
60 # check initial state
61 self.assertEqual(self.evaluate(m.total), 0)
62
63 # check __call__()
64 self.assertEqual(self.evaluate(m(100)), 100)
65 self.assertEqual(self.evaluate(m.total), 100)
66
67 # check update_state() and result() + state accumulation + tensor input
68 update_op = m.update_state(ops.convert_n_to_tensor([1, 5]))
69 self.evaluate(update_op)
70 self.assertAlmostEqual(self.evaluate(m.result()), 106)
71 self.assertEqual(self.evaluate(m.total), 106) # 100 + 1 + 5
72
73 # check reset_states()
74 m.reset_states()
75 self.assertEqual(self.evaluate(m.total), 0)
76
77 def test_sum_with_sample_weight(self):
78 m = metrics.Sum(dtype=dtypes.float64)

Callers

nothing calls this directly

Calls 4

evaluateMethod · 0.45
update_stateMethod · 0.45
resultMethod · 0.45
reset_statesMethod · 0.45

Tested by

no test coverage detected