#NEWLINE# def grad_and_aux( fun , argnum = 0 ) : #NEWLINE# #INDENT# 'Builds a function that returns the gradient of the first output and the\n    (unmodified) second output of a function that returns two outputs.' #NEWLINE# def grad_and_aux_fun( * args , **kwargs ) : #NEWLINE# #INDENT# saved = ( lambda : None ) #NEWLINE# def return_val_save_aux( * args , **kwargs ) : #NEWLINE# #INDENT# ( val , saved . aux ) = fun ( * args , ** kwargs ) #NEWLINE# return val #NEWLINE# #UNINDENT# gradval = grad ( return_val_save_aux , argnum ) ( * args , ** kwargs ) #NEWLINE# return ( gradval , saved . aux ) #NEWLINE# #UNINDENT# return fun