#NEWLINE# def test_no_increase( self ) : #NEWLINE# #INDENT# def func( x ) : #NEWLINE# #INDENT# return ( ( x - 1 ) ** 2 ) #NEWLINE# #UNINDENT# def bad_grad( x ) : #NEWLINE# #INDENT# return ( ( ( 2 * ( x - 1 ) ) * ( - 1 ) ) - 2 ) #NEWLINE# #UNINDENT# def check( method ) : #NEWLINE# #INDENT# x0 = np . array ( [ 2.0 ] ) #NEWLINE# f0 = func ( x0 ) #NEWLINE# jac = bad_grad #NEWLINE# if ( method in [ 'nelder-mead' , 'powell' , 'cobyla' ] ) : #NEWLINE# #INDENT# jac = None #NEWLINE# #UNINDENT# sol = optimize . minimize ( func , x0 , jac = jac , method = method , options = dict ( maxiter = 20 ) ) #NEWLINE# assert_equal ( func ( sol . x ) , sol . fun ) #NEWLINE# dec . knownfailureif ( ( method == 'slsqp' ) , 'SLSQP returns slightly worse' ) ( ( lambda : None ) ) ( ) #NEWLINE# assert_ ( ( func ( sol . x ) <= f0 ) ) #NEWLINE# #UNINDENT# for method in [ 'nelder-mead' , 'powell' , 'cg' , 'bfgs' , 'newton-cg' , 'l-bfgs-b' , 'tnc' , 'cobyla' , 'slsqp' ] : #NEWLINE# #INDENT# ( yield ( check , method ) )