+
    0i|'                     ^    ^ RI t ^ RIt^ RIHtHt ^ RIHtH	t
  ! R R4      t ! R R4      tR# )    N)assert_equalassert_allclose)	_iv_ratio_iv_ratio_cc                   >  a  ] tR t^t o ]P
                  P                  R. RO4      R 4       t]P
                  P                  R^]P                  ^3]P                  ^^ 3.4      R 4       t
]P
                  P                  RR]P                  ) ]P                  ]P                  .4      ]P
                  P                  R]P                  ! ]4      P                  ) ]P                  ! ]4      P                  ) ]P                  ) ]P                  ]P                  .4      R 4       4       t]P
                  P                  RR^]P                  ! ]4      P"                  ]P                  .4      R	 4       t]P
                  P                  R
^]P                  ! ]4      P                  3^]P                  ! ]4      P                  3^]P                  ! ]4      P                  ^,          3R]P                  ! ]4      P"                  ^3]P                  ! ]4      P"                  ]P&                  ! ]P                  ! ]4      P"                  4      3.4      R 4       t]P
                  P                  R
RR]P&                  ! ]P                  ! ]4      P"                  4      ]P                  ! ]4      P"                  3.4      R 4       t]P
                  P                  R
]P                  ! ]4      P"                  ]P                  ! ]4      P"                  3]P                  ! ]4      P"                  ^,          ]P                  ! ]4      P"                  3]P                  ! ]4      P"                  ]P                  ! ]4      P"                  ^,          3.4      R 4       tRtV tR# )TestIvRatiov,x,r      ?c                6    \        \        W4      VR^ R7       R# )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))}),")
缉ؗҼ<rtolatolN)r   iv_ratioselfvxrs   &&&&_/var/www/html/photoedit/myenv/lib/python3.14/site-packages/scipy/special/tests/test_iv_ratio.pytest_against_reference_values)TestIvRatio.test_against_reference_values   s    ` 	A>    c                0    \        \        W4      V4       R# zaIf 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_infTestIvRatio.test_inf@   s     	Xa^Q'r   r   \(\?r   c                L    \        \        W4      \        P                  4       R# z]If 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_nanTestIvRatio.test_nanI   s     	Xa^RVV,r   c                ^    \        \        VR4      R4       \        \        VR4      R4       R# )z?If x is +/-0.0, return x to ensure iv_ratio is an odd function.        N       r   r   r   s   &&r   test_zero_xTestIvRatio.test_zero_xR   s&     	Xa%s+Xa&-r   v,xc                L    \        \        W4      RV,          V,          4       R# )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 R ~= x/2v.  Test against this asymptotic expression.
r
   Nr   r$   s   &&&r   test_tiny_xTestIvRatio.test_tiny_xX   s    " 	Xa^c!eQY/r   c                0    \        \        W4      R4       R# )a  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.
      ?Nr   r$   s   &&&r   test_huge_xTestIvRatio.test_huge_xk   s     	Xa^S)r   c                    W!,          pV^\         P                  ! ^V4      ,           ,          p\        \        W4      VR^ R7       R# )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   N)r"   hypotr   r   r   r   r   texpecteds   &&&  r   test_huge_v_xTestIvRatio.test_huge_v_x{   s6      EBHHQN*+u1Er    N))r
   UUUUUU?g.a0R#?)r
   UUUUUU?g<)?)r
   r
   gVS?)r
   UUUUUU?gP]k(?)r
   笪?gjD?)   6Z5Z?g&R͒U?)rA   窪?gZ?)rA   竪?gZr!?)rA   ?g4e~u?)rA   }|@gG)ȿ?)Q@}P?g1a?)rG   j6i?gִN`?)rG   :m@g9Ƭ7?)rG   5T@g4+?)rG   翎H%@gJ]?)EdL@9L;w3@g'~V?)rM   ^s!iFE@g/X?)rM   SR@g_8?)rM   PT`@g )X?)rM   >=s@g\h*?@xD{   rA   g 7yACrT   g\)c=H__name__
__module____qualname____firstlineno__pytestmarkparametrizer   r"   infr   r#   finfofloatsmallest_normalsmallest_subnormalr%   maxr+   sqrtr/   r3   r:   __static_attributes____classdictcell____classdict__s   @r   r   r      s    [[W ' ,?-,?8 [[W	
BFFA	A' (	(
 [[S4"&&"&&"&&"AB[[SBHHUO$C$C#C$&HHUO$F$F#F$&FF7BFFBFF#< =-= C-
 [[S3288E?+>+>"GH. I.
 [[U	
BHHUO++,	
BHHUO../	
BHHUO..q01	%		a 	%		bggbhhuo&9&9:;% 	0	0 [[U	%$$	%rxx':':;% 
	*
	* [[U	%		bhhuo112	%		q	 "((5/"5"56	%		bhhuo11A56% 
F
Fr   r   c                   >  a  ] tR t^t o ]P
                  P                  R. RO4      R 4       t]P
                  P                  R^]P                  ^ 3]P                  ^^3.4      R 4       t
]P
                  P                  RR]P                  ) ]P                  ]P                  .4      ]P
                  P                  R]P                  ! ]4      P                  ) ]P                  ! ]4      P                  ) ]P                  ) ]P                  ]P                  .4      R 4       4       t]P
                  P                  RR^]P                  ! ]4      P"                  ]P                  .4      R	 4       t]P
                  P                  R
^]P                  ! ]4      P                  3^]P                  ! ]4      P                  3^]P                  ! ]4      P                  ^,          3R]P                  ! ]4      P"                  ^3]P                  ! ]4      P"                  ]P&                  ! ]P                  ! ]4      P"                  4      3.4      R 4       t]P
                  P                  R
RR]P&                  ! ]P                  ! ]4      P"                  4      ]P                  ! ]4      P"                  3.4      R 4       t]P
                  P                  R
]P                  ! ]4      P"                  ]P                  ! ]4      P"                  3]P                  ! ]4      P"                  ^,          ]P                  ! ]4      P"                  3]P                  ! ]4      P"                  ]P                  ! ]4      P"                  ^,          3.4      R 4       tRtV tR# )TestIvRatioCr	   r
   c                6    \        \        W4      VR^ R7       R# )z8The reference values are one minus those of TestIvRatio.V瞯<r   Nr   
iv_ratio_cr   s   &&&&r   r   *TestIvRatioC.test_against_reference_values   s    0 	
1(!%a@r   c                0    \        \        W4      V4       R# r   r   rp   r   s   &&&&r   r   TestIvRatioC.test_inf   s     	Z%q)r   r   r   r   c                L    \        \        W4      \        P                  4       R# r!   )r   rp   r"   r#   r$   s   &&&r   r%   TestIvRatioC.test_nan   s     	Z%rvv.r   c                ^    \        \        VR4      R4       \        \        VR4      R4       R# )zIf x is +/-0.0, return 1.r(   r2   Nr)   rs   r*   s   &&r   r+   TestIvRatioC.test_zero_x   s&     	Z3'-Z4(#.r   r-   c                Z    \        \        W4      RRV,          V,          ,
          4       R# )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.
r2   r
   Nrs   r$   s   &&&r   r/   TestIvRatioC.test_tiny_x   s    " 	Z%sCE19}5r   c                R    \        \        W4      VR,
          V,          R^ R7       R# )a#  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
   rn   r   Nro   r$   s   &&&r   r3   TestIvRatioC.test_huge_x   s     	
1(1S5!)%aHr   c                    W!,          p^V^\         P                  ! ^V4      ,           ,          ,
          p\        \        W4      VR^ R7       R# )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   N)r"   r6   r   rp   r7   s   &&&  r   r:   TestIvRatioC.test_huge_v_x   s<      EqAA.//
1((QGr   r<   N))r
   r=   g{s+?)r
   r>   ga*?)r
   r
   gTV6?)r
   r?   g`D)?)r
   r@   g,wU?)rA   rB   gvL[?)rA   rC   g>7R?)rA   rD   gL?)rA   rE   g5?)rA   rF   gZ ?)rG   rH   g3zʈ?)rG   rI   gؤO??)rG   rJ   gsF?)rG   rK   g1?)rG   rL   gL9Ԋ?)rM   rN   gCv`?)rM   rO   g
-S?)rM   rP   g@ɣ?)rM   rQ   gO?)rM   rR   g^VO?rS   rV   rW   rX   ri   s   @r   rl   rl      s    [[W ' ,A-,A [[W	
BFFA	A' *	*
 [[S4"&&"&&"&&"AB[[SBHHUO$C$C#C$&HHUO$F$F#F$&FF7BFFBFF#< =/= C/
 [[S3288E?+>+>"GH/ I/
 [[U	
BHHUO++,	
BHHUO../	
BHHUO..q01	%		a 	%		bggbhhuo&9&9:;% 	6	6 [[U	%$$	%rxx':':;% 
	I
	I [[U	%		bhhuo112	%		q	 "((5/"5"56	%		bhhuo11A56% 
H
Hr   rl   )r]   numpyr"   numpy.testingr   r   scipy.special._ufuncsr   r   r   rp   r   rl   r<   r   r   <module>r      s2      7AF AFHiH iHr   