#NEWLINE# def minibatch_map( fn , batch_size , input_data , output_data = None , output_width = None ) : #NEWLINE# #INDENT# '\n    Apply a function on input_data, one minibatch at a time.\n\n    Storage for the output can be provided. If it is the case,\n    it should have appropriate size.\n\n    If output_data is not provided, then output_width should be specified.\n\n    Parameters\n    ----------\n    fn : WRITEME\n    batch_size : WRITEME\n    input_data : WRITEME\n    output_data : WRITEME\n    output_width : WRITEME\n\n    Returns\n    -------\n    WRITEME\n    ' #NEWLINE# if ( output_width is None ) : #NEWLINE# #INDENT# if ( output_data is None ) : #NEWLINE# #INDENT# raise ValueError ( 'output_data or output_width should be provided' ) #NEWLINE# #UNINDENT# output_width = output_data . shape [ 1 ] #NEWLINE# #UNINDENT# output_length = input_data . shape [ 0 ] #NEWLINE# if ( output_data is None ) : #NEWLINE# #INDENT# output_data = numpy . empty ( ( output_length , output_width ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# assert ( output_data . shape [ 0 ] == input_data . shape [ 0 ] ) , ( 'output_data should have the same length as input_data' , output_data . shape [ 0 ] , input_data . shape [ 0 ] ) #NEWLINE# #UNINDENT# for i in xrange ( 0 , output_length , batch_size ) : #NEWLINE# #INDENT# output_data [ i : ( i + batch_size ) ] = fn ( input_data [ i : ( i + batch_size ) ] ) #NEWLINE# #UNINDENT# return output_data