#NEWLINE# def softmax_simplifier( numerators , denominators ) : #NEWLINE# #INDENT# for numerator in list ( numerators ) : #NEWLINE# #INDENT# if ( not numerator . type . dtype . startswith ( 'float' ) ) : #NEWLINE# #INDENT# continue #NEWLINE# #UNINDENT# if ( numerator . ndim != 2 ) : #NEWLINE# #INDENT# continue #NEWLINE# #UNINDENT# if ( numerator . owner and ( numerator . owner . op == tensor . exp ) ) : #NEWLINE# #INDENT# x = numerator . owner . inputs [ 0 ] #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# continue #NEWLINE# #UNINDENT# matching_denom = None #NEWLINE# for denominator in denominators : #NEWLINE# #INDENT# if ( denominator . owner and isinstance ( denominator . owner . op , tensor . DimShuffle ) ) : #NEWLINE# #INDENT# if ( denominator . owner . op . new_order == ( 0 , 'x' ) ) : #NEWLINE# #INDENT# z = denominator . owner . inputs [ 0 ] #NEWLINE# if ( z . owner and isinstance ( z . owner . op , tensor . Sum ) ) : #NEWLINE# #INDENT# if ( z . owner . op . axis == ( 1 , ) ) : #NEWLINE# #INDENT# if ( z . owner . inputs [ 0 ] is numerator ) : #NEWLINE# #INDENT# matching_denom = denominator #NEWLINE# break #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# if matching_denom : #NEWLINE# #INDENT# numerators . remove ( numerator ) #NEWLINE# denominators . remove ( matching_denom ) #NEWLINE# numerators . append ( softmax_op ( x ) ) #NEWLINE# #UNINDENT# #UNINDENT# return ( numerators , denominators )