#NEWLINE# def test_slsqp_respect_bounds( self ) : #NEWLINE# #INDENT# def f( x ) : #NEWLINE# #INDENT# return sum ( ( ( x - np . array ( [ 1.0 , 2.0 , 3.0 , 4.0 ] ) ) ** 2 ) ) #NEWLINE# #UNINDENT# def cons( x ) : #NEWLINE# #INDENT# a = np . array ( [ [ ( - 1 ) , ( - 1 ) , ( - 1 ) , ( - 1 ) ] , [ ( - 3 ) , ( - 3 ) , ( - 2 ) , ( - 1 ) ] ] ) #NEWLINE# return np . concatenate ( [ ( np . dot ( a , x ) + np . array ( [ 5 , 10 ] ) ) , x ] ) #NEWLINE# #UNINDENT# x0 = np . array ( [ 0.5 , 1.0 , 1.5 , 2.0 ] ) #NEWLINE# res = optimize . minimize ( f , x0 , method = 'slsqp' , constraints = { #NEWLINE# #INDENT# 'type' : 'ineq' , #NEWLINE# 'fun' : cons , #NEWLINE# #UNINDENT# } ) #NEWLINE# assert_allclose ( res . x , ( np . array ( [ 0.0 , 2 , 5 , 8 ] ) / 3 ) , atol = 1e-12 )