U
    »mœd5
  ã                   @   sB   d Z ddlmZ ddlmZ ddlZddlm	Z	 G dd„ dƒZ
dS )z5
Unit tests for optimization routines from _root.py.
é    )Úassert_)ÚraisesN©Úrootc                   @   s,   e Zd Zdd„ Zdd„ Zdd„ Zdd„ Zd	S )
ÚTestRootc                 C   sÂ   dd„ }dd„ }dD ]¨}|dkr"q|dkr0|}nd }t |ddg|d	|d
�}t |ddg|d|d
�}d|||jƒ||jƒf }t|j|ƒ t|j|ƒ tt||jƒƒ ¡ t||jƒƒ ¡ k |ƒ qd S )Nc                 S   s&   | \}}t  |d d |d d g¡S ©Né   é   ©ÚnpÚarray©ÚzÚxÚy© r   úX/home/sam/Atlas/atlas_env/lib/python3.8/site-packages/scipy/optimize/tests/test__root.pyÚfunc   s    z)TestRoot.test_tol_parameter.<locals>.funcc                 S   s.   | \}}t  d|d  dgdd|d  gg¡S )Nr   é   r   r
   r   r   r   r   Údfunc   s    z*TestRoot.test_tol_parameter.<locals>.dfunc)ÚhybrÚlmÚbroyden1Úbroyden2ÚandersonÚdiagbroydenÚkrylov)ÚlinearmixingÚexcitingmixing)r   r   çš™™™™™ñ?g-Cëâ6?)ÚjacZtolÚmethodç      à?z%s: %s vs. %s)r   r   r   ÚsuccessÚabsÚmax)Úselfr   r   r!   r    Zsol1Zsol2Úmsgr   r   r   Útest_tol_parameter   s     $ÿzTestRoot.test_tol_parameterc                 C   s2   dd„ }dD ] }t tjt d¡|d|id� qd S )Nc                 S   s   t | d ƒS ©Nr   )r$   )r   r   r   r   Únorm+   s    z$TestRoot.test_tol_norm.<locals>.norm)r   r   r   r   r   r   r   r   Ztol_norm)r!   Úoptions)r   r   Z
zeros_likeZzeros)r&   r*   r!   r   r   r   Útest_tol_norm)   s
    ÿzTestRoot.test_tol_normc                 C   s    ddd„}t |ddgdd� d S )Nr	   c                 S   s&   | \}}t  |d d |d | g¡S r   r
   )r   Úfr   r   r   r   r   r   ;   s    z=TestRoot.test_minimize_scalar_coerce_args_param.<locals>.funcr   g      ø?)Úargs)r	   r   )r&   r   r   r   r   Ú&test_minimize_scalar_coerce_args_param9   s    
z/TestRoot.test_minimize_scalar_coerce_args_paramc              	   C   s>   G dd„ dƒ}|ƒ }t tƒ� t|ddgdd� W 5 Q R X d S )Nc                   @   s   e Zd Zdd„ Zdd„ ZdS )z!TestRoot.test_f_size.<locals>.func                 S   s
   d| _ d S r)   ©Úcount)r&   r   r   r   Ú__init__E   s    z*TestRoot.test_f_size.<locals>.fun.__init__c                 S   s†   |  j d7  _ | j d s>|d d|d |d  d   d }nD|d d|d |d  d   d d|d |d  d  |d  g}|S )Nr	   é   r   r"   r   g      ð?r0   )r&   r   Úretr   r   r   Ú__call__H   s    
&"ÿz*TestRoot.test_f_size.<locals>.fun.__call__N)Ú__name__Ú
__module__Ú__qualname__r2   r5   r   r   r   r   ÚfunD   s   r9   gš™™™™™¹?g        r   )r!   )Úassert_raisesÚ
ValueErrorr   )r&   r9   ÚFr   r   r   Útest_f_size@   s    
zTestRoot.test_f_sizeN)r6   r7   r8   r(   r,   r/   r=   r   r   r   r   r      s   r   )Ú__doc__Znumpy.testingr   Zpytestr   r:   Únumpyr   Zscipy.optimizer   r   r   r   r   r   Ú<module>   s
   