U
    /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   C/tmp/pip-unpacked-wheel-9gxwnfpp/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_like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      ?r1   )r&   r   retr   r   r   __call__H   s    
&"z*TestRoot.test_f_size.<locals>.fun.__call__N)__name__
__module____qualname__r3   r6   r   r   r   r   funD   s   r:   g?g        r   )r!   )assert_raises
ValueErrorr   )r&   r:   Fr   r   r   test_f_size@   s    
zTestRoot.test_f_sizeN)r7   r8   r9   r(   r-   r0   r>   r   r   r   r   r      s   r   )__doc__Znumpy.testingr   Zpytestr   r;   Znumpyr   Zscipy.optimizer   r   r   r   r   r   <module>   s
   