
    xf                     P    d Z ddlmZmZ ddlmZmZ ddl	Z
ddlmZ  G d d      Zy)z5
Unit tests for optimization routines from _root.py.
    )assert_assert_equal)raiseswarnsNrootc                   *    e Zd Zd Zd Zd Zd Zd Zy)TestRootc           	         d }d }dD ]  }|dv r|dv r|}nd }t        |ddg|d|      }t        |ddg|d	|      }| d
 ||j                         d ||j                         }t        |j                  |       t        |j                  |       t        t	         ||j                              j                         t	         ||j                              j                         k  |        y )Nc                 R    | \  }}t        j                  |dz  dz
  |dz  dz
  g      S N      nparrayzxys      A/usr/lib/python3/dist-packages/scipy/optimize/tests/test__root.pyfuncz)TestRoot.test_tol_parameter.<locals>.func   /    DAq88QTAXq!tax011    c                 Z    | \  }}t        j                  d|dz  z  dgdd|dz  z  gg      S )Nr      r   r   r   s      r   dfuncz*TestRoot.test_tol_parameter.<locals>.dfunc   s7    DAq88a1fa[1a1f+677r   )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msgs           r   test_tol_parameterzTestRoot.test_tol_parameter   s    	2	80 	F;;'s3iSd6JDs3iSc&IDHBtDFF|nE$tvv,@CDLL#&DLL#&CTVV%))+c$tvv,.?.C.C.EE!	r   c                 |    d }dD ]4  }t        t        j                  t        j                  d      |d|i       6 y )Nc                     t        | d         S Nr   )r-   )r   s    r   normz$TestRoot.test_tol_norm.<locals>.norm+   s    qt9r   )r&   r#   r%   r"   r    r!   r$   r   tol_norm)r*   options)r   r   
zeros_likezeros)r/   r7   r*   s      r   test_tol_normzTestRoot.test_tol_norm)   s<    	! 		,F F#T*,		,r   c                 ,    dd}t        |ddgd       y )Nc                 R    | \  }}t        j                  |dz  dz
  |dz  |z
  g      S r   r   )r   fr   r   s       r   r   z=TestRoot.test_minimize_scalar_coerce_args_param.<locals>.func;   r   r   r'   g      ?)argsr   r   )r/   r   s     r   &test_minimize_scalar_coerce_args_paramz/TestRoot.test_minimize_scalar_coerce_args_param9   s    	2 	TC:C(r   c                      G d d      } |       }t        t              5  t        |ddgd       d d d        y # 1 sw Y   y xY w)Nc                       e Zd Zd Zd Zy)!TestRoot.test_f_size.<locals>.func                     d| _         y r6   count)r/   s    r   __init__z*TestRoot.test_f_size.<locals>.fun.__init__E   s	    
r   c                     | xj                   dz  c_         | j                   dz  s|d   d|d   |d   z
  dz  z  z   dz
  }|S |d   d|d   |d   z
  dz  z  z   dz
  d|d   |d   z
  dz  z  |d   z   g}|S )Nr      r   r+   r   g      ?rG   )r/   r   rets      r   __call__z*TestRoot.test_f_size.<locals>.fun.__call__H   s    

a


QA$!qt'9!99C?C
 
 aD3!A$1+!);#;;cA!A$1+!!33ad:<C 
r   N)__name__
__module____qualname__rI   rM    r   r   funrE   D   s    	r   rR   皙?g        r   )r*   )assert_raises
ValueErrorr   )r/   rR   Fs      r   test_f_sizezTestRoot.test_f_size@   sB    	 	 E:& 	-S#Jt,	- 	- 	-s	   ;Ac                 &   d d fd}t        j                  d      }t        |dd      }d}t        t        |	      5  t        |dd
      }d d d        t        t        |	      5  t        ||ddd
      }d d d        t        j                  |j                         t        j                  |j                         |j                  |j                  cxu r|j                  cxu rdu sJ  J y # 1 sw Y   xY w# 1 sw Y   xY w)Nc                 ^    d| d   z  d| d   dz  z  z
  dz   d| d   dz  z  d| d   z  z   dz
  gS )	Nr   r   g      ?r   r   
   rS   rK   rQ   r   ignoreds     r   rR   z#TestRoot.test_gh_10370.<locals>.fun[   sI    adFT!A$'\)B.AaD!Ga!f0Dq0HIIr   c                 *    dd| d   z  gd| d   z  dggS )Nr   r+   r   g?r   rK   rQ   r[   s     r   gradz$TestRoot.test_gh_10370.<locals>.grad^   s%    ad
OcAaDj!_55r   c                 (     | |       | |      fS )NrQ   )r   r\   rR   r^   s     r   fun_gradz(TestRoot.test_gh_10370.<locals>.fun_grada   s    q'?DG$444r   r   rA   r$   )r@   r*   z'Method krylov does not use the jacobian)match)r@   r*   r(   T)r   r;   r   assert_warnsRuntimeWarningr   r   r,   )	r/   r`   x0refmessageres1res2rR   r^   s	          @@r   test_gh_10370zTestRoot.test_gh_10370W   s    	J	6	5 XXa[3h7;.8 	GRd8FD	G.8 	L"4dKD	L 	TVVSUU#TVVSUU#||t||Bs{{BdBBBBB	G 	G	L 	Ls   C;0D;DDN)rN   rO   rP   r3   r<   rB   rW   ri   rQ   r   r   r
   r
      s    :, )-.Cr   r
   )__doc__numpy.testingr   r   pytestr   rT   r   rb   numpyr   scipy.optimizer   r
   rQ   r   r   <module>ro      s&    0 A  dC dCr   