Ë
    âQ(h|'  ã                   ó\   — d dl Z d dlZd dlmZmZ d dlmZm	Z
  G d„ d«      Z G d„ d«      Zy)é    N)Úassert_equalÚassert_allclose)Ú	_iv_ratioÚ_iv_ratio_cc                   ó  — e Zd Zej                  j                  dg d¢«      d„ «       Zej                  j                  ddej                  dfej                  ddfg«      d„ «       Z	ej                  j                  ddej                   ej                  ej                  g«      ej                  j                  d	 ej                  e«      j                    ej                  e«      j                   ej                   ej                  ej                  g«      d
„ «       «       Zej                  j                  ddd ej                  e«      j                   ej                  g«      d„ «       Zej                  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                  j                  ddd ej$                   ej                  e«      j                   «       ej                  e«      j                   fg«      d„ «       Zej                  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y)ÚTestIvRatioúv,x,r))ç      à?çUUUUUUÅ?g.a0R#Å?)r
   çUUUUUUÕ?gˆ<)ª“Ô?)r
   r
   góŠV×S“Ý?)r
   çUUUUUUå?gPò]k(¦â?)r
   ç¬ªªªªªê?gjDŒ­Õå?)é   ç6Z£5Z£Õ?g&RÍ’®UÅ?)r   çªªªªªªæ?g„‘ùÂZÕ?)r   ç«ªªªªªò?gZrò!à?)r   çÝÝÝÝÝÝý?gŽ4e~u–å?)r   ç}ðÁ|@gG)È¿ë?)ç¸…ëQ¸@ç}ôõ¦P…é?gâ1ÖÜaÅ?)r   çj�6Ðiû?gÖ´N¶`�Õ?)r   ç Ó:m @g9Æ¬Ü7à?)r   çí5’¦T@g÷4¸+ç�å?)r   ç¿ŽÔëH½%@gü¬ñJ]Ðê?)ç¢E¶óýdL@ç€9LŒ;w3@g¤ñž'~VÅ?)r   çä^s!iFE@gì¥Õ/°XÕ?)r   çÙÎ÷SãR@g“_®8à?)r   çP²ÂTø`@g¿ø )Xå?)r   çÿ>ÝïÓ=s@g\h*¬ê?c                 ó6   — t        t        ||«      |dd¬«       y)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 (0.5, 1, 2.34, 56.789):
            xs = _sample(5, v=v)
            for x in xs:
                print(f"({v}, {x}, {float(iv_ratio_mp(v,x))}),")
        ç¼‰Ø—²Ò¼<r   ©ÚrtolÚatolN)r   Úiv_ratio©ÚselfÚvÚxÚrs       ú_/var/www/skyplay_api_hub/venv/lib/python3.12/site-packages/scipy/special/tests/test_iv_ratio.pyÚtest_against_reference_valuesz)TestIvRatio.test_against_reference_values   s   € ô` 	œ  A›¨°¸AÖ>ó    r   r   c                 ó0   — t        t        ||«      |«       y©ziIf exactly one of v or x is inf and the other is within domain,
        should return 0 or 1 accordingly.N©r   r&   r'   s       r,   Útest_infzTestIvRatio.test_inf@   s   € ô 	”X˜a “^ QÕ'r.   r)   ç\�Âõ(\ß?r*   c                 óL   — t        t        ||«      t        j                  «       y©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_nanI   s   € ô 	”X˜a “^¤R§V¡VÕ,r.   r
   c                 ó\   — t        t        |d«      d«       t        t        |d«      d«       y)z?If x is +/-0.0, return x to ensure iv_ratio is an odd function.ç        ç       €Nr1   ©r(   r)   s     r,   Útest_zero_xzTestIvRatio.test_zero_xR   s&   € ô 	”X˜a Ó% sÔ+Ü”X˜a Ó&¨Õ-r.   úv,xé   ©ç@Œµx¯Dé{   c                 ó<   — t        t        ||«      d|z  |z  «       y)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.
        r
   Nr1   r8   s      r,   Útest_tiny_xzTestIvRatio.test_tiny_xX   s   € ô" 	”X˜a “^ c¨!¡e¨Q¡YÕ/r.   ©r   g €à7yÃAC©rB   g¥\Ãñ)c=Hc                 ó0   — t        t        ||«      d«       y)aA  If x is much greater than v, the bounds

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

        collapses to R ~= 1.  Test against this asymptotic expression.
        ç      ð?Nr1   r8   s      r,   Útest_huge_xzTestIvRatio.test_huge_xk   s   € ô 	”X˜a “^ SÕ)r.   é   c                 óx   — ||z  }|dt        j                  d|«      z   z  }t        t        ||«      |dd¬«       y)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)r6   Úhypotr   r&   ©r(   r)   r*   ÚtÚexpecteds        r,   Útest_huge_v_xzTestIvRatio.test_huge_v_x{   s:   € ð  �‰EˆØ˜œBŸH™H Q¨›NÑ*Ñ+ˆÜœ  A›¨°uÀ1ÖEr.   N©Ú__name__Ú
__module__Ú__qualname__ÚpytestÚmarkÚparametrizer-   r6   Úinfr2   r7   ÚfinfoÚfloatÚsmallest_normalÚsmallest_subnormalr9   Úmaxr>   ÚsqrtrE   rJ   rQ   © r.   r,   r   r      s"  „ à‡[�[×Ñ˜Wò 'ó ñ,?ó-ð,?ð8 ‡[�[×Ñ˜WØ	
ˆB�F‰F�AˆØ	�‰��Aˆð'ó ñ(ó	ð(ð
 ‡[�[×Ñ˜S 4¨"¯&©&¨°"·&±&¸"¿&¹&Ð"AÓBØ‡[�[×Ñ˜S H B§H¡H¨U£O×$CÑ$CÐ#CØ$, B§H¡H¨U£O×$FÑ$FÐ#FØ$&§F¡F 7¨B¯F©F°B·F±Fð#<ó =ñ-ó=ó Cð-ð
 ‡[�[×Ñ˜S 3¨¨8¨2¯8©8°E«?×+>Ñ+>ÀÇÁÐ"GÓHñ.ó Ið.ð
 ‡[�[×Ñ˜UØ	
ˆHˆB�H‰H�U‹O×+Ñ+Ð,Ø	
ˆHˆB�H‰H�U‹O×.Ñ.Ð/Ø	
ˆHˆB�H‰H�U‹O×.Ñ.¨qÑ0Ð1ØØ	ˆ�‰�%‹×	Ñ	˜aÐ Ø	ˆ�‰�%‹×	Ñ	˜g˜bŸg™g h b§h¡h¨u£o×&9Ñ&9Ó:Ð;ð%ó ñ	0óð	0ð ‡[�[×Ñ˜UØØØ	ˆ�‰��—‘˜%“×$Ñ$Ó	% x r§x¡x°£×':Ñ':Ð;ð%ó ñ
	*óð
	*ð ‡[�[×Ñ˜UØ	ˆ�‰�%‹×	Ñ	˜h˜bŸh™h u›o×1Ñ1Ð2Ø	ˆ�‰�%‹×	Ñ	˜qÑ	  ( "§(¡(¨5£/×"5Ñ"5Ð6Ø	ˆ�‰�%‹×	Ñ	˜h˜bŸh™h u›o×1Ñ1°AÑ5Ð6ð%ó ñ
Fóñ
Fr.   r   c                   ó  — e Zd Zej                  j                  dg d¢«      d„ «       Zej                  j                  ddej                  dfej                  ddfg«      d„ «       Z	ej                  j                  ddej                   ej                  ej                  g«      ej                  j                  d	 ej                  e«      j                    ej                  e«      j                   ej                   ej                  ej                  g«      d
„ «       «       Zej                  j                  ddd ej                  e«      j                   ej                  g«      d„ «       Zej                  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                  j                  ddd ej$                   ej                  e«      j                   «       ej                  e«      j                   fg«      d„ «       Zej                  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y)ÚTestIvRatioCr	   ))r
   r   g{´çs+·ê?)r
   r   gÿ»aë*¶å?)r
   r
   g†ºTV6á?)r
   r   g`D)¯³Ú?)r
   r   g,wç¤ÒUÔ?)r   r   gv«L[”ªê?)r   r   g>7öžRå?)r   r   gLá¼Ùß?)r   r   gä–5ÓÔ?)r   r   gäZ³ß ñÃ?)r   r   gˆ3zÊˆ§ê?)r   r   g•¥Ø¤O?å?)r   r   gŽ÷s¦F�ß?)r   r   g–�¨1ÄÔ?)r   r   gL9ÔŠ¾Ä?)r   r   g—Cv`ªê?)r   r   g
-è§Så?)r   r   gÚ@É£Žùß?)r   r   g‚þ­OÕ?)r   r    g�^V³ßOÅ?c                 ó6   — t        t        ||«      |dd¬«       y)z8The reference values are one minus those of TestIvRatio.çVçž¯Ò<r   r#   N©r   Ú
iv_ratio_cr'   s       r,   r-   z*TestIvRatioC.test_against_reference_values’   s   € ô0 	œ
 1 aÓ(¨!°%¸aÖ@r.   r   r   c                 ó0   — t        t        ||«      |«       yr0   ©r   rf   r'   s       r,   r2   zTestIvRatioC.test_inf¬   s   € ô 	”Z  1Ó% qÕ)r.   r)   r3   r*   c                 óL   — t        t        ||«      t        j                  «       yr5   )r   rf   r6   r7   r8   s      r,   r9   zTestIvRatioC.test_nanµ   s   € ô 	”Z  1Ó%¤r§v¡vÕ.r.   r
   c                 ó\   — t        t        |d«      d«       t        t        |d«      d«       y)zIf x is +/-0.0, return 1.r;   rI   r<   Nrh   r=   s     r,   r>   zTestIvRatioC.test_zero_x¾   s&   € ô 	”Z  3Ó'¨Ô-Ü”Z  4Ó(¨#Õ.r.   r?   r@   rA   c                 óB   — t        t        ||«      dd|z  |z  z
  «       y)a=  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 1-R ~= 1-x/2v.  Test against this asymptotic expression.
        rI   r
   Nrh   r8   s      r,   rE   zTestIvRatioC.test_tiny_xÄ   s!   € ô" 	”Z  1Ó% s¨C°©E°1©9¡}Õ5r.   rF   rG   c                 óB   — t        t        ||«      |dz
  |z  dd¬«       y)aK  If x is much greater than v, the bounds

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

        collapses to 1-R ~= (v-0.5)/x.  Test against this asymptotic expression.
        r
   rd   r   r#   Nre   r8   s      r,   rJ   zTestIvRatioC.test_huge_x×   s!   € ô 	œ
 1 aÓ(¨1¨S©5°!©)¸%ÀaÖHr.   rK   c                 ó~   — ||z  }d|dt        j                  d|«      z   z  z
  }t        t        ||«      |dd¬«       y)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 1 - R ~= 1 - 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)r6   rM   r   rf   rN   s        r,   rQ   zTestIvRatioC.test_huge_v_xç   s@   € ð  �‰EˆØ�q˜A¤§¡¨¨A£Ñ.Ñ/Ñ/ˆÜœ
 1 aÓ(¨(¸ÀQÖGr.   NrR   r`   r.   r,   rb   rb   �   s&  „ à‡[�[×Ñ˜Wò 'ó ñ,Aó-ð,Að ‡[�[×Ñ˜WØ	
ˆB�F‰F�AˆØ	�‰��Aˆð'ó ñ*ó	ð*ð
 ‡[�[×Ñ˜S 4¨"¯&©&¨°"·&±&¸"¿&¹&Ð"AÓBØ‡[�[×Ñ˜S H B§H¡H¨U£O×$CÑ$CÐ#CØ$, B§H¡H¨U£O×$FÑ$FÐ#FØ$&§F¡F 7¨B¯F©F°B·F±Fð#<ó =ñ/ó=ó Cð/ð
 ‡[�[×Ñ˜S 3¨¨8¨2¯8©8°E«?×+>Ñ+>ÀÇÁÐ"GÓHñ/ó Ið/ð
 ‡[�[×Ñ˜UØ	
ˆHˆB�H‰H�U‹O×+Ñ+Ð,Ø	
ˆHˆB�H‰H�U‹O×.Ñ.Ð/Ø	
ˆHˆB�H‰H�U‹O×.Ñ.¨qÑ0Ð1ØØ	ˆ�‰�%‹×	Ñ	˜aÐ Ø	ˆ�‰�%‹×	Ñ	˜g˜bŸg™g h b§h¡h¨u£o×&9Ñ&9Ó:Ð;ð%ó ñ	6óð	6ð ‡[�[×Ñ˜UØØØ	ˆ�‰��—‘˜%“×$Ñ$Ó	% x r§x¡x°£×':Ñ':Ð;ð%ó ñ
	Ióð
	Ið ‡[�[×Ñ˜UØ	ˆ�‰�%‹×	Ñ	˜h˜bŸh™h u›o×1Ñ1Ð2Ø	ˆ�‰�%‹×	Ñ	˜qÑ	  ( "§(¡(¨5£/×"5Ñ"5Ð6Ø	ˆ�‰�%‹×	Ñ	˜h˜bŸh™h u›o×1Ñ1°AÑ5Ð6ð%ó ñ
Hóñ
Hr.   rb   )rV   Únumpyr6   Únumpy.testingr   r   Úscipy.special._ufuncsr   r&   r   rf   r   rb   r`   r.   r,   ú<module>rq      s2   ðó Û ß 7÷÷AFñ AF÷HiHò iHr.   