a
    ˆù»j<0  ã                	   @   sŽ   d dl Z d dlZd dlZd dlmZ d dlZd dlmZ d dl	Z	d dl
mZ g d¢ZG dd„ dƒZdd„ Zd	d
„ Zddd„ZG dd„ dƒZdS )é    N)Ú_pep440)Úassert_)Úwith_special_errorsÚassert_func_equalÚFuncDatac                   @   s   e Zd Zdd„ ZdS )ÚMissingModulec                 C   s
   || _ d S ©N)Úname)Úselfr	   © r   ú>E:\soccer\ml_env\Lib\site-packages\scipy/special/_testutils.pyÚ__init__   s    zMissingModule.__init__N)Ú__name__Ú
__module__Ú__qualname__r   r   r   r   r   r      s   r   c                 C   sR   t | ƒtkr"tjj| j› d�d�S tjjt | j	¡t 
|¡k | j› d|› d�d�S )Nz is not installed©Úreasonz version >= z	 required)Útyper   ÚpytestÚmarkÚskipr	   Zskipifr   ÚparseÚ__version__ÚVersionr   )ÚmoduleZmin_verr   r   r   Úcheck_version   s    þr   c                    s   t  ˆ ¡‡ fdd„ƒ}|S )zc
    Enable special function errors (such as underflow, overflow,
    loss of precision, etc.)
    c                     s>   t jdd�� ˆ | i |¤Ž}W d   ƒ n1 s00    Y  |S )NÚraise©Úall)ÚscÚerrstate)ÚaÚkwÚres©Úfuncr   r   Úwrapper*   s    ,z$with_special_errors.<locals>.wrapper)Ú	functoolsÚwraps)r%   r&   r   r$   r   r   %   s    r   TFc                 C   s´   t |dƒrt|ƒ}t |¡}|jdkr6|d d …d f }|jd }t |dƒrX|}d }|}n&tj||f }tt||jd ƒƒ}d }t| |tt|ƒƒ|||||||	||
|d�}| 	¡  d S )NÚnexté   r   )
Úresult_columnsÚresult_funcÚrtolÚatolÚparam_filterÚknownfailureÚnan_okÚ
vectorizedÚignore_inf_signÚdistinguish_nan_and_inf)
ÚhasattrÚlistÚnpÚasarrayÚndimÚshapeZc_Úranger   Úcheck)r%   ÚresultsZpointsr-   r.   r/   r0   r2   Údtyper1   r3   r4   ÚnparamsÚdatar+   r,   Úfdatar   r   r   r   7   s*    




ûr   c                   @   s4   e Zd ZdZddd„Zdd„ Zdd	d
„Zdd„ ZdS )r   aí  
    Data set for checking a special function.

    Parameters
    ----------
    func : function
        Function to test
    data : numpy array
        columnar data to use for testing
    param_columns : int or tuple of ints
        Columns indices in which the parameters to `func` lie.
        Can be imaginary integers to indicate that the parameter
        should be cast to complex.
    result_columns : int or tuple of ints, optional
        Column indices for expected results from `func`.
    result_func : callable, optional
        Function to call to obtain results.
    rtol : float, optional
        Required relative tolerance. Default is 5*eps.
    atol : float, optional
        Required absolute tolerance. Default is 5*tiny.
    param_filter : function, or tuple of functions/Nones, optional
        Filter functions to exclude some parameter ranges.
        If omitted, no filtering is done.
    knownfailure : str, optional
        Known failure error message to raise when the test is run.
        If omitted, no exception is raised.
    nan_ok : bool, optional
        If nan is always an accepted result.
    vectorized : bool, optional
        Whether all functions passed in are vectorized.
    ignore_inf_sign : bool, optional
        Whether to ignore signs of infinities.
        (Doesn't matter for complex-valued functions.)
    distinguish_nan_and_inf : bool, optional
        If True, treat numbers which contain nans or infs as
        equal. Sets ignore_inf_sign to be True.

    NFTc                 C   sÒ   || _ || _|
| _t|dƒs"|f}t|ƒ| _|d urdt|dƒsD|f}t|ƒ| _|d ur|d}t|ƒ‚n|d urtd | _ntdƒ‚|| _|| _	|| _
t|dƒsž|f}|| _|	| _|| _|| _|| _|| _| jsÎd| _d S )NÚ__len__z5Only result_func or result_columns should be providedz7Either result_func or result_columns should be providedT)r%   r@   Údatanamer5   ÚtupleÚparam_columnsr+   Ú
ValueErrorr,   r-   r.   r/   r0   r1   r2   r3   r4   )r
   r%   r@   rE   r+   r,   r-   r.   r/   r0   rC   r1   r2   r3   r4   Úmessager   r   r   r   �   s:    





zFuncData.__init__c                 C   s\   t  |t j¡st  t¡}t  |¡}| j| j }}|d u rBd|j }|d u rTd|j	 }||fS )Né   )
r7   Ú
issubdtypeZinexactr>   ÚfloatZfinfor-   r.   ÚepsZtiny)r
   r>   Úinfor-   r.   r   r   r   Úget_tolerances¤   s    



zFuncData.get_tolerancesc           )         sœ  t  dt¡}ˆjr tjˆjd� ˆ du r.ˆj‰ |du r>ˆ j}n
ˆ  |¡‰ ˆ 	|¡\}}ˆj
r²t ˆ jd ftj¡}tˆjˆj
ƒD ](\‰}|r€|t|ˆ dd…ˆf ƒƒM }q€ˆ | ‰ g ‰tˆjƒD ]†\}	‰t ˆ¡rútˆjƒ‰ˆ ˆ dd…ˆf  t¡¡ qÀ|�r0|	t|ƒk �r0ˆ ˆ dd…ˆf  ||	 ¡¡ qÀˆ ˆ dd…ˆf ¡ qÀd‡‡fdd„	}
|
ˆjƒ}ˆjdu�rˆt‡ fdd„ˆjD ƒƒ}n6d}ˆj�r°t|ƒd	k�r°t |d ¡}|
ˆj|d
�}tt|ƒt|ƒkƒ tt||ƒƒD �]´\}\}}t  |jtj!¡�sˆj"�r2t #|¡}t #|¡}t #|¡}t #|¡}n(t $|¡}t $|¡}t %|¡}t %|¡}t |¡}t |¡}tj&dd��f t '|¡}d|t (|¡ < t '|| ¡}d|t (|¡ < |t '|¡ }d|t (|¡ < W d  ƒ n1 �sè0    Y  ||||  k}||k}||k}||k}||@ |@ |@  }|j)}ˆj�r^|| M }|| M }|||B  *¡ 8 }ˆj+�s¨ˆj�s¨t #|¡} t #|¡}!| |@ ||!@ B }"||" M }||" *¡ 8 }t ,|¡�ràdg}#|# d||  -¡  ¡ |# d||  -¡  ¡ |# dt *|¡||f ¡ t .|¡d D ]t‰tˆƒ‰‡fdd„}$d /t0|$ˆƒ¡}%d /t0|$|ƒ¡}&d /t0|$|ƒ¡}'|$|ƒ}(|# |%› d|&› d|'› d|(› d�¡ �qtdd /|#¡ƒ �qàdS )z,Check the special function against the data.Zerrisinstancer   Nr   c              	      s�   ˆj r| ˆŽ }nlg }ttˆd ƒƒD ]L‰ |d urF|ˆ  rF| tj¡ q$| | t‡ ‡fdd„ttˆƒƒD ƒƒŽ ¡ q$t |¡}t|tƒsŒ|f}|S )Nr   c                    s   g | ]}ˆ| ˆ  ‘qS r   r   )Ú.0Úi)ÚjÚparamsr   r   Ú
<listcomp>ß   ó    z?FuncData.check.<locals>.eval_func_at_params.<locals>.<listcomp>)	r2   r;   ÚlenÚappendr7   ÚnanrD   r8   Ú
isinstance)r%   Ú	skip_maskÚgot)rQ   r
   ©rP   r   Úeval_func_at_paramsÖ   s    
,

z+FuncData.check.<locals>.eval_func_at_paramsc                    s   g | ]}ˆ d d …|f ‘qS r   r   )rN   Zicol)r@   r   r   rR   ë   rS   z"FuncData.check.<locals>.<listcomp>r*   )rX   Úignorer   Ú zMax |adiff|: %gzMax |rdiff|: %gzCBad results (%d out of %d) for the following points (in output %d):c                    s   dt j| ˆ  dd� S )Nz%30sé   )Ú	precision)r7   Zarray2string)ÚxrZ   r   r   Úfmt.  s    zFuncData.check.<locals>.fmtz  z => z != z	  (rdiff ú)FÚ
)N)1ÚoperatorÚmethodcallerÚAssertionErrorr0   r   Zxfailr@   r>   ZastyperM   r/   r7   Zonesr:   Zbool_ÚziprE   r6   Ú	enumerateÚiscomplexobjÚintÚimagrU   ÚcomplexrT   r%   r+   rD   r1   Úisnanr,   r   rI   Zcomplexfloatingr3   ÚisinfZisposinfZisneginfr    ÚabsoluteÚisfiniteÚsizeÚsumr4   ÚanyÚmaxZnonzeroÚjoinÚmap))r
   r@   r>   ZdtypesZ__tracebackhide__r-   r.   Z
param_maskÚfilterÚidxr[   rY   ÚwantedrX   Z
output_numr`   ÚyZpinf_xZpinf_yZminf_xZminf_yZnan_xZnan_yZabs_yÚdiffZrdiffZtol_maskZ	pinf_maskZ	minf_maskZnan_maskZbad_jZpoint_countZinf_xZinf_yZboth_nonfiniteÚmsgra   r!   ÚbÚcÚdr   )r@   rP   rQ   r
   r   r<   ¯   sª    ÿ


"










0




þ&zFuncData.checkc                 C   s\   t  ttt j| jƒƒ¡rd}nd}| jrDd | jj	|t
j | j¡¡S d| jj	› |› d�S dS )z%Pretty-printing, esp. for Nose outputz
 (complex)r]   z<Data for {}{}: {}>z
<Data for ú>N)r7   rs   r6   rv   ri   rE   rC   Úformatr%   r   ÚosÚpathÚbasename)r
   Z
is_complexr   r   r   Ú__repr__7  s    ÿzFuncData.__repr__)NNNNNNNFTFT)NNN)r   r   r   Ú__doc__r   rM   r<   r…   r   r   r   r   r   X   s   (    ý
#
 	r   )	NNNNTNFFT)r‚   r'   rd   Z
scipy._libr   Únumpyr7   Znumpy.testingr   r   Zscipy.specialZspecialr   Ú__all__r   r   r   r   r   r   r   r   r   Ú<module>   s"       ý
!