o
    Eb5
                     @   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 ]T}|dv rq
|dv r|}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      npZarrayzxy r   A/usr/lib/python3/dist-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?)jacZtolmethod      ?z%s: %s vs. %s)r   r   r   Z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   ;   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_param9   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__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 }|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__H   s   
$"z*TestRoot.test_f_size.<locals>.fun.__call__N)__name__
__module____qualname__r1   r4   r   r   r   r   funD   s    r8   g?g        r   )r!   )assert_raises
ValueErrorr   )r%   r8   Fr   r   r   test_f_size@   s
   
"zTestRoot.test_f_sizeN)r5   r6   r7   r'   r+   r.   r<   r   r   r   r   r      s
    r   )__doc__Znumpy.testingr   Zpytestr   r9   Znumpyr   Zscipy.optimizer   r   r   r   r   r   <module>   s    