#NEWLINE# def is_neg( var ) : #NEWLINE# #INDENT# '\n    Match a variable with the `-x` pattern.\n\n    Parameters\n    ----------\n    var\n        The Variable to analyze.\n\n    Returns\n    -------\n    object\n        `x` if `var` is of the form `-x`, or None otherwise.\n\n    ' #NEWLINE# apply = var . owner #NEWLINE# if ( not apply ) : #NEWLINE# #INDENT# return None #NEWLINE# #UNINDENT# if ( apply . op == tensor . neg ) : #NEWLINE# #INDENT# return apply . inputs [ 0 ] #NEWLINE# #UNINDENT# if ( ( apply . op == tensor . mul ) and ( len ( apply . inputs ) >= 2 ) ) : #NEWLINE# #INDENT# for ( idx , mul_input ) in enumerate ( apply . inputs ) : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# constant = opt . get_scalar_constant_value ( mul_input ) #NEWLINE# is_minus_1 = numpy . allclose ( constant , ( - 1 ) ) #NEWLINE# #UNINDENT# except NotScalarConstantError : #NEWLINE# #INDENT# is_minus_1 = False #NEWLINE# #UNINDENT# if is_minus_1 : #NEWLINE# #INDENT# if ( len ( apply . inputs ) == 2 ) : #NEWLINE# #INDENT# return apply . inputs [ ( 1 - idx ) ] #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# return tensor . mul ( * ( constant . inputs [ 0 : idx ] + apply . inputs [ ( idx + 1 ) : ] ) ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# return None