예제 #1
0
 def test_xbatch(self):
     self.assertSequenceEqual(
         list(utils.xbatch(2, range(10))),
         [range(0, 2),
          range(2, 4),
          range(4, 6),
          range(6, 8),
          range(8, 10)])
     self.assertSequenceEqual(
         list(
             utils.xbatch(3, [
                 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug',
                 'Sep', 'Oct', 'Nov', 'Dec'
             ])), [['Jan', 'Feb', 'Mar'], ['Apr', 'May', 'Jun'],
                   ['Jul', 'Aug', 'Sep'], ['Oct', 'Nov', 'Dec']])
     self.assertSequenceEqual(
         list(
             utils.xbatch(3, ('Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun',
                              'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'))),
         [('Jan', 'Feb', 'Mar'), ('Apr', 'May', 'Jun'),
          ('Jul', 'Aug', 'Sep'), ('Oct', 'Nov', 'Dec')])
     npt.assert_almost_equal(list(utils.xbatch(2, np.array(range(10)))), [
         np.array([0, 1]),
         np.array([2, 3]),
         np.array([4, 5]),
         np.array([6, 7]),
         np.array([8, 9])
     ])
     self.assertSequenceEqual(
         list(utils.xbatch(2, range(10))),
         [range(0, 2),
          range(2, 4),
          range(4, 6),
          range(6, 8),
          range(8, 10)])
예제 #2
0
    def test_peek(self):
        it = utils.xbatch(2, range(10))
        first_three, new_it = utils.peek(it, 3)
        self.assertSequenceEqual(
            first_three,
            [range(0, 2), range(2, 4), range(4, 6)])
        self.assertSequenceEqual(
            list(new_it),
            [range(0, 2),
             range(2, 4),
             range(4, 6),
             range(6, 8),
             range(8, 10)])
        self.assertSequenceEqual(list(it), [])

        it = utils.xbatch(2, range(10))
        first_three, new_it = utils.peek(it, 3)
        self.assertSequenceEqual(
            first_three,
            [range(0, 2), range(2, 4), range(4, 6)])
        self.assertSequenceEqual(list(it), [range(6, 8), range(8, 10)])