示例#1
0
 def test_append_to_list_structure_with_too_many_unnamed_elements(self):
     type_spec = computation_types.to_type([tf.int32, tf.int32])
     structure = tuple([[], []])
     value = [10, 20, 30]
     with self.assertRaises(TypeError):
         graph_utils.append_to_list_structure_for_element_type_spec(
             structure, value, type_spec)
示例#2
0
 def test_append_to_list_structure_with_too_many_element_keys(self):
   type_spec = computation_types.to_type([('a', tf.int32), ('b', tf.int32)])
   structure = collections.OrderedDict([('a', []), ('b', [])])
   value = {'a': 10, 'b': 20, 'c': 30}
   with self.assertRaises(TypeError):
     graph_utils.append_to_list_structure_for_element_type_spec(
         structure, value, type_spec)
示例#3
0
 def test_append_to_list_structure_for_element_type_spec_w_tuple_dict(self):
   type_spec = computation_types.to_type(
       [tf.int32, [('a', tf.bool), ('b', tf.float32)]])
   structure = tuple([[], collections.OrderedDict([('a', []), ('b', [])])])
   for value in [[10, {'a': 20, 'b': 30}], (40, [50, 60])]:
     graph_utils.append_to_list_structure_for_element_type_spec(
         structure, value, type_spec)
   self.assertEqual(
       str(structure),
       '([10, 40], OrderedDict([(\'a\', [20, 50]), (\'b\', [30, 60])]))')
示例#4
0
 def _test_list_structure(self, type_spec, elements, expected_output_str):
   structure = graph_utils.make_empty_list_structure_for_element_type_spec(
       type_spec)
   for element_value in elements:
     graph_utils.append_to_list_structure_for_element_type_spec(
         structure, element_value, type_spec)
   structure = (
       graph_utils.to_tensor_slices_from_list_structure_for_element_type_spec(
           structure, type_spec))
   self.assertEqual(
       str(structure).replace(' ', ''), expected_output_str.replace(' ', ''))