o
    tBhM8                     @   sN  d dl Z 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	 zd dl
Z
W n	 ey/   Y nw G dd dZG dd dZG dd	 d	ZG d
d dZdd ZG dd dZdd Zdd Zdd Zdd Zdd Zzd dlZd dlZdeev ZW n ey   dZY nw G dd deZdejdfd d!Zd"d# Zd$d% Z d)d'd(Z!dS )*    N)assert_)assert_func_equalc                   @   s8   e Zd ZdZej ejddfddZdd Zdd Zd	S )
ArgzGenerate a set of numbers on the real axis, concentrating on
    'interesting' regions and covering all orders of magnitude.

    Tc                 C   sf   ||krt d|tj krdttj }|tjkr#dttj }||| _| _||| _| _	d S )Nz#a should be less than or equal to bg            ?)

ValueErrornpinffinfofloatmaxabinclusive_ainclusive_b)selfr   r   r   r    r   q/var/www/html/riverr-enterprise-integrations-main/venv/lib/python3.10/site-packages/scipy/special/_mptestutils.py__init__   s   
zArg.__init__c                 C   s  |dk rt d|d dkr|d }|}n|d }|d }|dkr/tt|t||}n|dkr?|dk r?t|||}n|dkr^tj|d|dd}tdt||}t||f}nw|dkr|dkrtd||}|jdkrzt|d }	nd}	tjd|	|dd}t||f}nH|d dkr|d }
|
}n|d }
|
d }tjdd|dd}|jdkrt|d }	nd}	tjd|	|
dd}tdt||}t|||f}t|S )	Nr   za should be positive      
   F)endpointi)r   r   logspacelog10linspacehstacksizesort)r   r   r   nnlogptsnlinptsptslinptslogptsrightnlogpts1nlogpts2logpts1logpts2r   r   r   _positive_values&   sF   


zArg._positive_valuesc           	      C   s  | j | j}}||krt|S | js|d7 }| js|d7 }|d dkr+|d }|}n|d }|d }|dkrA| |||}g }n)|dkrRg }| | | | }n| d||}| d| |d  }|dd }t|ddd |f}| js|dd }| js|dd }|S )z%Return an array containing n numbers.r   r   r   N)r   r   r   zerosr   r   r)   r   )	r   r   r   r   n1n2posptsnegptsr!   r   r   r   values^   s6   
z
Arg.valuesN)	__name__
__module____qualname____doc__r   r   r   r)   r0   r   r   r   r   r      s
    8r   c                   @   s   e Zd Zdd Zdd ZdS )FixedArgc                 C   s   t || _d S N)r   asarray_values)r   r0   r   r   r   r      s   zFixedArg.__init__c                 C   s   | j S r6   )r8   )r   r   r   r   r   r0         zFixedArg.valuesNr1   r2   r3   r   r0   r   r   r   r   r5      s    r5   c                   @   s:   e Zd Zeej ej eejejfddZdd ZdS )
ComplexArgc                 C   s$   t |j|j| _t |j|j| _d S r6   )r   realimagr   r   r   r   r   r   r      s   zComplexArg.__init__c                 C   sX   t tt|}| j|}| j|d }|d d d f d|d d d f    S )Nr   y              ?)intr   floorsqrtr<   r0   r=   ravel)r   r   mxyr   r   r   r0      s   (zComplexArg.valuesN)r1   r2   r3   complexr   r   r   r0   r   r   r   r   r;      s    &r;   c                   @   s   e Zd ZdddZdd ZdS )	IntArg  c                 C   s   || _ || _d S r6   )r   r   r>   r   r   r   r      s   
zIntArg.__init__c                 C   sh   t | j| jtd|d  |d t}tdd}t	tj
||f }||| jk|| jk @  }|S )Nr   r      )r   r   r   r0   r   astyper?   r   arangeuniquer_)r   r   v1v2vr   r   r   r0      s
   ,zIntArg.valuesN)rH   rI   r:   r   r   r   r   rG      s    
rG   c                 C   s   t | tjr|  }|S t| }tdd | D }||t|  td }dd t	| |D }t
tjtj|  |dj}|S )Nc                 S   s   g | ]}t |trd ndqS )g      ?g      ?
isinstancer;   ).0specr   r   r   
<listcomp>   s    zget_args.<locals>.<listcomp>r   c                 S   s   g | ]	\}}| |qS r   )r0   )rU   rV   rC   r   r   r   rW      s    r*   )rT   r   ndarraycopylenr7   sumrL   r?   ziparraybroadcast_arraysix_reshapeT)argspecr   argsnargsmsr   r   r   get_args   s   	 rf   c                   @   s.   e Zd Z				dddZdd	 Zd
d ZdS )
MpmathDataNHz>YnFTc                 C   s  |d u r!zt tjdd}W n ty   d}Y nw |rdnd}|| _|| _|| _|| _|| _	|| _
|| _|	| _|
| _|| _t| jtjrQt| jjtj| _ntdd | jD | _|
| _|| _|rh|dkrnt|d	d }|rt|dkrzt|d	d }|| _|| _d S )
NSCIPY_XSLOW0Fi  i  c                 S   s   g | ]}t |tqS r   rS   )rU   argr   r   r   rW      s    z'MpmathData.__init__.<locals>.<listcomp>z<lambda>r1   )r?   osenvirongetr   
scipy_funcmpmath_funcarg_specdpsprecr   rtolatolignore_inf_signnan_okrT   r   rX   
issubdtypedtypecomplexfloating
is_complexanydistinguish_nan_and_infgetattrnameparam_filter)r   rp   rq   rr   r   rs   rt   r   ru   rv   rw   r~   rx   r   is_xslowr   r   r   r      s8   
zMpmathData.__init__c           
         sl  t jd tjj}tjjtjj	}}zjd ur!jg}ndg}j	d ur.j	tj_	t 
|jt jr=tdd  ndd  dd t|D ]J\}}|tj_ztj fdd	|d
jjjjjjd
 W  n0 ty   |t|d krt \}}}	|j|	ur||	|Y qIw W ||tj_tj_	d S W ||tj_tj_	d S ||tj_tj_	w )Ni     c                 S      t t| S r6   )mpmathmpcrF   rD   r   r   r   mptype      z MpmathData.check.<locals>.mptypec                 S   r   r6   )r   mpfr
   r   r   r   r   r      r   c                 S   s,   t | jddt | j  krtjS t| jS )NgؗҜ<r   )absr=   r<   r   nan	mpf2floatr   r   r   r   pytype   s   
z MpmathData.check.<locals>.pytypec                     s   j t |  S r6   )rq   map)r   r   r   r   r   r   <lambda>  s    z"MpmathData.check.<locals>.<lambda>F)
vectorizedru   rv   rw   r~   rx   r   r   )r   randomseedrf   rr   r   r   mprs   rt   ry   rz   r{   mpc2complex	enumerater   rp   ru   rv   rw   r~   rx   r   AssertionErrorrZ   sysexc_info__traceback__with_traceback)
r   argarrold_dpsold_precdps_listjrs   tpvaluetbr   r   r   check   sP   




	

*	zMpmathData.checkc                 C   s   | j r	d| jf S d| jf S )Nz<MpmathData: %s (complex)>z<MpmathData: %s>)r|   r   )r   r   r   r   __repr__  s   zMpmathData.__repr__)
NNNNrh   ri   FTTN)r1   r2   r3   r   r   r   r   r   r   r   rg      s    
';rg   c                  O   s   t | i |}|  d S r6   )rg   r   )r   kwdr   r   r   assert_mpmath_equal  s   r   c                 C   s   t jjdd| S )Nz8    Test not yet functional (too slow), needs more work.)reason)pytestmarkskipfuncr   r   r   nonfunctional_tooslow"  s   r   c                 C   s   t tj| ddddS )z
    Convert an mpf to the nearest floating point number. Just using
    float directly doesn't work because of results like this:

    with mp.workdps(50):
        float(mpf("0.99999999999999999")) = 0.9999999999999999

       r   	min_fixed	max_fixed)r
   r   nstrr   r   r   r   r   *  s   	r   c                 C   s   t t| jt| jS r6   )rF   r   r<   r=   r   r   r   r   r   6  s   r   c                    s   dd  fdd}|S )Nc                 S   s   t | tjr
t| S t| S r6   )rT   r   r   rF   r
   r   r   r   r   tofloat;  s   ztrace_args.<locals>.tofloatc               	      sz   t jdtt| f  t j  z | i |}t jd|  W t jd t j  |S t jd t j  w )Nz%r: z-> %r
)r   stderrwritetupler   flush)r   r   rr   r   r   r   wrapA  s   

ztrace_args.<locals>.wrapr   r   r   r   r   r   
trace_args:  s   
r   	setitimerFc                   @   s   e Zd ZdS )TimeoutErrorN)r1   r2   r3   r   r   r   r   r   V  s    r   r   Tc                    s6   t r|rdd  fdd}|S  fdd}|S )a  
    Decorator for setting a timeout for pure-Python functions.

    If the function does not return within `timeout` seconds, the
    value `return_val` is returned instead.

    On POSIX this uses SIGALRM by default. On non-POSIX, settrace is
    used. Do not use this with threads: the SIGALRM implementation
    does probably not work well. The settrace implementation only
    traces the current thread.

    The settrace implementation slows down execution speed. Slowdown
    by a factor around 10 is probably typical.
    c                 S   s   t  r6   )r   )signumframer   r   r   sigalrm_handlerj  r9   z%time_limited.<locals>.sigalrm_handlerc                    s    fdd}|S )Nc               
      s   t  t j}t t j z2z | i |W W t t jd t  t j| S  ty@    Y W t t jd t  t j| S w t t jd t  t j| w )Nr   )signalSIGALRMr   ITIMER_REALr   )r   r   old_handler)r   
return_valr   timeoutr   r   r   n  s   (time_limited.<locals>.deco.<locals>.wrapr   r   r   r   r   r   r   decom  s   
ztime_limited.<locals>.decoc                    s    fdd}|S )Nc               	      sz   t     fddt z%z| i |W W td  S  ty6   td   Y W td  S w td  w )Nc                    s   t     krt S r6   )timer   )r   eventrl   )
start_timer   tracer   r   r   ~  s   z7time_limited.<locals>.deco.<locals>.wrap.<locals>.trace)r   r   settracer   r   r   )r   r   r   )r   r   r   r   {  s   

r   r   r   )r   r   r   r   r   z  s   )POSIX)r   r   use_sigalrmr   r   r   r   time_limitedZ  s   r   c                        fdd}|S )z9Decorate function to return nan if it raises an exceptionc                     s*   z | i |W S  t y   tj Y S w r6   )	Exceptionr   r   r   r   r   r   r     s
   
zexception_to_nan.<locals>.wrapr   r   r   r   r   exception_to_nan     r   c                    r   )z1Decorate function to return nan if it returns infc                     s"    | i |}t |st jS |S r6   )r   isfiniter   )r   r   rR   r   r   r   r     s   
zinf_to_nan.<locals>.wrapr   r   r   r   r   
inf_to_nan  r   r   FFg<c              	   C   sx  zt |  W n ty   t| } Y nw t |}t | |kr"tdg }t|D ]*}ztt| | ||  ||t||   k W q( tyR   || Y q(w t	t
t|}dg}|dt || |D ]A}tj| | |ddd}	tj|| |ddd}
|| dkrd}nt| | ||  ||  }t|d}|d||	|
| ql|rtd	d
| dS dS )z}
    Compare lists of mpmath.mpf's or mpmath.mpc's directly so that it
    can be done to higher precision than double.

    zLengths of inputs not equal. z4Bad results ({} out of {}) for the following points:r   r   r      z{}: {} != {} (rdiff {})Fr   N)rZ   	TypeErrorlistr   ranger   r   fabsappendr?   r   r   r   formatr   join)resstdrv   ru   r   failureskndigitsmsgresrepstdreprdiffr   r   r   mp_assert_allclose  s>   4r   )r   r   )"rm   r   r   numpyr   numpy.testingr   r   scipy.special._testutilsr   r   ImportErrorr   r5   r;   rG   rf   rg   r   r   r   r   r   posixr   dirr   r   r   r   r   r   r   r   r   r   r   r   <module>   sF    oj4

