Example #1
0
 def testFlatCallFlatZip(self):
     before = NS(v=2, w=NS(x=1, y=NS(z=0)))
     after = NS.FlatCall(lambda xs: [2 * x for x in xs], before)
     self.assertEqual(NS(v=4, w=NS(x=2, y=NS(z=0))), after)
     self.assertItemsEqual([(2, 4), (1, 2), (0, 0)],
                           list(NS.FlatZip([before, after])))
     after.w.y.a = 6
     self.assertRaises(ValueError, lambda: NS.FlatZip([before, after]))
     self.assertItemsEqual([(2, 4), (0, 0)],
                           list(NS.FlatZip([before, after], "v w.y.z")))
Example #2
0
    def feed_dict(self, state):
        """Construct a feed dict for the model's states.

    Args:
      state: the model state.

    Returns:
      A feed dict mapping each of the model's placeholders to the corresponding
      numerical value in `state`.
    """
        return util.odict(NS.FlatZip([self.state_placeholders(), state]))