Exemplo n.º 1
0
    def testCounter(self):
        """Test dataset construction using `count`."""
        dataset = counter.Counter(start=3, step=4)
        self.assertEqual([], dataset.output_shapes.as_list())
        self.assertEqual(dtypes.int64, dataset.output_types)
        get_next = self.getNext(dataset)

        negative_dataset = counter.Counter(start=0, step=-1)
        negative_get_next = self.getNext(negative_dataset)

        self.assertEqual(3, self.evaluate(get_next()))
        self.assertEqual(3 + 4, self.evaluate(get_next()))
        self.assertEqual(3 + 2 * 4, self.evaluate(get_next()))

        self.assertEqual(0, self.evaluate(negative_get_next()))
        self.assertEqual(-1, self.evaluate(negative_get_next()))
        self.assertEqual(-2, self.evaluate(negative_get_next()))
Exemplo n.º 2
0
 def testCounter(self, start, step, expected_output):
   """Test dataset construction using `count`."""
   dataset = counter.Counter(start, step)
   self.assertEqual(
       [], dataset_ops.get_legacy_output_shapes(dataset).as_list())
   self.assertEqual(dtypes.int64, dataset_ops.get_legacy_output_types(dataset))
   get_next = self.getNext(dataset)
   for expected in expected_output:
     self.assertEqual(expected, self.evaluate(get_next()))
Exemplo n.º 3
0
    def testCounter(self):
        """Test dataset construction using `count`."""
        iterator = (counter.Counter(start=3, step=4).make_one_shot_iterator())
        get_next = iterator.get_next()
        self.assertEqual([], get_next.shape.as_list())
        self.assertEqual(dtypes.int64, get_next.dtype)

        negative_iterator = (counter.Counter(start=0,
                                             step=-1).make_one_shot_iterator())
        negative_get_next = negative_iterator.get_next()

        with self.cached_session() as sess:
            self.assertEqual(3, self.evaluate(get_next))
            self.assertEqual(3 + 4, self.evaluate(get_next))
            self.assertEqual(3 + 2 * 4, self.evaluate(get_next))

            self.assertEqual(0, self.evaluate(negative_get_next))
            self.assertEqual(-1, self.evaluate(negative_get_next))
            self.assertEqual(-2, self.evaluate(negative_get_next))
Exemplo n.º 4
0
def Counter(start=0, step=1, dtype=dtypes.int64):
  """Creates a `Dataset` that counts from `start` in steps of size `step`.

  For example:

  ```python
  Dataset.count() == [0, 1, 2, ...)
  Dataset.count(2) == [2, 3, ...)
  Dataset.count(2, 5) == [2, 7, 12, ...)
  Dataset.count(0, -1) == [0, -1, -2, ...)
  Dataset.count(10, -1) == [10, 9, ...)
  ```

  Args:
    start: (Optional.) The starting value for the counter. Defaults to 0.
    step: (Optional.) The step size for the counter. Defaults to 1.
    dtype: (Optional.) The data type for counter elements. Defaults to
      `tf.int64`.

  Returns:
    A `Dataset` of scalar `dtype` elements.
  """
  return counter.Counter(start, step, dtype)