o
    \h.                     @   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   [/home/air/segue/gemini/backup/venv/lib/python3.10/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u 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	   skipifr   parse__version__Versionr   )module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    |S 1 sw   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r|d d d f }|jd }t |dr,|}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shapec_ranger   check)r'   resultspointsr/   r0   r1   r2   r4   dtyper3   r5   r6   nparamsdatar-   r.   fdatar   r   r   r   7   s*   




r   c                   @   s<   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r2t|ds"|f}t|| _|d ur1d}t|n|d ur:d | _ntd|| _|| _	|| _
t|dsO|f}|| _|	| _|| _|| _|| _|| _| jsid| _d S d S )N__len__z5Only result_func or result_columns should be providedz7Either result_func or result_columns should be providedT)r'   rD   datanamer7   tupleparam_columnsr-   
ValueErrorr.   r/   r0   r1   r2   r3   r4   r5   r6   )r
   r'   rD   rI   r-   r.   r/   r0   r1   r2   rG   r3   r4   r5   r6   messager   r   r   r      s>   





zFuncData.__init__c                 C   s\   t |t jst t}t |}| j| j}}|d u r!d|j }|d u r*d|j	 }||fS )N   )
r9   
issubdtypeinexactrB   floatfinfor/   r0   epstiny)r
   rB   infor/   r0   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
rYt jd ftj}tjj
D ]\}|rT|t| ddf M }q@ |  g tjD ]A\}	tr}tj ddf t q`|r|	t|k r ddf ||	  q` ddf  q`dfdd	}
|
j}jdurt fddjD }nd}jrt|d	krt|d }|
j|d
}tt|t|k tt||D ]\\}\}}t |jtj!sj"rt#|}t#|}t#|}t#|}nt$|}t$|}t%|}t%|}t|}t|}tj&dd3 t'|}d|t(| < t'|| }d|t(| < |t'| }d|t(| < W d   n	1 snw   Y  ||||  k}||k}||k}||k}||@ |@ |@  }|j)}jr|| M }|| M }|||B * 8 }j+sΈjst#|} t#|}!| |@ ||!@ B }"||" M }||"* 8 }t,|rHdg}#|#d|| - d |#d|| - d |#dt*|||f  t.|d D ]:tfdd}$d/t0|$}%d/t0|$|}&d/t0|$|}'|$|}(|#|% d|& d|' d|( d qtdd/|# qdS )z,Check the special function against the data.errisinstancer   Nr   c              	      s   j r|  }n6g }ttd D ]& |d ur#|  r#|tj q|| t fddttD   qt|}t|tsF|f}|S )Nr   c                    s   g | ]}|   qS r   r   ).0i)jparamsr   r   
<listcomp>   s    z?FuncData.check.<locals>.eval_func_at_params.<locals>.<listcomp>)	r4   r>   lenappendr9   nanrH   r:   
isinstance)r'   	skip_maskgot)rY   r
   rX   r   eval_func_at_params   s   
,

z+FuncData.check.<locals>.eval_func_at_paramsc                    s   g | ]
} d d |f qS r   r   )rV   icol)rD   r   r   rZ      s    z"FuncData.check.<locals>.<listcomp>r,   )r_   ignorer    zMax |adiff|: gzMax |rdiff|: zCBad results (%d out of %d) for the following points (in output %d):c                    s   dt j|   dd S )Nz%30s   )	precision)r9   array2string)xra   r   r   fmt.  s   zFuncData.check.<locals>.fmtz  z => z != z	  (rdiff )F
r   )1operatormethodcallerAssertionErrorr2   r   xfailrD   rB   astyperT   r1   r9   onesr<   bool_ziprI   r8   	enumerateiscomplexobjintimagr\   complexr[   r'   r-   rH   r3   isnanr.   r   rM   complexfloatingr5   isinfisposinfisneginfr"   absoluteisfinitesizesumr6   anymaxnonzerojoinmap))r
   rD   rB   dtypes__tracebackhide__r/   r0   
param_maskfilteridxrb   r`   wantedr_   
output_numrj   ypinf_xpinf_yminf_xminf_ynan_xnan_yabs_ydiffrdifftol_mask	pinf_mask	minf_masknan_maskbad_jpoint_countinf_xinf_yboth_nonfinitemsgrk   r#   bcdr   )rD   rX   rY   r
   r   r?      s   


"











	




&zFuncData.checkc                 C   s`   t ttt j| jrd}nd}| jr&d| jj | dt	j
| j dS d| jj | dS )zPretty-printingz
 (complex)re   z
<Data for z: >)r9   r   r8   r   rw   rI   rG   r'   r   ospathbasename)r
   
is_complexr   r   r   __repr__7  s   zFuncData.__repr__)NNNNNNNFTFT)NNN)r   r   r   __doc__r   rT   r?   r   r   r   r   r   r   X   s    (
#
 	r   )	NNNNTNFFT)r   r)   rn   
scipy._libr   numpyr9   numpy.testingr   r   scipy.specialspecialr!   __all__r   r   r   r   r   r   r   r   r   <module>   s$    
!