sizes = itertools.repeat(size) if isinstance(size, int) else size
is_list = isinstance(sequence, list)
if isinstance(sequence, list): // need condition here for type checking
sequence = Objects(sequence)
indices = numpy.arange(len(sequence))
if shuffle:
numpy.random.shuffle(indices)
i = 0
queue = []
while i < indices.shape[0]: // type: ignore
batch_size = next(sizes)
idx_batch = indices[i : i + batch_size]
subseq = sequence[idx_batch]
if is_xp_array(subseq):
subseq = self.as_contig(cast(Array, subseq))
if is_list and isinstance(subseq, Objects):
subseq = subseq.data
queue.append(subseq)
i += batch_size
return queue