o
    hlg                     @   s>  d dl Zd dlZd dlmZ d dlmZ d dlmZm	Z	m
Z
mZmZmZ d dlmZmZmZmZmZmZ G dd dZG dd	 d	ZG d
d dZG dd dZG dd dZG dd deZG dd deZG dd deZG dd dZG dd deZG dd deZdd Z ej!j"ddd d!d" Z#G d#d$ d$Z$dS )%    N)
block_diag)
csc_matrix)TestCaseassert_array_almost_equalassert_array_lessassert_assert_allclosesuppress_warnings)NonlinearConstraintLinearConstraintBoundsminimizeBFGSSR1c                   @   s>   e Zd ZdZdddZdd Zdd	 Zd
d Zedd Z	dS )MaratosProblem 15.4 from Nocedal and Wright

    The following optimization problem:
        minimize 2*(x[0]**2 + x[1]**2 - 1) - x[0]
        Subject to: x[0]**2 + x[1]**2 - 1 = 0
    <   Nc                 C   J   |d t j }t |t |g| _t ddg| _|| _|| _d | _	d S N         ?        
nppicossinx0arrayx_opt
constr_jacconstr_hessboundsselfdegreesr    r!   rads r'   i/var/www/html/scripts/venv/lib/python3.10/site-packages/scipy/optimize/tests/test_minimize_constrained.py__init__      
zMaratos.__init__c                 C   s(   d|d d |d d  d  |d  S N   r      r'   r$   xr'   r'   r(   fun       (zMaratos.func                 C   s"   t d|d  d d|d  gS N   r   r-   r   r   r.   r'   r'   r(   grad#   s   "zMaratos.gradc                 C      dt d S Nr3   r,   r   eyer.   r'   r'   r(   hess&      zMaratos.hessc                 C   L   dd }| j d u rdd }n| j }| jd u rdd }n| j}t|dd||S )Nc                 S      | d d | d d  S Nr   r,   r-   r'   r/   r'   r'   r(   r0   +      zMaratos.constr.<locals>.func                 S      d| d  d| d  ggS r+   r'   r?   r'   r'   r(   jac/      zMaratos.constr.<locals>.jacc                 S      d|d  t d S Nr,   r   r8   r/   vr'   r'   r(   r:   5      zMaratos.constr.<locals>.hessr-   r    r!   r
   r$   r0   rB   r:   r'   r'   r(   constr)      



zMaratos.constrr   NN
__name__
__module____qualname____doc__r)   r0   r5   r:   propertyrK   r'   r'   r'   r(   r      s    
r   c                   @   sF   e Zd ZdZdddZdd Zdd	 Zd
d Zdd Ze	dd Z
dS )MaratosTestArgsr   r   Nc                 C   sV   |d t j }t |t |g| _t ddg| _|| _|| _|| _	|| _
d | _d S r   )r   r   r   r   r   r   r   r    r!   abr"   )r$   rU   rV   r%   r    r!   r&   r'   r'   r(   r)   E   s   
zMaratosTestArgs.__init__c                 C   s   | j |ks
| j|krt d S N)rU   rV   
ValueError)r$   rU   rV   r'   r'   r(   
_test_argsO   s   zMaratosTestArgs._test_argsc                 C   s4   |  || d|d d |d d  d  |d  S r+   )rY   r$   r/   rU   rV   r'   r'   r(   r0   S   s   (zMaratosTestArgs.func                 C   s.   |  || td|d  d d|d  gS r2   )rY   r   r   rZ   r'   r'   r(   r5   W   s   "zMaratosTestArgs.gradc                 C   s   |  || dtd S r7   )rY   r   r9   rZ   r'   r'   r(   r:   [   s   zMaratosTestArgs.hessc                 C   r<   )Nc                 S   r=   r>   r'   r?   r'   r'   r(   r0   a   r@   z#MaratosTestArgs.constr.<locals>.func                 S   rA   r2   r'   r?   r'   r'   r(   rB   e   rC   z#MaratosTestArgs.constr.<locals>.jacc                 S   rD   rE   r8   rF   r'   r'   r(   r:   k   rH   z$MaratosTestArgs.constr.<locals>.hessr-   rI   rJ   r'   r'   r(   rK   _   rL   zMaratosTestArgs.constrrM   )rO   rP   rQ   rR   r)   rY   r0   r5   r:   rS   rK   r'   r'   r'   r(   rT   =   s    

rT   c                   @   sB   e Zd ZdZdddZdd Zedd	 Zd
d Zedd Z	dS )MaratosGradInFuncr   r   Nc                 C   r   r   r   r#   r'   r'   r(   r)   {   r*   zMaratosGradInFunc.__init__c                 C   sJ   d|d d |d d  d  |d  t d|d  d d|d  gfS )Nr,   r   r-   r3   r4   r.   r'   r'   r(   r0      s   & zMaratosGradInFunc.func                 C      dS )NTr'   r$   r'   r'   r(   r5         zMaratosGradInFunc.gradc                 C   r6   r7   r8   r.   r'   r'   r(   r:      r;   zMaratosGradInFunc.hessc                 C   r<   )Nc                 S   r=   r>   r'   r?   r'   r'   r(   r0      r@   z%MaratosGradInFunc.constr.<locals>.func                 S   rA   r2   r'   r?   r'   r'   r(   rB      rC   z%MaratosGradInFunc.constr.<locals>.jacc                 S   rD   rE   r8   rF   r'   r'   r(   r:      rH   z&MaratosGradInFunc.constr.<locals>.hessr-   rI   rJ   r'   r'   r(   rK      rL   zMaratosGradInFunc.constrrM   )
rO   rP   rQ   rR   r)   r0   rS   r5   r:   rK   r'   r'   r'   r(   r[   s   s    

r[   c                   @   s>   e Zd ZdZdddZdd Zdd Zd	d
 Zedd Z	dS )HyperbolicIneqa  Problem 15.1 from Nocedal and Wright

    The following optimization problem:
        minimize 1/2*(x[0] - 2)**2 + 1/2*(x[1] - 1/2)**2
        Subject to: 1/(x[0] + 1) - x[1] >= 1/4
                                   x[0] >= 0
                                   x[1] >= 0
    Nc                 C   s2   ddg| _ ddg| _|| _|| _tdtj| _d S )Nr   g~T>?g~1[?)r   r   r    r!   r   r   infr"   )r$   r    r!   r'   r'   r(   r)      s
   

zHyperbolicIneq.__init__c                 C   s(   d|d d d  d|d d d   S )N      ?r   r,   r-   r'   r.   r'   r'   r(   r0      r1   zHyperbolicIneq.func                 C   s   |d d |d d gS )Nr   r,   r-   ra   r'   r.   r'   r'   r(   r5      r@   zHyperbolicIneq.gradc                 C   s
   t dS Nr,   r8   r.   r'   r'   r(   r:      s   
zHyperbolicIneq.hessc                 C   sN   dd }| j d u rdd }n| j }| jd u rdd }n| j}t|dtj||S )Nc                 S   s   d| d d  | d  S )Nr-   r   r'   r?   r'   r'   r(   r0      r@   z"HyperbolicIneq.constr.<locals>.func                 S   s   d| d d d  dggS )Nr   r-   r,   r'   r?   r'   r'   r(   rB      rC   z"HyperbolicIneq.constr.<locals>.jacc                 S   s2   d|d  t d| d d d  dgddgg S )Nr,   r   r-      r4   rF   r'   r'   r(   r:      s   $z#HyperbolicIneq.constr.<locals>.hessg      ?r    r!   r
   r   r`   rJ   r'   r'   r(   rK      s   



zHyperbolicIneq.constr)NNrN   r'   r'   r'   r(   r_      s    
r_   c                   @   s>   e Zd ZdZdddZdd Zdd	 Zd
d Zedd Z	dS )
RosenbrockzRosenbrock function.

    The following optimization problem:
        minimize sum(100.0*(x[1:] - x[:-1]**2.0)**2.0 + (1 - x[:-1])**2.0)
    r,   r   c                 C   s2   t j|}|dd|| _t || _d | _d S )Nrc   r-   )r   randomRandomStateuniformr   onesr   r"   )r$   nrandom_staterngr'   r'   r(   r)      s   
zRosenbrock.__init__c                 C   sP   t |}t jd|dd  |d d d  d  d|d d  d  dd}|S )Ng      Y@r-   rc          @r   axis)r   asarraysum)r$   r/   rr'   r'   r(   r0      s
   
:zRosenbrock.func                 C   s   t |}|dd }|d d }|dd  }t |}d||d   d||d   |  dd|   |dd< d|d  |d |d d   dd|d    |d< d|d |d d   |d< |S )	Nr-   rc   r,        pr   )r   rq   
zeros_like)r$   r/   xmxm_m1xm_p1derr'   r'   r(   r5      s   


4zRosenbrock.gradc                 C   s   t |}t d|d d  dt d|d d  d }t jt||jd}d|d d  d|d   d |d< d	|d< d
d|dd d   d|dd    |dd< |t | }|S )Nrw   rc   r-   rv   )dtypei  r   r,   ru      )r   
atleast_1ddiagzeroslenr}   )r$   r/   Hdiagonalr'   r'   r(   r:      s   
0$0zRosenbrock.hessc                 C   r\   )Nr'   r'   r]   r'   r'   r(   rK      r^   zRosenbrock.constrN)r,   r   rN   r'   r'   r'   r(   rf      s    

rf   c                   @   &   e Zd ZdZdddZedd ZdS )	IneqRosenbrockzRosenbrock subject to inequality constraints.

    The following optimization problem:
        minimize sum(100.0*(x[1] - x[0]**2)**2.0 + (1 - x[0])**2)
        subject to: x[0] + 2 x[1] <= 1

    Taken from matlab ``fmincon`` documentation.
    r   c                 C   ,   t | d| ddg| _ddg| _d | _d S )Nr,   rc         gn?g$?rf   r)   r   r   r"   r$   rl   r'   r'   r(   r)        


zIneqRosenbrock.__init__c                 C   s   ddgg}d}t |tj |S Nr-   r,   r   r   r`   )r$   ArV   r'   r'   r(   rK     s   
zIneqRosenbrock.constrNr   rO   rP   rQ   rR   r)   rS   rK   r'   r'   r'   r(   r      s
    
r   c                   @   s   e Zd ZdZdddZdS )BoundedRosenbrocka  Rosenbrock subject to inequality constraints.

    The following optimization problem:
        minimize sum(100.0*(x[1] - x[0]**2)**2.0 + (1 - x[0])**2)
        subject to:  -2 <= x[0] <= 0
                      0 <= x[1] <= 2

    Taken from matlab ``fmincon`` documentation.
    r   c                 C   s6   t | d| ddg| _d | _tddgddg| _d S )Nr,   gɿg?rt   r   )rf   r)   r   r   r   r"   r   r'   r'   r(   r)     s   
zBoundedRosenbrock.__init__Nr   )rO   rP   rQ   rR   r)   r'   r'   r'   r(   r     s    	r   c                   @   r   )	EqIneqRosenbrocka*  Rosenbrock subject to equality and inequality constraints.

    The following optimization problem:
        minimize sum(100.0*(x[1] - x[0]**2)**2.0 + (1 - x[0])**2)
        subject to: x[0] + 2 x[1] <= 1
                    2 x[0] + x[1] = 1

    Taken from matlab ``fimincon`` documentation.
    r   c                 C   r   )Nr,   rc   r   gWs`?g|\*?r   r   r'   r'   r(   r)   /  r   zEqIneqRosenbrock.__init__c                 C   s8   ddgg}d}ddgg}d}t |tj |t |||fS r   r   )r$   A_ineqb_ineqA_eqb_eqr'   r'   r(   rK   5  s   


zEqIneqRosenbrock.constrNr   r   r'   r'   r'   r(   r   %  s
    
	r   c                   @   sR   e Zd ZdZ		dddZdd Zd	d
 Zdd Zdd Zdd Z	e
dd ZdS )Eleca  Distribution of electrons on a sphere.

    Problem no 2 from COPS collection [2]_. Find
    the equilibrium state distribution (of minimal
    potential) of the electrons positioned on a
    conducting sphere.

    References
    ----------
    .. [1] E. D. Dolan, J. J. Mor'{e}, and T. S. Munson,
           "Benchmarking optimization software with COPS 3.0.",
            Argonne National Lab., Argonne, IL (US), 2004.
    ru   r   Nc           
      C   s   || _ tj|| _| jddtj | j }| jtj tj| j }t|t| }t|t| }t|}	t	|||	f| _
d | _|| _|| _d | _d S )Nr   r,   )n_electronsr   rg   rh   rm   ri   r   r   r   hstackr   r   r    r!   r"   )
r$   r   rl   r    r!   phithetar/   yzr'   r'   r(   r)   M  s   

zElec.__init__c                 C   s>   |d | j  }|| j d| j   }|d| j  d  }|||fS rb   r   )r$   r/   x_coordy_coordz_coordr'   r'   r(   _get_cordinates]  s   
zElec._get_cordinatesc                 C   sV   |  |\}}}|d d d f | }|d d d f | }|d d d f | }|||fS rW   r   )r$   r/   r   r   r   dxdydzr'   r'   r(   _compute_coordinate_deltasc  s
   
zElec._compute_coordinate_deltasc                 C   st   |  |\}}}tjdd |d |d  |d  d }W d    n1 s'w   Y  d|t|< dt| S )Nignoredivider,   r   r   ra   )r   r   errstatediag_indices_fromrr   )r$   r/   r   r   r   dm1r'   r'   r(   r0   j  s   zElec.func           	      C   s   |  |\}}}tjdd |d |d  |d  d }W d    n1 s'w   Y  d|t|< tj|| dd }tj|| dd }tj|| dd }t|||fS )Nr   r   r,         r   r-   ro   )r   r   r   r   rr   r   )	r$   r/   r   r   r   dm3grad_xgrad_ygrad_zr'   r'   r(   r5   q  s   z	Elec.gradc              	   C   s  |  |\}}}|d |d  |d  d }tjdd |d }|d }W d    n1 s/w   Y  t| j}d|||f< d|||f< |d|d  |  }	tj|	d	d
 |	||f< d| | | }
tj|
d	d
 |
||f< d| | | }tj|d	d
 |||f< |d|d  |  }tj|d	d
 |||f< d| | | }tj|d	d
 |||f< |d|d  |  }tj|d	d
 |||f< tt|	|
|ft|
||ft|||ff}|S )Nr,   ra   r   r   r   rd   r-   ro   )r   r   r   aranger   rr   vstackr   )r$   r/   r   r   r   dr   dm5iHxxHxyHxzHyyHyzHzzr   r'   r'   r(   r:   ~  s6   
z	Elec.hessc                    sX    fdd} j d u r fdd}n j } jd u rdd }n j}t|tj d||S )Nc                    s,     | \}}}|d |d  |d  d S )Nr,   r-   r   )r/   r   r   r   r]   r'   r(   r0     s   zElec.constr.<locals>.func                    sN     | \}}}dt| }dt| }dt| }tt|||fS rb   )r   r   r   r   r   )r/   r   r   r   JxJyJzr]   r'   r(   rB     s
   zElec.constr.<locals>.jacc                 S   s   dt | }t|||S rb   )r   r   r   )r/   rG   Dr'   r'   r(   r:     s   zElec.constr.<locals>.hessr   re   rJ   r'   r]   r(   rK     s   


zElec.constr)ru   r   NN)rO   rP   rQ   rR   r)   r   r   r0   r5   r:   rS   rK   r'   r'   r'   r(   r   ?  s    
&r   c                   @   s\   e Zd Zejjdd Zdd Zdd Zdd Z	d	d
 Z
dd Zdd Zdd Zdd ZdS )TestTrustRegionConstrc                 C   s  t  t ddt t dt dt dt t tddtt dtdt dt t t t t	ddt	dddt	dt dt	ddt dg}|D ]}|j
dd	fD ]}|jdt td
dtddfD ]u}|dv rj|dv rjq_|j
du rt|dv rtq_t }|td t|j|jd|||j|jd}W d    n1 sw   Y  |jd urt|j|jdd |jdkrt|jd |jdkrt|jd |jdkrt|jd |jdv rtdq_qNqFd S )N2-point)r!   )r    r!   3-pointr,   r   )r   r!   )r   r    r!   Fdamp_update)exception_strategyskip_update)r   r   csF)r   r   r   T)r   Fdelta_grad == 0.0trust-constrmethodrB   r:   r"   constraints   decimalr-   :0yE>tr_interior_pointr   rd   Invalid termination condition.)r   r   r[   r_   r   rf   r   r   r   r   r5   r:   r	   filterUserWarningr   r0   r   r"   rK   r   r   r/   statusr   
optimality	tr_radiusr   barrier_parameterRuntimeError)r$   list_of_problemsprobr5   r:   supresultr'   r'   r(   test_list_of_problems  sx   









z+TestTrustRegionConstr.test_list_of_problemsc                 C   s4   dd }dg}t |dg|dd}t|jddd	 d S )
Nc                 S      | d d S r   r'   r?   r'   r'   r(   r0        z<TestTrustRegionConstr.test_default_jac_and_hess.<locals>.funrt   r,   r   r   )r   r"   r   r-   r   r   r   r   r/   r$   r0   r"   resr'   r'   r(   test_default_jac_and_hess  s   z/TestTrustRegionConstr.test_default_jac_and_hessc                 C   s6   dd }dg}t |dg|ddd}t|jdd	d
 d S )Nc                 S   r   r   r'   r?   r'   r'   r(   r0     r   z4TestTrustRegionConstr.test_default_hess.<locals>.funr   r   r   r   )r   r"   r   rB   r-   r   r   r   r   r'   r'   r(   test_default_hess  s   z'TestTrustRegionConstr.test_default_hessc                 C   s   t  }t|j|jd|j|jd}t|j|jddd}t|j|jddd}t|j|jdd t|j|jdd t|j|jdd d S )	Nr   )r   rB   r:   zL-BFGS-Br   )r   rB   r   r   r   )	rf   r   r0   r   r5   r:   r   r/   r   )r$   r   r   result1result2r'   r'   r(   test_no_constraints  s    


z)TestTrustRegionConstr.test_no_constraintsc              	      s   t    fdd}t j jd j| j jd} jd ur't|j	 jdd |j
dkr2t|jd |j
dkrHt|jd |jd	krHt|jd |j
d
v rQtdd S )Nc                    s     | }||S rW   )r:   dot)r/   pr   r   r'   r(   hessp  s   

z/TestTrustRegionConstr.test_hessp.<locals>.hesspr   )r   rB   r   r"   r   r,   r   r-   r   r   r   r   )r   r   r0   r   r5   r"   rK   r   r   r/   r   r   r   r   r   r   r   )r$   r   r   r'   r   r(   
test_hessp  s&   





z TestTrustRegionConstr.test_hesspc              
   C   s   t dd}t|j|jdd|j|j|j|jd}|jd ur%t	|j
|jdd |jdkr0t|jd	 |jdkrFt|jd	 |jd
krFt|jd	 |jdv rOtdd S )NrU      )rU   r   r   r   r,   r   r-   r   r   r   r   )rT   r   r0   r   r5   r:   r"   rK   r   r   r/   r   r   r   r   r   r   r   )r$   r   r   r'   r'   r(   	test_args8  s$   





zTestTrustRegionConstr.test_argsc              	   C   sX   t  }d}tjt|d t|j|jddd|jd W d    d S 1 s%w   Y  d S )Nz9Whenever the gradient is estimated via finite-differencesmatchr   r   )r   rB   r:   r   )r   pytestraisesrX   r   r0   r   rK   )r$   r   messager'   r'   r(   test_raise_exceptionP  s   "z*TestTrustRegionConstr.test_raise_exceptionc                 C   sd   dd }t dd dgdd dd |dd	}t|d
 t|dddk t|dddk d S )Nc                 S   s   t d|v  t d|v  d S )Nnitniter)r   )r/   infor'   r'   r(   callback\  s   z7TestTrustRegionConstr.test_issue_9044.<locals>.callbackc                 S   s   | d S rb   r'   r?   r'   r'   r(   <lambda>`      z7TestTrustRegionConstr.test_issue_9044.<locals>.<lambda>r   c                 S   s   d|  S rb   r'   r?   r'   r'   r(   r   `  r   c                 S   r\   rb   r'   r?   r'   r'   r(   r   a  s    r   )rB   r:   r   r   successr   rc   r-   r   )r   r   get)r$   r   r   r'   r'   r(   test_issue_9044W  s   z%TestTrustRegionConstr.test_issue_9044c                 C   s   t ddg}dd }tt ddgt ddgdd}t }|td td	|||d
}W d    n1 s8w   Y  |d sCJ d S )Nr   ra   c                 S   s    | d }| d }|d |d  S )Nr   r-   r,   r'   )r/   x1x2r'   r'   r(   objr  s   z3TestTrustRegionConstr.test_issue_15093.<locals>.objr   T)keep_feasibler   r   )r   r0   r   r"   r  )r   r   r   r	   r   r   r   )r$   r   r  r"   r   r   r'   r'   r(   test_issue_15093j  s   z&TestTrustRegionConstr.test_issue_15093N)rO   rP   rQ   r   markslowr   r   r   r   r   r   r   r  r  r'   r'   r'   r(   r     s    
;r   c                   @   s   e Zd ZdZdd ZdS )TestEmptyConstrainta  
    Here we minimize x^2+y^2 subject to x^2-y^2>1.
    The actual minimum is at (0, 0) which fails the constraint.
    Therefore we will find a minimum on the boundary at (+/-1, 0).

    When minimizing on the boundary, optimize uses a set of
    constraints that removes the constraint that sets that
    boundary.  In our case, there's only one constraint, so
    the result is an empty constraint.

    This tests that the empty constraint works.
    c           
   	   C   s   dd }dd }dd }dd }d	d
 }dd }t |dtj||}ddg}ttj tj gtjtjg}t||d|||g|d}	tt|	jtddgdd d S )Nc                 S   r=   r>   r'   r?   r'   r'   r(   function  r@   z;TestEmptyConstraint.test_empty_constraint.<locals>.functionc                 S   s   t d| d  d| d  gS )Nrn   r   r-   r4   r?   r'   r'   r(   functionjacobian     zCTestEmptyConstraint.test_empty_constraint.<locals>.functionjacobianc                 S   s   d| S )Nrn   r'   rF   r'   r'   r(   functionhvp  s   z>TestEmptyConstraint.test_empty_constraint.<locals>.functionhvpc                 S   s    t | d d | d d  gS r>   r4   r?   r'   r'   r(   
constraint      z=TestEmptyConstraint.test_empty_constraint.<locals>.constraintc                 S   s    t d| d  d| d  ggS )Nr,   r   rt   r-   r4   r?   r'   r'   r(   constraintjacobian  r  zETestEmptyConstraint.test_empty_constraint.<locals>.constraintjacobianc                 S   s   t ddgddgg|d  S )Nrn   r   g       r   r4   rF   r'   r'   r(   constraintlcoh  r  zATestEmptyConstraint.test_empty_constraint.<locals>.constraintlcohr   rn   r   )r   rB   r   r   r"   r-   r   r3   r   )	r
   r   r`   r   r   r   absr/   r   )
r$   r  r  r  r  r  r  
startpointr"   r   r'   r'   r(   test_empty_constraint  s&   "
z)TestEmptyConstraint.test_empty_constraintN)rO   rP   rQ   rR   r  r'   r'   r'   r(   r    s    r  c                  C   sv   dd } t j }|t t t ddg}W d    n1 s#w   Y  t|dt j}t	| ddg |d d S )Nc                 S   r=   r>   r'   r?   r'   r'   r(   opt  r@   ztest_bug_11886.<locals>.optr-   rc   r,   )r   )
r   testingr	   r   PendingDeprecationWarningmatrixr   r   r`   r   )r  r   r   lin_consr'   r'   r(   test_bug_11886  s   
r  z(Known bug in trust-constr; see gh-11649.T)reasonstrictc                     s   t ddgddgddfdd  fdd}  fd	d
} fdd}td}t|dtjt|ddg}t| |d|d}|jsCJ  |j |d j|d 	|j  k r_|d j
k sbJ  J t||j|d j
 t| |d|d}t|j	|j	 d S )Nrc   r-   T)lbubr  c                    s,   t |  jks
J t |  jksJ d S rW   )r   allr  r   r?   )bndsr'   r(   assert_inbounds  s   z%test_gh11649.<locals>.assert_inboundsc                    sZ    |  t | d d| d d  d| d d   d| d  | d   d| d   d  S )Nr   r3   r,   r-   )r   expr?   r#  r'   r(   r    s   Rztest_gh11649.<locals>.objc                    s    |  | d d | d  S r>   r'   r?   r%  r'   r(   nce  s   ztest_gh11649.<locals>.ncec                    s    |  | d | d  S )Nr   r-   r'   r?   r%  r'   r(   nci  s   ztest_gh11649.<locals>.nci)gGz?gGzr   )r0   r   r   r"   r   r   slsqp)r   r   r   r
   r`   r   r  r/   r  r0   r   r   )r  r&  r'  r   nlcsr   refr'   )r#  r"  r(   test_gh11649  s(   



4r,  c                
   @   s   e Zd Zejdeej eje	 j
feej dddgfedejddgfeddgddgddgfgdd	 Zd
d Zdd Zdd Zejjdddd ZdS )TestBoundedNelderMeadzbounds, x_optgg      @g      "@r         @      @c                 C   s   t  }t J}|td t|jddgd|d}t|j|j	
 s$J t|j	|j
 s0J t||j	|js=J tj|j	|ddsHJ W d    d S 1 sSw   Y  d S )N0Initial guess is not within the specified boundsr(  Nelder-Meadr   r"   gMbP?)atol)rf   r	   r   r   r   r0   r   
less_equalr  r/   r!  r   allclose)r$   r"   r   r   r   r   r'   r'   r(   test_rosen_brock_with_bounds  s   "z2TestBoundedNelderMead.test_rosen_brock_with_boundsc                 C   s|   t  }tddgddg}t %}|td t|jddgd|d}t|j	ddgs,J W d    d S 1 s7w   Y  d S )Nr.  r/  r0  r(     r1  r2  
rf   r   r	   r   r   r   r0   r   r5  r/   r$   r   r"   r   r   r'   r'   r(   test_equal_all_bounds     "z+TestBoundedNelderMead.test_equal_all_boundsc                 C   s|   t  }tddgddg}t %}|td t|jddgd|d}t|j	dd	gs,J W d    d S 1 s7w   Y  d S )
Nr.  r/  g      4@r0  r(  r7  r1  r2  g      0@r8  r9  r'   r'   r(   test_equal_one_bounds	  r;  z+TestBoundedNelderMead.test_equal_one_boundsc                 C   j   t  }d}tjt|d ttj dgddg}t|jddgd|d	 W d    d S 1 s.w   Y  d S )
Nz:An upper bound is less than the corresponding lower bound.r   r   r.  g      r(  rd   r1  r2  )	rf   r   r   rX   r   r   r`   r   r0   r$   r   r   r"   r'   r'   r(   test_invalid_bounds  s   "z)TestBoundedNelderMead.test_invalid_boundsz5Failing on Azure Linux and macOS builds, see gh-13846)r  c                 C   r=  )
Nr0  r   r   r.  r/  r(  r7  r1  r2  )	rf   r   warnsr   r   r   r`   r   r0   r>  r'   r'   r(   test_outside_bounds_warning  s   "z1TestBoundedNelderMead.test_outside_bounds_warningN)rO   rP   rQ   r   r	  parametrizer   r   r`   rf   r   r6  r:  r<  r?  xfailrA  r'   r'   r'   r(   r-    s    
	r-  )%numpyr   r   scipy.linalgr   scipy.sparser   numpy.testingr   r   r   r   r   r	   scipy.optimizer
   r   r   r   r   r   r   rT   r[   r_   rf   r   r   r   r   r   r  r  r	  rC  r,  r-  r'   r'   r'   r(   <module>   s0      -6/.. G4
#