def test_tuple_conversion_from_tuple_datset(self):
   x = np.random.rand(6, 1)
   y = 2 * x + 3
   tuple_dataset = tf.data.Dataset.from_tensor_slices((x, y))
   converted_dataset = training_utils.convert_to_tuple_dataset(tuple_dataset)
   tuple_batch = next(iter(tuple_dataset))
   converted_batch = next(iter(converted_dataset))
   self.assertAllClose(tuple_batch, converted_batch)
 def test_tuple_conversion_from_ordered_dict(self):
   x = np.random.rand(6, 1)
   y = 2 * x + 3
   tuple_dataset = tf.data.Dataset.from_tensor_slices((x, y))
   ordered_dict_dataset = tf.data.Dataset.from_tensor_slices(
       collections.OrderedDict([('x', x), ('y', y)]))
   converted_dataset = training_utils.convert_to_tuple_dataset(
       ordered_dict_dataset)
   tuple_batch = next(iter(tuple_dataset))
   converted_batch = next(iter(converted_dataset))
   self.assertAllClose(tuple_batch, converted_batch)
  def test_tuple_conversion_from_named_tuple(self):
    x = np.random.rand(6, 1)
    y = 2 * x + 3
    tuple_dataset = tf.data.Dataset.from_tensor_slices((x, y))

    example_tuple = collections.namedtuple('Example', ['x', 'y'])
    named_tuple_dataset = tf.data.Dataset.from_tensor_slices(
        example_tuple(x=x, y=y))
    converted_dataset = training_utils.convert_to_tuple_dataset(
        named_tuple_dataset)
    tuple_batch = next(iter(tuple_dataset))
    converted_batch = next(iter(converted_dataset))
    self.assertAllClose(tuple_batch, converted_batch)