def test_dict_iterator(): d = {'a': 'b', 1: 2} assert list(_iter(d)) == list(iter(d)) assert list(_iter(d.items())) == list(iter(d.items())) assert list(_iter(d.keys())) == list(iter(d.keys())) assert list(_iter(d.values())) == list(iter(d.values())) yield verify_pickle, _iter, iter, 2, 1, d yield verify_pickle, _iter, iter, 2, 1, d.items() yield verify_pickle, _iter, iter, 2, 1, d.values() yield verify_pickle, _iter, iter, 2, 1, d.keys()
def get_request_iterator(self): indices = list(self.indices)[::self.batch_size] self.rng.shuffle(indices) if self.use_slice: return imap(slice, _iter(indices), imap(lambda x: x + self.batch_size, _iter(indices))) else: return imap(range, _iter(indices), imap(lambda x: x + self.batch_size if x != self.indices[-1] - (self.indices[-1] % self.batch_size) else self.indices[-1], _iter(indices)))
def get_request_iterator(self): indices = list(self.indices)[::self.batch_size] self.rng.shuffle(indices) if self.use_slice: return imap(slice, _iter(indices), imap(lambda x: x + self.batch_size, _iter(indices))) else: return imap( range, _iter(indices), imap( lambda x: x + self.batch_size if x != self.indices[-1] - (self.indices[-1] % self.batch_size) else self.indices[-1], _iter(indices)))
def get_request_iterator(self): indices = list(range(self.num_examples)) self.rng.shuffle(indices) return imap( list, imap(islice, repeat(_iter(indices), self.num_batches), repeat(self.batch_size, self.num_batches)))
def test_file_iterator_pickling(): f = _create_test_file() it = _iter(open(f.name)) last = [next(it) for _ in range(2)][-1] first = next(cPickle.loads(cPickle.dumps(it))) assert int(first) == int(last) + 1
def open(self): iterators = [_iter(channel) for channel in self.data_channels] return izip(*iterators)
def tee(iterable, n=2): """tee(iterable, n=2) --> tuple of n independent iterators.""" return tee_manager(_iter(iterable), n=n).iterators()
def __init__(self, iterable, n=2): self._iterable = _iter(iterable) self._tee_iterators = [tee_iterator(self) for i in range(n)]
def get_request_iterator(self): return imap( list, imap(islice, repeat(_iter(xrange(self.num_examples)), self.num_batches), repeat(self.batch_size, self.num_batches)))