o
    èEbî  ã                   @   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_feasibilityZ	strict_lbZ	strict_ub© r   úG/usr/lib/python3/dist-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)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   ÚpytestZraisesÚ
ValueErrorr   Ú	violationÚanyÚallr   r   )r   r   Zx0r   ÚboundsÚpcZlinearr4   r6   r9   Z	nonlinearr   r2   r   Ú%test_prepare_constraint_infeasible_x0F   s:   ÿÿrC   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_féÿÿÿÿg333333ë¿r   r'   r   ç        g333333ó?gš™™™™™¹?g{®Gázä?r   g333333ó¿gR¸…ëQÈ?g{®Gáz„?g=
×£p=ò?)r   r   r   r>   r   ZtestingZassert_almost_equal)rD   ZnlcrB   r   r   r   Útest_violationo   s    rG   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   rH   ))rE   r   ©rE   N)rE   rH   rE   )rI   ©NN)NrH   ))Nr%   )r   r%   )r   r%   r%   )rL   rJ   )r   N)©r   r   rM   rM   r   )rL   rL   rL   )r   r:   r   r   r   )	r   r   rA   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    rN   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   rI   rK   rE   r   )r   r:   r   r	   r   )rA   Zlb_trueZub_truer   r   r   r   r   Útest_old_bounds_to_new›   s   

&rO   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      @rP   Tç      ð?g       @F)Únumpyr:   r   r   r   ÚevalÚreprr   r   r   Zkeep_feasible)r:   r   ÚargsrA   Zbounds2r   r   r   Útest_bounds_repr«   s   
 ,üörV   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 )NrF   rQ   )r   r   )r   Ú
isinstancer   r   Zndarrayr   )Úbr   r   r   Útest_Bounds_arrayº   s   rY   )r<   rR   r   Znumpy.testingr   r   Zscipy.sparseZsparser7   Zscipy.optimize._constraintsr   r   r   r   r   r	   r
   r   rC   rG   rN   rO   rV   rY   r   r   r   r   Ú<module>   s    $<)