o
    Ö­j†  ã                   @   sR   d Z ddlmZmZ ddlZddlmZ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_Úassert_equalN)ÚraisesÚwarns©Úrootc                   @   sV   e Zd Zdd„ Zdd„ Zdd„ Zdd„ Zejj	d	d
„ ƒZ
ej dg d¢¡dd„ ƒZdS )ÚTestRootc                 C   sÈ   dd„ }dd„ }dD ]W}|dv rq
|dv r|}nd }t |ddg|d	|d
�}t |ddg|d|d
�}|› d||jƒ› d||jƒ› �}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   ú\/var/www/html/CropPilot/venv/lib/python3.10/site-packages/scipy/optimize/tests/test__root.pyÚfunc   ó   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?)ÚjacÚtolÚmethodç      à?z: z vs. )r   r   r   ÚsuccessÚabsÚmax)Úselfr   r   r%   r#   Úsol1Ú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   Útol_norm)r%   Úoptions)r   r   Ú
zeros_likeÚzeros)r*   r1   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   <   r   z=TestRoot.test_minimize_scalar_coerce_args_param.<locals>.funcr"   g      ø?)Úargs©r   r   )r*   r   r   r   r   Ú&test_minimize_scalar_coerce_args_param:   s   
z/TestRoot.test_minimize_scalar_coerce_args_paramc                 C   sT   G dd„ dƒ}|ƒ }t tƒ� t|ddgdd� W d   ƒ d S 1 s#w   Y  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__F   s   
z*TestRoot.test_f_size.<locals>.fun.__init__c                 S   sˆ   |  j d7  _ | j d s |d d|d |d  d   d }|S |d d|d |d  d   d d|d |d  d  |d  g}|S )Nr   é   r   r&   r
   g      ð?r;   )r*   r   Úretr   r   r   Ú__call__I   s   
$"ýÿz*TestRoot.test_f_size.<locals>.fun.__call__N)Ú__name__Ú
__module__Ú__qualname__r=   r@   r   r   r   r   ÚfunE   s    rD   çš™™™™™¹?g        r   )r%   )Úassert_raisesÚ
ValueErrorr   )r*   rD   ÚFr   r   r   Útest_f_sizeA   s
   
"ÿzTestRoot.test_f_sizec                    s  dd„ ‰ dd„ ‰‡ ‡fdd„}t  d¡}tˆ |dd	d
�}d}tt|d�� tˆ |dd	ˆd�}W d   ƒ n1 s8w   Y  tt|d�� t||dd	dd�}W d   ƒ n1 sWw   Y  t|j|jƒ t|j|jƒ |j|j  u r}|j  u r}du s€J ‚ J ‚d S )Nc                 S   s@   d| d  d| d d   d d| d d  d| d   d gS )	Nr
   r   g      Ð?r   r   é
   rE   r>   r   ©r   Úignoredr   r   r   rD   ]   s   @z#TestRoot.test_gh_10370.<locals>.func                 S   s    dd| d  gd| d  dggS )Nr
   r&   r   gš™™™™™É?r   r>   r   rK   r   r   r   Úgrad`   s    z$TestRoot.test_gh_10370.<locals>.gradc                    s   ˆ | |ƒˆ| |ƒfS )Nr   rK   ©rD   rM   r   r   Úfun_gradc   s   z(TestRoot.test_gh_10370.<locals>.fun_gradr   r9   r   )r8   r%   z'Method krylov does not use the jacobian)Úmatch)r8   r%   r#   T)r   r5   r   Úassert_warnsÚRuntimeWarningr   r   r'   )r*   rO   Úx0ÚrefÚmessageÚres1Úres2r   rN   r   Útest_gh_10370X   s   
ÿÿ0zTestRoot.test_gh_10370r%   )
r   r   r   r   r   r    r   r!   r   zdf-sanec                 C   s*   dd„ }t |dg|d�}|j|ksJ ‚d S )Nc                 S   s   | d S )Nr   r   r0   r   r   r   r   x   s   z,TestRoot.test_method_in_result.<locals>.funcr   )rS   r%   )r   r%   )r*   r%   r   Úresr   r   r   Útest_method_in_results   s   zTestRoot.test_method_in_resultN)rA   rB   rC   r.   r6   r:   rI   ÚpytestÚmarkÚthread_unsaferX   ÚparametrizerZ   r   r   r   r   r      s    
r   )Ú__doc__Únumpy.testingr   r   r[   r   rF   r   rQ   Únumpyr   Úscipy.optimizer   r   r   r   r   r   Ú<module>   s    