U
    »mœdN
  ã                   @   s‚   d Z ddlmZ ddlmZ edd„ edƒD ƒƒZdZ	d\Z
Zd	\ZZZd
d„ eD ƒZdd„ Zdd„ Zdd„ Zdd„ Zdd„ ZdS )a8  
Test Cython optimize zeros API functions: ``bisect``, ``ridder``, ``brenth``,
and ``brentq`` in `scipy.optimize.cython_optimize`, by finding the roots of a
3rd order polynomial given a sequence of constant terms, ``a0``, and fixed 1st,
2nd, and 3rd order terms in ``args``.

.. math::

    f(x, a0, args) =  ((args[2]*x + args[1])*x + args[0])*x + a0

The 3rd order polynomial function is written in Cython and called in a Python
wrapper named after the zero function. See the private ``_zeros`` Cython module
in `scipy.optimize.cython_optimze` for more information.
é    N)Ú_zerosc                 c   s   | ]}d |d  V  qdS )g       Àg      $@N© )Ú.0Úxr   r   úb/home/sam/Atlas/atlas_env/lib/python3.8/site-packages/scipy/optimize/tests/test_cython_optimize.pyÚ	<genexpr>   s     r   é
   )ç        r	   g      ð?)r	   g       @)çü©ñÒMbP?r
   r   c                 C   s   g | ]}| d  ‘qS )gUUUUUUÕ?r   )r   Za0r   r   r   Ú
<listcomp>   s     r   c                   C   s.   t jttt dtttt	t
tt¡ƒtt
d� d S )NÚbisect©ZrtolZatol©ÚnptÚassert_allcloseÚEXPECTEDÚlistr   Zloop_exampleÚA0ÚARGSÚXLOÚXHIÚXTOLÚRTOLÚMITRr   r   r   r   Útest_bisect*   s    ÿ ûr   c                   C   s.   t jttt dtttt	t
tt¡ƒtt
d� d S )NZridderr   r   r   r   r   r   Útest_ridder5   s    ÿ ûr   c                   C   s.   t jttt dtttt	t
tt¡ƒtt
d� d S )NZbrenthr   r   r   r   r   r   Útest_brenth@   s    ÿ ûr   c                   C   s.   t jttt dtttt	t
tt¡ƒtt
d� d S )NZbrentqr   r   r   r   r   r   Útest_brentqK   s    ÿ ûr   c                  C   sl   t  td ft ttttt¡} t	j
td | d ttd� t	 d| d ¡ t	 d| d ¡ t	 d| d ¡ d S )	Nr   Úrootr   é   Z
iterationsé   ZfuncallsZ	error_num)r   Zfull_output_exampler   r   r   r   r   r   r   r   r   r   Zassert_equal)Úoutputr   r   r   Útest_brentq_full_outputV   s         ÿr"   )Ú__doc__Znumpy.testingÚtestingr   Zscipy.optimize.cython_optimizer   ÚtupleÚranger   r   r   r   r   r   r   r   r   r   r   r   r"   r   r   r   r   Ú<module>   s   
