
    Ug                     L    d dl Z d dlZd dlmZmZ d dlmZ  G d d          Z	dS )    N)assert_equalassert_allclose)	_iv_ratioc                       e Zd Zej                            dg d          d             Zej                            ddej        dfej        ddfg          d             Z	ej                            d ej
        dd          ej         ej        ej        g          ej                            d ej        e          j          ej        e          j         ej         ej        ej        g          d	                         Zej                            dd ej        e          j        ej        g          d
             Zej                            dd ej        e          j        fd ej        e          j        fd ej        e          j        dz  fd ej        e          j        df ej        e          j         ej         ej        e          j                  fg          d             Zej                            ddd ej         ej        e          j                   ej        e          j        fg          d             Zej                            d ej        e          j         ej        e          j        f ej        e          j        dz   ej        e          j        f ej        e          j         ej        e          j        dz  fg          d             ZdS )TestIvRatiozv,x,r))   g6Z5Z?g&R͒U?)r   g?gZ?)r   g?gZr!?)r   g?g4e~u?)r   g}|@gG)ȿ?)Q@g}P?g1a?)r	   gj6i?gִN`?)r	   g:m@g9Ƭ7?)r	   g5T@g4+?)r	   gH%@gJ]?)EdL@g9L;w3@g'~V?)r
   g^s!iFE@g/X?)r
   gSR@g_8?)r
   gPT`@g )X?)r
   g>=s@g\h*?c                 H    t          t          ||          |dd           dS )a  The reference values are computed using mpmath as follows.

        from mpmath import mp
        mp.dps = 100

        def iv_ratio_mp(v, x):
            return mp.besseli(v, x) / mp.besseli(v - 1, x)

        def _sample(n, *, v):
            '''Return n positive real numbers x such that iv_ratio(v, x) are
            roughly evenly spaced over (0, 1).  The formula is taken from [1].

            [1] Banerjee A., Dhillon, I. S., Ghosh, J., Sra, S. (2005).
                "Clustering on the Unit Hypersphere using von Mises-Fisher
                Distributions."  Journal of Machine Learning Research,
                6(46):1345-1382.
            '''
            r = np.arange(1, n+1) / (n+1)
            return r * (2*v-r*r) / (1-r*r)

        for v in (1, 2.34, 56.789):
            xs = _sample(5, v=v)
            for x in xs:
                print(f"({v}, {x}, {float(iv_ratio_mp_float(v,x))}),")
        缉ؗҼ<r   rtolatolN)r   iv_ratioselfvxrs       `/var/www/surfInsights/venv3-11/lib/python3.11/site-packages/scipy/special/tests/test_iv_ratio.pytest_against_reference_valuesz)TestIvRatio.test_against_reference_values   s*    V 	AA>>>>>>    r   r   c                 B    t          t          ||          |           dS )zIf exactly one of v or x is inf and the other is within domain,
        should return 0 or 1 accordingly.

        Also check that the function
        never returns -0.0.Nr   r   r   s       r   test_infzTestIvRatio.test_inf8   s"     	Xa^^Q'''''r   r   r   c                 V    t          t          ||          t          j                   dS )zeIf at least one argument is out of domain, or if v = x = inf,
        the function should return nan.N)r   r   npnanr   r   r   s      r   test_nanzTestIvRatio.test_nanD   s$     	Xa^^RV,,,,,r   c                 ~    t          t          |d          d           t          t          |d          d           dS )z=If x is +/-0.0, return x to agree with the limiting behavior.g        g       Nr   )r   r   s     r   test_zero_xzTestIvRatio.test_zero_xM   s>     	Xa%%s+++Xa&&-----r   zv,x   )@xD{   c                 N    t          t          ||          d|z  |z             dS )a9  If x is much less than v, the bounds

                    x                                 x
        --------------------------- <= R <= -----------------------
        v-0.5+sqrt(x**2+(v+0.5)**2)         v-1+sqrt(x**2+(v+1)**2)

        collapses to R ~= x/2v.  Test against this asymptotic expression.
        g      ?Nr   r   s      r   test_tiny_xzTestIvRatio.test_tiny_xS   s*    " 	Xa^^c!eQY/////r   )r   g 7yAC)r$   g\)c=Hc                 B    t          t          ||          d           dS )a9  If x is much greater than v, the bounds

                    x                                 x
        --------------------------- <= R <= -----------------------
        v-0.5+sqrt(x**2+(v+0.5)**2)         v-1+sqrt(x**2+(v+1)**2)

        collapses to R ~= 1.  Test against this asymptotic expression.
        g      ?Nr   r   s      r   test_huge_xzTestIvRatio.test_huge_xf   s"     	Xa^^S)))))r      c                     ||z  }|dt          j        d|          z   z  }t          t          ||          |dd           dS )a  If both x and v are very large, the bounds

                    x                                 x
        --------------------------- <= R <= -----------------------
        v-0.5+sqrt(x**2+(v+0.5)**2)         v-1+sqrt(x**2+(v+1)**2)

        collapses to R ~= x/(v+sqrt(x**2+v**2).  Test against this asymptotic
        expression, and in particular that no numerical overflow occurs during
        intermediate calculations.
        r   r   r   r   N)r   hypotr   r   )r   r   r   texpecteds        r   test_huge_v_xzTestIvRatio.test_huge_v_xv   sK      EBHQNN*+Au1EEEEEEr   N)__name__
__module____qualname__pytestmarkparametrizer   r   infr   	nextafterr   finfofloatsmallest_normalsmallest_subnormalr    maxr"   sqrtr'   r)   r/    r   r   r   r   	   se       [W ' ' '  "? ?# "?8 [W	
BFA	A'  ( (	 ( [S<2<1#5#5w"OPP[SHBHUOO$C#C$,BHUOO$F#F$&F7BFBF#< = =- -= = QP-
 [S1hbhuoo&926"BCC. . DC.
 [U	
HBHUOO+,	
HBHUOO./	
HBHUOO.q01	%	a 	%	gbghbhuoo&9::;%  	0 	0 	0 [U	%$	%	%xrx':;%  
	* 	* 
	* [U	%	hbhuoo12	%	q	 ("(5//"56	%	hbhuoo1A56%  
F F 
F F Fr   r   )
r3   numpyr   numpy.testingr   r   scipy.special._ufuncsr   r   r   r>   r   r   <module>rB      s         7 7 7 7 7 7 7 7 7 7 7 7 7 7F F F F F F F F F Fr   