§
    ¢é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))é   g6Z£5Z£Õ?g&RÍ’®UÅ?)r   gªªªªªªæ?g„‘ùÂZÕ?)r   g«ªªªªªò?gZrò!à?)r   gÝÝÝÝÝÝý?gŽ4e~u–å?)r   g}ðÁ|@gG)È¿ë?)ç¸…ëQ¸@g}ôõ¦P…é?gâ1ÖÜaÅ?)r	   gj�6Ðiû?gÖ´N¶`�Õ?)r	   g Ó:m @g9Æ¬Ü7à?)r	   gí5’¦T@g÷4¸+ç�å?)r	   g¿ŽÔëH½%@gü¬ñJ]Ðê?)ç¢E¶óýdL@g€9LŒ;w3@g¤ñž'~VÅ?)r
   gä^s!iFE@gì¥Õ/°XÕ?)r
   gÙÎ÷SãR@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 )z«If 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"   € õ 	•X˜a ‘^”^ 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$   € õ 	•X˜a ‘^”^¥R¤VÑ,Ô,Ð,Ð,Ð,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>   € õ 	•X˜a Ñ%Ô% sÑ+Ô+Ð+Ý•X˜a Ñ&Ô&¨Ñ-Ô-Ð-Ð-Ð-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*   € õ" 	•X˜a ‘^”^ c¨!¡e¨Q¡YÑ/Ô/Ð/Ð/Ð/r   )r   g €à7yÃAC)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"   € õ 	•X˜a ‘^”^ 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ˆØ˜�BœH Q¨™NœNÑ*Ñ+ˆÝ�  A™œ¨°uÀ1Ð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Ø	
ˆBŒF�AˆØ	Œ��Aˆð'ñ ô ð(ð (ñ	ô ð(ð „[×Ò˜S < 2¤<°°1Ñ#5Ô#5¸¼°wÀÄÈÌÐ"OÑPÔPØ„[×Ò˜S H B¤H¨U¡O¤OÔ$CÐ#CØ$, B¤H¨U¡O¤OÔ$FÐ#FØ$&¤F 7¨B¬F°B´Fð#<ñ =ô =ð-ð -ñ=ô =ñ QÔPð-ð
 „[×Ò˜S 1 h b¤h¨u¡o¤oÔ&9¸2¼6Ð"BÑCÔCð.ð .ñ DÔCð.ð
 „[×Ò˜UØ	
ˆHˆBŒH�U‰OŒOÔ+Ð,Ø	
ˆHˆBŒH�U‰OŒOÔ.Ð/Ø	
ˆHˆBŒH�U‰OŒOÔ.¨qÑ0Ð1ØØ	ˆŒ�%‰ŒÔ	˜aÐ Ø	ˆŒ�%‰ŒÔ	˜g˜bœg h b¤h¨u¡o¤oÔ&9Ñ:Ô:Ð;ð%ñ ô ð	0ð 	0ñô ð	0ð „[×Ò˜UØØØ	ˆŒ��”˜%‘”Ô$Ñ	%Ô	% x r¤x°¡¤Ô':Ð;ð%ñ ô ð
	*ð 	*ñô ð
	*ð „[×Ò˜UØ	ˆŒ�%‰ŒÔ	˜h˜bœh u™oœoÔ1Ð2Ø	ˆŒ�%‰ŒÔ	˜qÑ	  ( "¤(¨5¡/¤/Ô"5Ð6Ø	ˆŒ�%‰ŒÔ	˜h˜bœh u™oœoÔ1°AÑ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   