#NEWLINE# def buffer_batch( generator , buffer_size ) : #NEWLINE# #INDENT# 'Buffer an iterable of batches into larger (or smaller) batches\n\n    Parameters\n    ----------\n    generator : iterable\n        The generator to buffer\n\n    buffer_size : int > 0\n        The number of examples to retain per batch.\n\n    Yields\n    ------\n    batch\n        A batch of size at most `buffer_size`\n    ' #NEWLINE# batches = [ ] #NEWLINE# n = 0 #NEWLINE# for x in generator : #NEWLINE# #INDENT# batches . append ( x ) #NEWLINE# n += batch_length ( x ) #NEWLINE# if ( n < buffer_size ) : #NEWLINE# #INDENT# continue #NEWLINE# #UNINDENT# ( batch , batches ) = __split_batches ( batches , buffer_size ) #NEWLINE# if ( batch is not None ) : #NEWLINE# #INDENT# ( yield batch ) #NEWLINE# batch = None #NEWLINE# n = 0 #NEWLINE# #UNINDENT# #UNINDENT# while batches : #NEWLINE# #INDENT# ( batch , batches ) = __split_batches ( batches , buffer_size ) #NEWLINE# if ( batch is not None ) : #NEWLINE# #INDENT# ( yield batch )