
    ge                     X    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dS )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dS )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                                                            t	           ||j                                                            k     |           d S )Nc                 P    | \  }}t          j        |dz  dz
  |dz  dz
  g          S N      nparrayzxys      ?lib/python3.11/site-packages/scipy/optimize/tests/test__root.pyfuncz)TestRoot.test_tol_parameter.<locals>.func   0    DAq8QTAXq!tax0111    c                 X    | \  }}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   s8    DAq8a1fa[1a1f+67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   sI   	2 	2 	2	8 	8 	80 	 	F;;;''s3iSd6JJJDs3iSc&IIID@@ttDF||@@$$tv,,@@CDL#&&&DL#&&&CTV%%))++c$$tv,,.?.?.C.C.E.EE   !	 	r   c                 x    d }dD ]3}t          t          j        t          j        d          |d|i           4d S )Nc                 ,    t          | d                   S Nr   )r-   )r   s    r   normz$TestRoot.test_tol_norm.<locals>.norm+   s    qt99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)   sb    	 	 	! 		, 		,F F#T*, , , , ,		, 		,r   c                 6    dd}t          |ddgd           d S )Nr   c                 P    | \  }}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   s7    	2 	2 	2 	2 	TC:C((((((r   c                      G d d          } |            }t          t                    5  t          |ddgd           d d d            d S # 1 swxY w Y   d S )Nc                       e Zd Zd Zd ZdS )!TestRoot.test_f_size.<locals>.func                     d| _         d S 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
  }nC|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?CCaD3!A$1+!);#;;cA!A$1+!!33ad:<C 
r   N)__name__
__module____qualname__rI   rM    r   r   funrE   D   s2          	 	 	 	 	r   rR   皙?g        r   )r*   )assert_raises
ValueErrorr   )r/   rR   Fs      r   test_f_sizezTestRoot.test_f_size@   s    	 	 	 	 	 	 	 	 CEE:&& 	- 	-S#Jt,,,,	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	-s   AAAc                 &   d d fd}t          j        d          }t          |dd          }d}t          t          |	          5  t          |dd
          }d d d            n# 1 swxY w Y   t          t          |	          5  t          ||ddd
          }d d d            n# 1 swxY w Y   t          |j        |j                   t          |j        |j                   |j        |j        cxu r|j        cxu rdu sn J d S )Nc                 v    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                 6    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                 4     | |           | |          fS )NrQ   )r   r\   rR   r^   s     r   fun_gradz(TestRoot.test_gh_10370.<locals>.fun_grada   s$    3q'??DDG$4$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 	J 	J	6 	6 	6	5 	5 	5 	5 	5 	5 Xa[[3h777;.888 	G 	GRd8FFFD	G 	G 	G 	G 	G 	G 	G 	G 	G 	G 	G 	G 	G 	G 	G.888 	L 	L"4dKKKD	L 	L 	L 	L 	L 	L 	L 	L 	L 	L 	L 	L 	L 	L 	L 	TVSU###TVSU###|t|BBBBs{BBBBdBBBBBBBBs$   A//A36A3B11B58B5N)rN   rO   rP   r3   r<   rB   rW   ri   rQ   r   r   r
   r
      sd          :, , , ) ) )- - -.C C C C Cr   r
   )__doc__numpy.testingr   r   pytestr   rT   r   rb   numpyr   scipy.optimizer   r
   rQ   r   r   <module>ro      s     0 / / / / / / / A A A A A A A A          dC dC dC dC dC dC dC dC dC dCr   