
    ^Mhi8                        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 	 d dlZn# e$ r Y nw xY w G d d          Z G d d          Z G d	 d
          Z G d d          Zd Z G d d          Zd Zd Zd Zd Zd Z	 d dlZd ee          v Zn# e$ r dZY nw xY w G d de          Zdej        dfdZd Z d Z!d dZ"dS )!    N)zip_longest)assert_)assert_func_equalc                   D    e Zd ZdZej         ej        ddfdZd Zd ZdS )ArgzGenerate a set of numbers on the real axis, concentrating on
    'interesting' regions and covering all orders of magnitude.

    Tc                 2   ||k    rt          d          |t          j         k    r!dt          j        t                    j        z  }|t          j        k    r!dt          j        t                    j        z  }||c| _        | _        ||c| _        | _	        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   s        Z/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/scipy/special/_mptestutils.py__init__zArg.__init__   s    q55BCCC<<RXe__((A;;BHUOO''AA-8+*$***    c                 h   |dk     rt          d          |dz  dk    r|dz  }|}n
|dz  }|dz   }|dk    r<t          j        t          j        |          t          j        |          |          }n|dk    r|dk     rt          j        |||          }n|dk    rXt          j        |d|d          }t          j        dt          j        |          |          }t          j        ||f          }n+|dk    rs|dk    rmt          j        d||          }|j        dk    rt          j        |d                   }	nd}	t          j        d|	|d          }t          j        ||f          }n|dz  dk    r|dz  }
|
}n
|dz  }
|
dz   }t          j        dd|d          }|j        dk    rt          j        |d                   }	nd}	t          j        d|	|
d          }t          j        dt          j        |          |          }t          j        |||f          }t          j        |          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logpts2s                 r   _positive_valueszArg._positive_values'   s3   q553444 q5A::dGGGdGkG77+bhqkk28A;;::CCUUq2vv+aA&&CCUU [B%@@@F[BHQKK99F)VV,--CC!VVR [Aw//F{Q++[eWuEEEF)VV,--CC
 {a"A:#"A:#a<[B%@@@F{Q++k#uhGGGGk!RXa[[(;;G)Wfg677Cws||r   c                 >   | j         | j        }}||k    rt          j        |          S | j        s|dz  }| j        s|dz  }|dz  dk    r|dz  }|}n
|dz  }|dz   }|dk    r|                     |||          }g }n`|dk    rg }|                     | | |           }n=|                     d||          }|                     d| |dz              }|dd         }t          j        |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&   s	            r   valuesz
Arg.values_   si   vtv1668A;; 	FA 	FAq5A::ABBBABaB66**1a33FFF!VVF++QBA666FF**1a44F++Ar26:::FABBZFi"v.// 	abb'C 	crc(C
r   N)	__name__
__module____qualname____doc__r   r   r   r.   r6    r   r   r   r      sf         
 &BF$ 	F 	F 	F 	F6 6 6p# # # # #r   r   c                       e Zd Zd Zd ZdS )FixedArgc                 8    t          j        |          | _        d S N)r   asarray_values)r   r6   s     r   r   zFixedArg.__init__   s    z&))r   c                     | j         S r?   )rA   )r   r#   s     r   r6   zFixedArg.values   s
    |r   Nr7   r8   r9   r   r6   r;   r   r   r=   r=      s2        * * *    r   r=   c                   t    e Zd Z eej         ej                    eej        ej                  fdZd ZdS )
ComplexArgc                     t          |j        |j                  | _        t          |j        |j                  | _        d S r?   )r   realimagr   r   r   s      r   r   zComplexArg.__init__   s0    ''	''			r   c                 2   t          t          j        t          j        |                              }| j                            |          }| j                            |dz             }|d d d f         d|d d d f         z  z                                   S )Nr   y              ?)intr   floorsqrtrG   r6   rH   ravel)r   r#   mxys        r   r6   zComplexArg.values   s    $$%%IQIQU##!!!D&	BqaaayL(//111r   N)r7   r8   r9   complexr   r   r   r6   r;   r   r   rE   rE      s`         "&26'22ggbfbf6M6M ( ( ( (2 2 2 2 2r   rE   c                       e Zd ZddZd ZdS )IntArg  c                 "    || _         || _        d S r?   )r   r   rI   s      r   r   zIntArg.__init__   s    r   c                 n   t          | j        | j                                      t	          d|dz  z   |dz
                                          t                    }t          j        dd          }t          j	        t          j
        ||f                   }||| j        k    || j        k     z           }|S )Nr   r      )r   r   r   r6   r   astyperK   r   arangeuniquer_)r   r#   v1v2vs        r   r6   zIntArg.values   s      ''A1Hac(:(:;;BB3GGYr1IbeBFm$$qDF{q46z*+r   N)rU   rV   rC   r;   r   r   rT   rT      s7               r   rT   c                    t          | t          j                  r|                                 }nt	          |           }t          j        d | D                       }||t          |          z  z                      t                    dz   }d t          | |          D             }t          j
        t          j        t          j        |                                |d          j        }|S )Nc                 @    g | ]}t          |t                    rd ndS )g      ?g      ?
isinstancerE   ).0specs     r   
<listcomp>zget_args.<locals>.<listcomp>   s+    NNNdJtZ009SScNNNr   r   c                 >    g | ]\  }}|                     |          S r;   )r6   )rf   rg   rO   s      r   rh   zget_args.<locals>.<listcomp>   s&    ???74A???r   r0   )re   r   ndarraycopylenr@   sumr[   rK   ziparraybroadcast_arraysix_reshapeT)argspecr#   argsnargsmss        r   get_argsrx      s    '2:&& 
R||~~GZNNgNNN
 
 "SWW*o%%c**Q.??c'2.>.>???x+RVT];<<DDUBOOQKr   c                   *    e Zd Z	 	 	 	 d	dZd Zd ZdS )

MpmathDataNHz>YnFTc                    |G	 t          t          j                            dd                    }n# t          $ r d}Y nw xY w|rdnd}|| _        || _        || _        || _        || _	        || _
        || _        |	| _        |
| _        || _        t          | j        t           j                  r/t!          j        | j        j        t           j                  | _        n#t-          d | j        D                       | _        |
| _        || _        |r|dk    rt1          |dd           }|r|dk    rt1          |dd           }|| _        || _        d S )	NSCIPY_XSLOW0Fi  i  c                 8    g | ]}t          |t                    S r;   rd   )rf   args     r   rh   z'MpmathData.__init__.<locals>.<listcomp>   s"    FFFC,,FFFr   z<lambda>r7   )rK   osenvirongetr
   
scipy_funcmpmath_funcarg_specdpsprecr#   rtolatolignore_inf_signnan_okre   r   rj   
issubdtypedtypecomplexfloating
is_complexanydistinguish_nan_and_infgetattrnameparam_filter)r   r   r   r   r   r   r   r#   r   r   r   r   r   r   is_xslows                  r   r   zMpmathData.__init__   sm    9!rz~~mSAABB ! ! ! ! !)cA$& 			.dmRZ00 	 mDM,?ASTTDOO!FFFFF DO  /'>$ 	9tz)):z488D 	:tz));
D99D	(s   -2 A Ac                    
 t           j                            d           t           j         j                  }t          j        j        t          j        j	        }}	  j        	 j        g}ndg} j	         j	        t          j        _	        t          j
        |j        t           j                  rt          d 
nd 
d t          |          D ]\  }}|t          j        _        	 t           j        
 fd|d j         j         j         j         j         j        
  
          n]# t.          $ rP |t1          |          d	z
  k    r7t3          j                    \  }}}	|j        |	ur|                    |	          |Y w xY w||ct          j        _        t          j        _	        d S # ||ct          j        _        t          j        _	        w xY w)
Ni     c                 D    t          j        t          |                     S r?   )mpmathmpcrR   rP   s    r   mptypez MpmathData.check.<locals>.mptype   s    !:gajj111r   c                 D    t          j        t          |                     S r?   )r   mpfr   r   s    r   r   z MpmathData.check.<locals>.mptype   s    !:eAhh///r   c                     t          | j                  ddt          | j                  z   z  k    rt          j        S t          | j                  S )NgؗҜ<r   )absrH   rG   r   nan	mpf2floatr   s    r   pytypez MpmathData.check.<locals>.pytype   s=    16{{UAAFO%<<<!v(000r   c                  F      j         t          |                      S r?   )r   map)r   r   r   r   s    r   <lambda>z"MpmathData.check.<locals>.<lambda>	  s$    66*:$*:CNN*K#L#L r   F)
vectorizedr   r   r   r   r   r   r   )r   randomseedrx   r   r#   r   mpr   r   r   r   r   mpc2complex	enumerater   r   r   r   r   r   r   r   AssertionErrorrl   sysexc_info__traceback__with_traceback)r   argarrold_dpsold_precdps_listjr   tpvaluetbr   r   s   `         @@r   checkzMpmathData.check   s   
	t $-00 #IM69>4	>x# H:4y$!%	
 }V\2+=>> 1$2 2 2 20 0 01 1 1 $H-- $ $3 #	$%LLLLLL#(!Y!Y(,(<040L#{%)%6    E% $ $ $CMM!O++(+E2 .b88"'"6"6r":"::# ,+$ -4X)FIM69>>>GX)FIM69>====s3    B
F0 +AD.,F0 .AFF0 FF0 0%Gc                 <    | j         rd| j         dS d| j         dS )Nz<MpmathData: z (complex)>>)r   r   )r   s    r   __repr__zMpmathData.__repr__  s2    ? 	09499999/49////r   )
NNNNr{   r|   FTTN)r7   r8   r9   r   r   r   r;   r   r   rz   rz      sT        ?C>D@D+/') ') ') ')R<> <> <>|0 0 0 0 0r   rz   c                  F    t          | i |}|                                 d S r?   )rz   r   )r   kwds      r   assert_mpmath_equalr   %  s%    AAGGIIIIIr   c                 R    t          j                            d          |           S )Nz8    Test not yet functional (too slow), needs more work.)reason)pytestmarkskip)funcs    r   nonfunctional_tooslowr   *  s1    ;I   
  r   c                 L    t          t          j        | 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   s    r   r   r   4  s%     Qa1===>>>r   c                 j    t          t          | j                  t          | j                            S r?   )rR   r   rG   rH   r   s    r   r   r   @  s&    9QV$$i&7&7888r   c                      d  fd}|S )Nc                 r    t          | t          j                  rt          |           S t	          |           S r?   )re   r   r   rR   r   r   s    r   tofloatztrace_args.<locals>.tofloatE  s-    a$$ 	1::88Or   c                     t           j                            t          t	          |                     d           t           j                                         	  | i |}t           j                            d|           t           j                            d           t           j                                         nB# t           j                            d           t           j                                         w xY w|S )N: z-> 
)r   stderrwritetupler   flush)r   r   rr   r   s      r   wrapztrace_args.<locals>.wrapK  s    
E#gq//22888999
	a2AJ[1[[)))JT"""J JT"""Js   *C ?Dr;   )r   r   r   s   ` @r   
trace_argsr   D  s8      	 	 	 	 	 	 Kr   	setitimerFc                       e Zd ZdS )TimeoutErrorN)r7   r8   r9   r;   r   r   r   r   _  s        Dr   r   r	   Tc                 @     t           r|rd  fd}n f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                     t                      r?   )r   )signumframes     r   sigalrm_handlerz%time_limited.<locals>.sigalrm_handlers  s    .. r   c                       fd}|S )Nc                  4   t          j         t           j                  }t          j        t           j                   	  | i |t          j        t           j        d           t          j         t           j        |           S # t          $ rC cY t          j        t           j        d           t          j         t           j        |           S w xY w# t          j        t           j        d           t          j         t           j        |           w xY w)Nr   )signalSIGALRMr   ITIMER_REALr   )r   r   old_handlerr   
return_valr   timeouts      r   r   z(time_limited.<locals>.deco.<locals>.wrapw  s    $mFNOLL !3W===?4>b>> $V%7;;;M&.+>>>>	 $ & & &%%%$V%7;;;M&.+>>>>	& $V%7;;;M&.+>>>>s%   B CC CC A Dr;   )r   r   r   r   r   s   ` r   decoztime_limited.<locals>.decov  s3    	? 	? 	? 	? 	? 	? 	? 	? Kr   c                       fd}|S )Nc                  D   t          j                     fdt          j                   	  | i |t          j        d            S # t          $ r- t          j        d            cY t          j        d            S w xY w# t          j        d            w xY w)Nc                 X    t          j                     z
  k    rt                      S r?   )timer   )r   eventr   
start_timer   traces      r   r   z7time_limited.<locals>.deco.<locals>.wrap.<locals>.trace  s(    y{{Z/'99*nn, Lr   )r   r   settracer   )r   r   r   r   r   r   r   s     @@r   r   z(time_limited.<locals>.deco.<locals>.wrap  s    !Y[[
! ! ! ! ! ! ! U###'4>b>>
 L&&&&	 $ & & &L&&&%%%L&&&&	& L&&&&s#   A  B/B	 BB	 	Br;   )r   r   r   r   s   ` r   r   ztime_limited.<locals>.deco  s.    ' ' ' ' ' ' ' Kr   )POSIX)r   r   use_sigalrmr   r   s   ``  @r   time_limitedr   c  sr      ! !	! 	! 	!	 	 	 	 	 	 	 		 	 	 	 	 	" Kr   c                       fd}|S )z9Decorate function to return nan if it raises an exceptionc                  N    	  | i |S # t           $ r t          j        cY S w xY wr?   )	Exceptionr   r   )r   r   r   s     r   r   zexception_to_nan.<locals>.wrap  s@    	4>b>>! 	 	 	6MMM	s    $$r;   r   r   s   ` r   exception_to_nanr     s#        
 Kr   c                       fd}|S )z1Decorate function to return nan if it returns infc                  X     | i |}t          j        |          st           j        S |S r?   )r   isfiniter   )r   r   ra   r   s      r   r   zinf_to_nan.<locals>.wrap  s0    D!NrNN{1~~ 	6Mr   r;   r   s   ` r   
inf_to_nanr    s#        
 Kr   FFg<c                 L   g }t          t          | |                    D ]f\  }\  }}||t          d          t          j        ||z
            ||t          j        |          z  z   k    r|                    |||f           gt          |          }|dk    rt          t          t          j
        |                              }	dg}
|
                    d| d|dz    d           |D ]\  }}}t          j        ||	dd	          }t          j        ||	dd	          }|dk    rd
}n/t          j        ||z
  |z            }t          j        |d          }|
                    | d| d| d| d           t          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.
    Nz,Lengths of inputs res and std are not equal.r    zBad results (z out of r   z) for the following points:r   r      r   z != z (rdiff )Fr   )r   r   r
   r   fabsappendrl   rK   r   r   r   r   r   join)resstdr   r   failureskresvalstdvalnfailndigitsmsgresrepstdreprdiffs                 r   mp_assert_allcloser    s   
 H(S#)>)>?? 1 1FF>V^KLLL;v''$fk&6I6I1I*IIIOOQ/000MMEqyyc"(4..))**d

T5TT!a%TTTUUU!) 	E 	EAvv[AKKKF[AKKKF{{Vf_f$<==E1--JJ!CCvCC6CC5CCCDDDDtyy~~&&&&& yr   )r   r  )#r   r   r   	itertoolsr   numpyr   numpy.testingr   r   scipy.special._testutilsr   r   ImportErrorr   r=   rE   rT   rx   rz   r   r   r   r   r   r   dirr   r   r   r   r   r   r  r  r;   r   r   <module>r     s   				 



  ! ! ! ! ! !     ! ! ! ! ! !  6 6 6 6 6 6	MMMM 	 	 	D	l l l l l l l l^       	2 	2 	2 	2 	2 	2 	2 	2
 
 
 
 
 
 
 
   l0 l0 l0 l0 l0 l0 l0 l0^  
  	? 	? 	?9 9 9  (MMMCCKK'EE   EEE	 	 	 	 	9 	 	 	 T 1 1 1 1h    ' ' ' ' ' 's   - 55B B('B(