#NEWLINE# def unroll_scan( fn , sequences , outputs_info , non_sequences , n_steps , go_backwards = False ) : #NEWLINE# #INDENT# '\n        Helper function to unroll for loops. Can be used to unroll theano.scan.\n        The parameter names are identical to theano.scan, please refer to here\n        for more information.\n\n        Note that this function does not support the truncate_gradient\n        setting from theano.scan.\n\n        Parameters\n        ----------\n\n        fn : function\n            Function that defines calculations at each step.\n\n        sequences : TensorVariable or list of TensorVariables\n            List of TensorVariable with sequence data. The function iterates\n            over the first dimension of each TensorVariable.\n\n        outputs_info : list of TensorVariables\n            List of tensors specifying the initial values for each recurrent\n            value.\n\n        non_sequences: list of TensorVariables\n            List of theano.shared variables that are used in the step function.\n\n        n_steps: int\n            Number of steps to unroll.\n\n        go_backwards: bool\n            If true the recursion starts at sequences[-1] and iterates\n            backwards.\n\n        Returns\n        -------\n        List of TensorVariables. Each element in the list gives the recurrent\n        values at each time step.\n\n        ' #NEWLINE# if ( not isinstance ( sequences , ( list , tuple ) ) ) : #NEWLINE# #INDENT# sequences = [ sequences ] #NEWLINE# #UNINDENT# counter = range ( n_steps ) #NEWLINE# if go_backwards : #NEWLINE# #INDENT# counter = counter [ : : ( - 1 ) ] #NEWLINE# #UNINDENT# output = [ ] #NEWLINE# prev_vals = outputs_info #NEWLINE# for i in counter : #NEWLINE# #INDENT# step_input = ( ( [ s [ i ] for s in sequences ] + prev_vals ) + non_sequences ) #NEWLINE# out_ = fn ( * step_input ) #NEWLINE# if isinstance ( out_ , T . TensorVariable ) : #NEWLINE# #INDENT# out_ = [ out_ ] #NEWLINE# #UNINDENT# if isinstance ( out_ , tuple ) : #NEWLINE# #INDENT# out_ = list ( out_ ) #NEWLINE# #UNINDENT# output . append ( out_ ) #NEWLINE# prev_vals = output [ ( - 1 ) ] #NEWLINE# #UNINDENT# output_scan = [ ] #NEWLINE# for i in range ( len ( output [ 0 ] ) ) : #NEWLINE# #INDENT# l = map ( ( lambda x : x [ i ] ) , sequences ) #NEWLINE# output_scan . append ( T . stack ( * l ) ) #NEWLINE# #UNINDENT# return output_scan