o
    gd                     @   sJ  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 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)raises)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(   l/home/ubuntu/cloudmapper/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 Nr4   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(   r0   r(   r(   r)   r1   -      zMaratos.constr.<locals>.func                 S      d| d  d| d  ggS r,   r(   r@   r(   r(   r)   jac1      zMaratos.constr.<locals>.jacc                 S      d|d  t d S Nr-   r   r9   r0   vr(   r(   r)   r;   7      zMaratos.constr.<locals>.hessr.   r!   r"   r   r%   r1   rC   r;   r(   r(   r)   constr+      



zMaratos.constrr   NN
__name__
__module____qualname____doc__r*   r1   r6   r;   propertyrL   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%   rV   rW   r&   r!   r"   r'   r(   r(   r)   r*   G   s   
zMaratosTestArgs.__init__c                 C   s   | j |ks
| j|krt d S N)rV   rW   
ValueError)r%   rV   rW   r(   r(   r)   
_test_argsQ   s   zMaratosTestArgs._test_argsc                 C   s4   |  || d|d d |d d  d  |d  S r,   )rZ   r%   r0   rV   rW   r(   r(   r)   r1   U   s   (zMaratosTestArgs.func                 C   s.   |  || td|d  d d|d  gS r3   )rZ   r   r   r[   r(   r(   r)   r6   Y   s   "zMaratosTestArgs.gradc                 C   s   |  || dtd S r8   )rZ   r   r:   r[   r(   r(   r)   r;   ]   s   zMaratosTestArgs.hessc                 C   r=   )Nc                 S   r>   r?   r(   r@   r(   r(   r)   r1   c   rA   z#MaratosTestArgs.constr.<locals>.func                 S   rB   r3   r(   r@   r(   r(   r)   rC   g   rD   z#MaratosTestArgs.constr.<locals>.jacc                 S   rE   rF   r9   rG   r(   r(   r)   r;   m   rI   z$MaratosTestArgs.constr.<locals>.hessr.   rJ   rK   r(   r(   r)   rL   a   rM   zMaratosTestArgs.constrrN   )rP   rQ   rR   rS   r*   rZ   r1   r6   r;   rT   rL   r(   r(   r(   r)   rU   ?   s    

rU   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.   r4   r5   r/   r(   r(   r)   r1      s   & zMaratosGradInFunc.func                 C      dS )NTr(   r%   r(   r(   r)   r6         zMaratosGradInFunc.gradc                 C   r7   r8   r9   r/   r(   r(   r)   r;      r<   zMaratosGradInFunc.hessc                 C   r=   )Nc                 S   r>   r?   r(   r@   r(   r(   r)   r1      rA   z%MaratosGradInFunc.constr.<locals>.func                 S   rB   r3   r(   r@   r(   r(   r)   rC      rD   z%MaratosGradInFunc.constr.<locals>.jacc                 S   rE   rF   r9   rG   r(   r(   r)   r;      rI   z&MaratosGradInFunc.constr.<locals>.hessr.   rJ   rK   r(   r(   r)   rL      rM   zMaratosGradInFunc.constrrN   )
rP   rQ   rR   rS   r*   r1   rT   r6   r;   rL   r(   r(   r(   r)   r\   u   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)   r1      r2   zHyperbolicIneq.func                 C   s   |d d |d d gS )Nr   r-   r.   rb   r(   r/   r(   r(   r)   r6      rA   zHyperbolicIneq.gradc                 C   s
   t dS Nr-   r9   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)   r1      rA   z"HyperbolicIneq.constr.<locals>.func                 S   s   d| d d d  dggS )Nr   r.   r-   r(   r@   r(   r(   r)   rC      rD   z"HyperbolicIneq.constr.<locals>.jacc                 S   s2   d|d  t d| d d d  dgddgg S )Nr-   r   r.      r5   rG   r(   r(   r)   r;      s   $z#HyperbolicIneq.constr.<locals>.hessg      ?r!   r"   r   r   ra   rK   r(   r(   r)   rL      s   



zHyperbolicIneq.constr)NNrO   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 )Nrd   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.   rd          @r   axis)r   asarraysum)r%   r0   rr(   r(   r)   r1      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.   rd   r-        pr   )r   rr   
zeros_like)r%   r0   xmxm_m1xm_p1derr(   r(   r)   r6      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 )Nrx   rd   r.   rw   )dtypei  r   r-   rv      )r   
atleast_1ddiagzeroslenr~   )r%   r0   Hdiagonalr(   r(   r)   r;      s   
0$0zRosenbrock.hessc                 C   r]   )Nr(   r(   r^   r(   r(   r)   rL      r_   zRosenbrock.constrN)r-   r   rO   r(   r(   r(   r)   rg      s    

rg   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-   rd         gn?g$?rg   r*   r   r    r#   r%   rm   r(   r(   r)   r*   	     


zIneqRosenbrock.__init__c                 C   s   ddgg}d}t |tj |S Nr.   r-   r   r   ra   )r%   ArW   r(   r(   r)   rL     s   
zIneqRosenbrock.constrNr   rP   rQ   rR   rS   r*   rT   rL   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?ru   r   )rg   r*   r   r    r   r#   r   r(   r(   r)   r*      s   
zBoundedRosenbrock.__init__Nr   )rP   rQ   rR   rS   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-   rd   r   gWs`?g|\*?r   r   r(   r(   r)   r*   1  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)   rL   7  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.
    rv   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   rh   ri   rn   rj   r   r   r   hstackr   r    r!   r"   r#   )
r%   r   rm   r!   r"   phithetar0   yzr(   r(   r)   r*   O  s   

zElec.__init__c                 C   s>   |d | j  }|| j d| j   }|d| j  d  }|||fS rc   r   )r%   r0   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 rX   r   )r%   r0   r   r   r   dxdydzr(   r(   r)   _compute_coordinate_deltase  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   rb   )r   r   errstatediag_indices_fromrs   )r%   r0   r   r   r   dm1r(   r(   r)   r1   l  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.   rp   )r   r   r   r   rs   r   )	r%   r0   r   r   r   dm3grad_xgrad_ygrad_zr(   r(   r)   r6   s  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-   rb   r   r   r   re   r.   rp   )r   r   r   aranger   rs   vstackr   )r%   r0   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   )r0   r   r   r   r^   r(   r)   r1     s   zElec.constr.<locals>.func                    sN     | \}}}dt| }dt| }dt| }tt|||fS rc   )r   r   r   r   r   )r0   r   r   r   JxJyJzr^   r(   r)   rC     s
   zElec.constr.<locals>.jacc                 S   s   dt | }t|||S rc   )r   r   r   )r0   rH   Dr(   r(   r)   r;     s   zElec.constr.<locals>.hessr   rf   rK   r(   r^   r)   rL     s   


zElec.constr)rv   r   NN)rP   rQ   rR   rS   r*   r   r   r1   r6   r;   rT   rL   r(   r(   r(   r)   r   A  s    
&r   c                   @   sT   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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   Fzdelta_grad == 0.0trust-constrmethodrC   r;   r#   constraints   decimalr.   :0yE>tr_interior_pointr   re   Invalid termination condition.)r   r   r\   r`   r   rg   r   r   r   r   r6   r;   r	   filterUserWarningr   r1   r   r#   rL   r    r   r0   statusr   
optimality	tr_radiusr   barrier_parameterRuntimeError)r%   list_of_problemsprobr6   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)   r1        z<TestTrustRegionConstr.test_default_jac_and_hess.<locals>.funru   r-   r   r   )r   r#   r   r.   r   r   r   r   r0   r%   r1   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)   r1     r   z4TestTrustRegionConstr.test_default_hess.<locals>.funr   r   r   r   )r   r#   r   rC   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   rC   r;   zL-BFGS-Br   )r   rC   r   r   r   )	rg   r   r1   r   r6   r;   r   r0   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 rX   )r;   dot)r0   pr   r   r(   r)   hessp   s   

z/TestTrustRegionConstr.test_hessp.<locals>.hesspr   )r   rC   r   r#   r   r-   r   r.   r   r   r   r   )r   r   r1   r   r6   r#   rL   r    r   r0   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 )NrV      )rV   r   r   r   r-   r   r.   r   r   r   r   )rU   r   r1   r   r6   r;   r#   rL   r    r   r0   r   r   r   r   r   r   r   )r%   r   r   r(   r(   r)   	test_args:  s$   





zTestTrustRegionConstr.test_argsc              
   C   s(   t  }ttt|j|jddd|jd d S )Nr   r   )r   rC   r;   r   )r   r
   rY   r   r1   r   rL   )r%   r   r(   r(   r)   test_raise_exceptionR  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   )r0   infor(   r(   r)   callback]  s   z7TestTrustRegionConstr.test_issue_9044.<locals>.callbackc                 S   s   | d S rc   r(   r@   r(   r(   r)   <lambda>a      z7TestTrustRegionConstr.test_issue_9044.<locals>.<lambda>r   c                 S   s   d|  S rc   r(   r@   r(   r(   r)   r   a  r   c                 S   r]   rc   r(   r@   r(   r(   r)   r   b  s    r   )rC   r;   r   r   successr   rd   r.   r   )r   r   get)r%   r   r   r(   r(   r)   test_issue_9044X  s   z%TestTrustRegionConstr.test_issue_9044N)rP   rQ   rR   pytestmarkslowr   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)   functionz  rA   z;TestEmptyConstraint.test_empty_constraint.<locals>.functionc                 S   s   t d| d  d| d  gS )Nro   r   r.   r5   r@   r(   r(   r)   functionjacobian}     zCTestEmptyConstraint.test_empty_constraint.<locals>.functionjacobianc                 S   s   d| S )Nro   r(   rG   r(   r(   r)   functionhvp  s   z>TestEmptyConstraint.test_empty_constraint.<locals>.functionhvpc                 S   s    t | d d | d d  gS r?   r5   r@   r(   r(   r)   
constraint      z=TestEmptyConstraint.test_empty_constraint.<locals>.constraintc                 S   s    t d| d  d| d  ggS )Nr-   r   ru   r.   r5   r@   r(   r(   r)   constraintjacobian  r  zETestEmptyConstraint.test_empty_constraint.<locals>.constraintjacobianc                 S   s   t ddgddgg|d  S )Nro   r   g       r   r5   rG   r(   r(   r)   constraintlcoh  r  zATestEmptyConstraint.test_empty_constraint.<locals>.constraintlcohr   ro   r   )r   rC   r   r   r#   r.   r   r4   r   )	r   r   ra   r   r   r   absr0   r   )
r%   r  r  r  r  r	  r
  
startpointr#   r   r(   r(   r)   test_empty_constraintx  s&   "
z)TestEmptyConstraint.test_empty_constraintN)rP   rQ   rR   rS   r  r(   r(   r(   r)   r  k  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  rA   ztest_bug_11886.<locals>.optr.   rd   r-   )r   )
r   testingr	   r   PendingDeprecationWarningmatrixr   r   ra   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 )Nrd   r.   T)lbubkeep_feasiblec                    s,   t |  jks
J t |  jksJ d S rX   )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   r4   r-   r.   )r   expr@   r  r(   r)   obj  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   )r1   r   r   r#   r   r   slsqp)r   r   r   r   ra   r   r   r0   r  r1   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)rg   r	   r   r   r   r1   r   
less_equalr  r0   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(  r)  r!     r*  r+  
rg   r   r	   r   r   r   r1   r   r.  r0   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@r)  r!  r0  r*  r+  g      0@r1  r2  r(   r(   r)   test_equal_one_bounds  r4  z+TestBoundedNelderMead.test_equal_one_boundsc                 C   d   t  }ttd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 )
Nz7one of the lower bounds is greater than an upper bound.matchr   r'  g      r!  re   r*  r+  )rg   r
   rY   r   r   ra   r   r1   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   r6  )
Nr)  r7  r   r'  r(  r!  r0  r*  r+  )rg   r
   r   r   r   ra   r   r1   r9  r(   r(   r)   test_outside_bounds_warning  s   "z1TestBoundedNelderMead.test_outside_bounds_warningN)rP   rQ   rR   r   r   parametrizer   r   ra   rg   r    r/  r3  r5  r:  xfailr;  r(   r(   r(   r)   r&    s    
	r&  )&numpyr   r   scipy.linalgr   scipy.sparser   numpy.testingr   r   r   r   r   r	   r
   scipy.optimizer   r   r   r   r   r   r   rU   r\   r`   rg   r   r   r   r   r   r  r  r   r=  r%  r&  r(   r(   r(   r)   <module>   s2     -6/.. ,4
#