#NEWLINE# def apply( self , fgraph ) : #NEWLINE# #INDENT# nodelist = list ( fgraph . toposort ( ) ) #NEWLINE# cond_nodes = [ s for s in nodelist if isinstance ( s . op , IfElse ) ] #NEWLINE# if ( len ( cond_nodes ) < 2 ) : #NEWLINE# #INDENT# return False #NEWLINE# #UNINDENT# merging_node = cond_nodes [ 0 ] #NEWLINE# for proposal in cond_nodes [ 1 : ] : #NEWLINE# #INDENT# if ( ( proposal . inputs [ 0 ] == merging_node . inputs [ 0 ] ) and ( not find_up ( new_outs , merging_node ) ) ) : #NEWLINE# #INDENT# mn_ts = merging_node . inputs [ 1 : ] [ : merging_node . op . n_outs ] #NEWLINE# mn_fs = merging_node . inputs [ 1 : ] [ merging_node . op . n_outs : ] #NEWLINE# pl_ts = proposal . inputs [ 1 : ] [ : proposal . op . n_outs ] #NEWLINE# pl_fs = proposal . inputs [ 1 : ] [ proposal . op . n_outs : ] #NEWLINE# new_ins = ( ( ( ( [ merging_node . inputs [ 0 ] ] + mn_ts ) + pl_ts ) + mn_fs ) + pl_fs ) #NEWLINE# mn_name = '?' #NEWLINE# if merging_node . op . name : #NEWLINE# #INDENT# mn_name = merging_node . op . name #NEWLINE# #UNINDENT# pl_name = '?' #NEWLINE# if proposal . op . name : #NEWLINE# #INDENT# pl_name = proposal . op . name #NEWLINE# #UNINDENT# new_ifelse = IfElse ( n_outs = len ( ( mn_ts + pl_ts ) ) , as_view = False , gpu = False , name = ( ( mn_name + '&' ) + pl_name ) ) #NEWLINE# print ( 'here' ) #NEWLINE# new_outs = new_ifelse ( * new_ins , ** dict ( return_list = True ) ) #NEWLINE# new_outs = [ clone ( x ) for x in new_outs ] #NEWLINE# old_outs = [ ] #NEWLINE# if ( type ( merging_node . outputs ) not in ( list , tuple ) ) : #NEWLINE# #INDENT# old_outs += [ merging_node . outputs ] #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# old_outs += merging_node . outputs #NEWLINE# #UNINDENT# if ( type ( proposal . outputs ) not in ( list , tuple ) ) : #NEWLINE# #INDENT# old_outs += [ proposal . outputs ] #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# old_outs += proposal . outputs #NEWLINE# #UNINDENT# pairs = list ( zip ( old_outs , new_outs ) ) #NEWLINE# fgraph . replace_all_validate ( pairs , reason = 'cond_merge' )