o
    ÒtBhî  ã                   @   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dd„ Z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_feasibilityÚ	strict_lbÚ	strict_ub© r   ú|/var/www/html/riverr-enterprise-integrations-main/venv/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 
¡ s›J ‚| 	g d¢¡dk ¡ s¨J ‚‡ fdd„}‡ fdd„}dd„ }	t|t j d||	|ƒ}
t tt|
|¡ t|
g d¢ƒ}| 	g d	¢¡dk 
¡ sßJ ‚| 	g d¢¡dk ¡ sìJ ‚d S )N)r   é   é   ç      à?éF   r   )FTT)Údtyper   )g      Ð?é   é   )r   r   r   r   )r   r   r   r    )é   r   é   r   )TTT)éöÿÿÿr   r0   r   c                    s
   ˆ   | ¡S ©N)Údot©Úx©ÚAr   r   Úfun]   ó   
z2test_prepare_constraint_infeasible_x0.<locals>.func                    s   ˆ S r1   r   r3   r5   r   r   Újac`   s   z2test_prepare_constraint_infeasible_x0.<locals>.jacc                 S   s
   t  d¡S )N)r   r   )ÚspsÚ
csr_matrix)r4   Úvr   r   r   Úhessc   r8   z3test_prepare_constraint_infeasible_x0.<locals>.hess)r   Úarrayr   Úboolr   ÚpytestÚraisesÚ
ValueErrorr   Ú	violationÚanyÚallr   r   )r   r   Úx0r   ÚboundsÚpcÚlinearr7   r9   r=   Ú	nonlinearr   r5   r   Ú%test_prepare_constraint_infeasible_x0F   s:   ÿÿrK   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>   r3   r   r   r   Úcons_fp   s   .ztest_violation.<locals>.cons_féÿÿÿÿg333333ë¿r   r)   r   ç        g333333ó?gš™™™™™¹?g{®Gázä?r   g333333ó¿gR¸…ëQÈ?g{®Gáz„?g=
×£p=ò?)r   r   r   rC   r   ÚtestingÚassert_almost_equal)rL   ÚnlcrH   r   r   r   Útest_violationo   s    rR   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   rS   ))rM   r   ©rM   N)rM   rS   rM   )rT   ©NN)NrS   ))Nr'   )r   r'   )r   r'   r'   )rW   rU   )r   N)©r   r   rX   rX   r   )rW   rW   rW   )r   r>   r   r   r   )	r   r   rG   Úbounds_single_lbÚbounds_no_lbÚbounds_single_ubÚbounds_no_ubÚbounds_single_bothÚbounds_no_bothr   r   r   Útest_new_bounds_to_old   s    r_   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   rT   rV   rM   r   )r   r>   r   r	   r   )rG   Úlb_trueÚub_truer   r   r   r   r   Útest_old_bounds_to_new›   s   

&rb   c               	   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      @rc   Tç      ð?g       @F)Únumpyr>   r   r   r   ÚevalÚreprr   r   r   Úkeep_feasible)r>   r   ÚargsrG   Úbounds2r   r   r   Útest_bounds_repr«   s   
 ,üörk   c                  C   s<   t ddgddgd} t| jtjƒsJ ‚t| jtjƒsJ ‚d S )NrN   rd   )r   r   )r   Ú
isinstancer   r   Úndarrayr   )Úbr   r   r   Útest_Bounds_arrayº   s   ro   )r@   re   r   Únumpy.testingr   r   Úscipy.sparseÚsparser:   Úscipy.optimize._constraintsr   r   r   r   r   r	   r
   r   rK   rR   r_   rb   rk   ro   r   r   r   r   Ú<module>   s    $<)