def unroll_scan(fn, sequences, outputs_info, non_sequences, n_steps, go_backwards=False):
 if (not isinstance(sequences, (list, tuple))):
  sequences = [sequences]
 counter = range(n_steps)
 if go_backwards:
  counter = counter[::(-1)]
 output = []
 prev_vals = outputs_info
 for i in counter:
  step_input = (([s[i] for s in sequences] + prev_vals) + non_sequences)
  out_ = fn(*step_input)
  if isinstance(out_, T.TensorVariable):
   out_ = [out_]
  if isinstance(out_, tuple):
   out_ = list(out_)
  output.append(out_)
  prev_vals = output[(-1)]
 output_scan = []
 for i in range(len(output[0])):
  l = map((lambda x: x[i]), output)
  output_scan.append(T.stack(*l))
 return output_scan

def unroll_scan ( fn , sequences , outputs_info , non_sequences , n_steps , go_backwards = False ) : if ( not isinstance ( sequences , ( list , tuple ) ) ) : sequences = [ sequences ] counter = range ( n_steps ) if go_backwards : counter = counter [ : : ( - 1 ) ] output = [ ] prev_vals = outputs_info for i in counter : step_input = ( ( [ s [ i ] for s in sequences ] + prev_vals ) + non_sequences ) out_ = fn ( * step_input ) if isinstance ( out_ , T . TensorVariable ) : out_ = [ out_ ] if isinstance ( out_ , tuple ) : out_ = list ( out_ ) output . append ( out_ ) prev_vals = output [ ( - 1 ) ] output_scan = [ ] for i in range ( len ( output [ 0 ] ) ) : l = map ( ( lambda x : x [ i ] ) , output ) output_scan . append ( T . stack ( * l ) ) return output_scan
helper function to unroll for loops .