o
    i$                     @   s   d dl Z d dlZd dlmZmZ d dlmZ d dl	m
Z
mZmZmZmZmZmZ G dd deZdd Zdd	 Zd
d Zdd ZG dd dZG dd dZdS )    N)TestCaseassert_array_equal)BoundsLinearConstraintNonlinearConstraintPreparedConstraintnew_bounds_to_oldold_bound_to_newstrict_boundsc                   @   s,   e Zd Zdd Zdd Zdd Zdd Zd	S )
TestStrictBoundsc                 C   s   d}d}d}d}t ||||\}}t|tj tj tj g t|tjtjtjg d}t ||||\}}t|g d t|g d d S )N         FT)r   r   r   )r   r   r   r
   r   npinfselfmlbubenforce_feasibilityZ	strict_lbZ	strict_ub r   t/var/www/html/eduruby.in/lip-sync/lip-sync-env/lib/python3.10/site-packages/scipy/optimize/tests/test_constraints.py+test_scalarvalue_unique_enforce_feasibility   s"   z<TestStrictBounds.test_scalarvalue_unique_enforce_feasibilityc                 C   s   d}g d}g d}d}t ||||\}}t|tj tj tj g t|tjtjtjg d}t ||||\}}t|g d t|g d d S )Nr      r   r   )r         FTr   r   r   r   r   +test_vectorvalue_unique_enforce_feasibility   s"   z<TestStrictBounds.test_vectorvalue_unique_enforce_feasibilityc                 C   sV   d}d}d}g d}t ||||\}}t|tj dtj g t|tjdtjg d S )Nr   r   r   )FTFr   r   r   r   r   +test_scalarvalue_vector_enforce_feasibility/   s   z<TestStrictBounds.test_scalarvalue_vector_enforce_feasibilityc                 C   s^   d}g d}ddt jg}g d}t||||\}}t|dt j dg t|dt jt jg d S )Nr   r   r   r   )TFTr   )r   r   r
   r   r   r   r   r   +test_vectorvalue_vector_enforce_feasibility:   s   z<TestStrictBounds.test_vectorvalue_vector_enforce_feasibilityN)__name__
__module____qualname__r   r   r    r!   r   r   r   r   r   
   s
    r   c                     s  t g d} t dt jdg}t g d}t jg dtd}t| ||}ttt|| tt| |g d}|	g ddk
 sEJ |	g ddk sRJ t g d	}t g d	g d
g dg t jg dtd}t t j d|}ttt|| tt t j dg d	}|	g d	dk
 sJ |	g ddk sJ  fdd} fdd}dd }	t|t j d||	|}
ttt|
| t|
g d}|	g d	dk
 sJ |	g ddk sJ d S )N)r               ?F   r   )FTT)Zdtyper   )g      ?      )r   r   r   r   )r   r   r   r   )   r      r   )TTT)r   r-   r   c                    s
     | S N)dotxAr   r   fun]      
z2test_prepare_constraint_infeasible_x0.<locals>.func                    s    S r.   r   r0   r2   r   r   jac`   s   z2test_prepare_constraint_infeasible_x0.<locals>.jacc                 S   s
   t dS )N)r   r   )spsZ
csr_matrix)r1   vr   r   r   hessc   r5   z3test_prepare_constraint_infeasible_x0.<locals>.hess)r   arrayr   boolr   pytestraises
ValueErrorr   	violationanyallr   r   )r   r   x0r   boundspcZlinearr4   r6   r9   Z	nonlinearr   r2   r   %test_prepare_constraint_infeasible_x0F   s:   rE   c                  C   s   dd } t | ddgddg}t|ddg}t|ddgddg tj|dd	gdd
g tj|d	d	gddg tj|d
dgddg tj|d
dgddg d S )Nc                 S   s.   t | d d | d  | d d | d  gS )Nr   r   r   )r   r:   r0   r   r   r   cons_fp   s   .ztest_violation.<locals>.cons_fg333333r   r'   r           g333333?g?g{Gz?r   g333333gRQ?g{Gz?g=
ףp=?)r   r   r   r?   r   testingZassert_almost_equal)rF   ZnlcrD   r   r   r   test_violationo   s    rJ   c            	      C   s   t t j ddg} t dt jdg}g d}tt| |d| g d}ttd|d| g d}ttt j |d| g d}tt| d	d| g d
}tt| t jd| g d}ttddd| g d}ttt j t jd| d S )Nr   r   
   )Nr   r   N)r   rK   ))rG   r   rG   N)rG   rK   rG   )rL   NN)NrK   ))Nr%   )r   r%   )r   r%   r%   )rO   rM   )r   N)r   r   rP   rP   r   )rO   rO   rO   )r   r:   r   r   r   )	r   r   rC   Zbounds_single_lbZbounds_no_lbZbounds_single_ubZbounds_no_ubZbounds_single_bothZbounds_no_bothr   r   r   test_new_bounds_to_old   s    rQ   c                  C   s   ddgddf} t dt j dg}t ddt jg}t| \}}t|| t|| t j t jft dgt dgfg} t| \}}t|t j dg t|t jdg d S )Nr   r   rL   rN   rG   r   )r   r:   r   r	   r   )rC   Zlb_trueZub_truer   r   r   r   r   test_old_bounds_to_new   s   

&rR   c                   @   s4   e Zd Zdd Zdd Zdd Zdd Zd	d
 ZdS )
TestBoundsc              	   C   s   ddl m}m} ddtjdftdtj gtdtjgftdtj gtdtjgtddgffD ]#}t| }ttt| }t|j|j t|j	|j	 t|j
|j
 q6d S )	Nr   )r:   r   )      g      @rT   T      ?g       @F)numpyr:   r   r   r   evalreprr   r   r   keep_feasible)r   r:   r   argsrC   Zbounds2r   r   r   	test_repr   s   
 zTestBounds.test_reprc                 C   s<   t ddgddgd}t|jtjsJ t|jtjsJ d S )NrH   rU   )r   r   )r   
isinstancer   r   Zndarrayr   )r   br   r   r   
test_array   s   zTestBounds.test_arrayc                 C   sF   t  }t ttj ttj}|j|jksJ |j|jks!J d S r.   )r   r   Zasarrayr   r   r   )r   b1b2r   r   r   test_defaults   s   zTestBounds.test_defaultsc                 C   s,  d}t jt|d ttddgddg W d    n1 s w   Y  t jt|d tddgtddg W d    n1 sCw   Y  d}t jt|d tddgddgtddgd W d    n1 slw   Y  d}t jt|d tddgg d	 W d    d S 1 sw   Y  d S )
Nz,Lower and upper bounds must be dense arrays.matchr   r   z&`keep_feasible` must be a dense array.TrY   z6`lb`, `ub`, and `keep_feasible` must be broadcastable.r   )r<   r=   r>   r   r7   	coo_array)r   messager   r   r   test_input_validation   s   ""z TestBounds.test_input_validationc                 C   s6   t dd}ddg}tj||ddgddgf d S )Nr   rG   r   r   r   )r   r   rI   assert_allcloseresidual)r   rC   rB   r   r   r   test_residual   s   
$zTestBounds.test_residualN)r"   r#   r$   r[   r^   ra   rg   rk   r   r   r   r   rS      s    rS   c                   @   s$   e Zd Zdd Zdd Zdd ZdS )TestLinearConstraintc                 C   sD   t d}t|}t|t j t j}t|j|j t|j|j d S )Nr   )r   eyer   r   r   r   r   )r   r3   lcZlc2r   r   r   ra      s
   
z"TestLinearConstraint.test_defaultsc                 C   s  t d}d}tjt|d t|ddgg d W d    n1 s#w   Y  d}tjt|d t|tddgddg W d    n1 sIw   Y  tjt|d t|ddgtddg W d    n1 smw   Y  d	}tjt|d td
d
g}t|ddgddg|d W d    n1 sw   Y  t d}d}tjt|d t| W d    d S 1 sw   Y  d S )Nr   z5`lb`, `ub`, and `keep_feasible` must be broadcastablerb   r   r   r   z&Constraint limits must be dense arraysr   z%`keep_feasible` must be a dense arrayTrd   )r   r   r   z%`A` must have exactly two dimensions.)	r   rm   r<   r=   r>   r   r7   re   empty)r   r3   rf   rY   r   r   r   rg      s,   


"z*TestLinearConstraint.test_input_validationc                 C   sB   t d}t|dd}ddg}t j||ddgddgf d S )Nr   rh   r   rG   r   r   )r   rm   r   rI   ri   rj   )r   r3   rn   rB   r   r   r   rk      s   
$z"TestLinearConstraint.test_residualN)r"   r#   r$   ra   rg   rk   r   r   r   r   rl      s    rl   )r<   rV   r   Znumpy.testingr   r   Zscipy.sparsesparser7   Zscipy.optimize._constraintsr   r   r   r   r   r	   r
   r   rE   rJ   rQ   rR   rS   rl   r   r   r   r   <module>   s    $<)2