
    (phN                     4   S SK rS SKrS SKJs  Jr  S SKJ	r	  Sr
\R                  " \R                  " S5      \
5      r\R                  " \R                  " S5      \
* 5      r\R                  " S\R                   -  5      r\R$                  " S\R                   -  5      rSr\R                  " S5      r\R                   S-  r\R                   S-  r\R                   S	-  r/ S
QrS rS rSS jrSS jrS rSS jrSS jr SS jr!S r"S r#SS jr$S r%SS jr&g)    N)_derivative         i<         )gSˆBgAAz?g}<ٰj_g#+K?g88CgJ?gllfgUUUUUU?c                     SU -  n[         R                  " U 5      S-  U -
  [        S-  -   U[         R                  " [        X-  5      -  -   $ )N      ?r   )nplog_LOG_2PIpolyval_STIRLING_COEFFS)nrns     G/var/www/html/venv/lib/python3.13/site-packages/scipy/stats/_ksstats.py_log_nfactorial_div_n_pow_nr   ]   sD     
QB66!9Q;?XaZ'"rzz:JBD/Q*QQQ    c                 2    [         R                  " U SS5      $ )z%clips a probability to range 0<=p<=1.        r   )r   clip)ps    r   
_clip_probr   g   s    771c3r   c                 F    [         R                  " X U5      n[        U5      $ )z>Selects either the CDF or SF, and then clips to range 0<=p<=1.)r   wherer   )cdfprobsfprobcdfr   s       r   _select_and_clip_probr    l   s    
v&Aa=r   c                    US:  a  [        SSU5      $ X-  nUS::  a  [        SSU5      $ [        [        R                  " U5      5      nXC-
  nSU-  S-
  n[        R                  " Xf/5      n[        R
                  " SUS-   5      nSXX-  -
  n	[        R                  " U5      n
SnU H  nXUS-
  '   X-  nXS-
  ==   U-  ss'   M     [        SU-  S-
  S5      U-  SXV-  -  -
  nSU-   U-  U	S'   [        SU5       H  nU
SXn-
  S-    X~S-
  S2U4'   M     XSS2S4'   [        R                  " U	SS	9USSS24'   [        R                  " [        R                  " U5      S   5      nU nSnSnUS:  a  US-  (       a  [        R                  " X5      nUU-  n[        R                  " Xw5      nUS-  n[        R                  " XtS-
  US-
  4   5      [        :  a  U[        -  nU[        -  nUS-  nUS:  a  M  XS-
  US-
  4   n[        SU S-   5       H=  nUU-  U -  n[        R                  " U5      [         :  d  M+  U[        -  nU[        -  nM?     US:w  a  [        R"                  " UU5      n[        USU-
  U5      $ )
zComputes the Kolmogorov CDF:  Pr(D_n <= d) using the MTW approach to
the Durbin matrix algorithm.

Durbin (1968); Marsaglia, Tsang, Wang (2003). [1], [3].
r   r         ?r   r   r   N)axis)r    intr   ceilzerosarangeemptymaxrangeflipeyeshapematmulabs_EP128_E128_EM128ldexp)r   dr   ndkhmHintmvwfacjttiHpwrnnexpntHexpntr   s                       r   _kolmogn_DMTWrF   r   s    	Cx$S#s33	
B	Sy$S#s33BGGBKA	A	A	A
!A 99QADaiA
A
C!a%	a%C  
QUS[!	a	!AD&	(B2XAbE1a[!%!)}a%&!) adGwwqq!Ab!eH66"((1+a.!D	
BEF
q&699T%DVOEIIaO!66!E1q5L/"V+KAeOF1W q& 	UAE\A 1a!e_EAI66!9vKAUNE	  zHHQ CE3//r   c                 &   U S:X  a  U* U-
  S-
  X#-   S-
  peOb[        U S-   S5      u  pxUS:X  a7  XqS-   :X  a  X-
  U-
  S-
  X-   U-   S-
  peO/US-
  U-
  U-
  S-
  Xr-   S-
  U-   S-
  peOUS-
  U-
  S-
  Xr-   U-   S-
  pe[        US-   S5      [        Xa5      4$ )z0Compute the endpoints of the interval for row i.r   r   r   )divmodr*   min)	rA   r   llceilfroundfj1j2ip1div2ip1mod2s	            r   _pomeranz_compute_j1j2rQ      s    Avuq"*q.B "!a%+a<a%%!+QVe^a-?B 1r)F2Q6q8H58PST8TBq[2%)7<&+@1+DrAvq>3r:%%r   c                    X-  n[        [        R                  " U5      5      nSX4-
  -  n[        USU-
  5      nUS:  a  SOSnUS:  a  SOSnSUS-   -  n	[        R                  " U	5      n
[        R                  " U	5      n[        R                  " U	5      nSU
S'   SUS'   SUS'   SnX`-  SU-  U -  SSU-  -
  U -  np[        SU	5       H6  nU
US-
     U-  U-  U
U'   UUS-
     U-  U-  UU'   UUS-
     U-  U-  UU'   M8     [        R                  " U	/5      n[        R                  " U	/5      nSUS'   Su  nn[        SXXx5      u  nn[        SSU -  S-   5       H  nUnUUnnUUnnUR                  S5        [        UXXx5      u  nnUS:X  d  USU -  S-   :X  a  U
nOUS-  (       a  UOUnUU-
  S-   nUS:  d  Ma  [        R                  " UUU-
  UU-
  U-    USU 5      nUU-
  nUU-
  S-   nUUUU-    USU& S[        R                  " U5      s=:  a
  [        :  a  O  OU[        -  nU[        -  nUU-   U-
  nM     UU U-
     n[        SU S-   5       H8  n[        R                  " U5      [        :  a  U[        -  nU[        -  nUU-  nM:     US:w  a  [        R                  " UU5      n[!        USU-
  U5      nU$ )	zSComputes Pr(D_n <= d) using the Pomeranz recursion algorithm.

Pomeranz (1974) [2]
r   r   r   r"   r   )r   r   r   N)r%   r   floorrI   r)   r+   r'   rQ   fillconvolver*   r3   r1   r2   r0   r4   r    ) r   xr   trJ   fgrK   rL   npwrsgpower	twogpoweronem2gpowerrD   g_over_ntwo_g_over_none_minus_two_g_over_nr9   V0V1V0sV1srM   rN   rA   k1pwrsln2conv
conv_startconv_lenanss                                    r   _kolmogn_Pomeranzrl      s   $ 	
A	RXXa[	BqvAAsQwAa%QQEs7aFaLEXXe_FI((5/K F1IIaLKNE56S!A#a%!ac'12l1e_1q5MH,q0q	 Q',6:	!$QU+.DDqHA 
 
5'	B	5'	BBqEHC#Aqe<FB1a!eai RBS
'1%@B6Q!a%!)^D!"QIKD2gk7;;r"s(28c>:D#JGDbJBw{H J,ABByM266":&&f(R-C+ !0 QW+C1a!e_66#;6MCUNEq	  zhhsE"
S3Y
4CJr   c           	         US::  a  [        SSUS9$ US:  a  [        SSUS9$ [        R                  " U 5      U-  nUS-  US-  US-  US-  4u  pEpg[        * S-  U-  nU[        :  a  [        SSUS9$ [        R
                  " U5      n	U* n
[        S-  nSU-  SU-  -   nSU-  S	U-  -
  [        -  S-  n[        S
SU-  -
  -  S-  n[        S	SU-  -
  -  S-  n[        SU-  SU-  -   -  S-  n[        SU-  SU-  -
  -  S-  nSU-  SUS-  -  -
  n[        R                  " S5      n[        [        R                  " SU-  [        R                  -  5      5      n[        USS5       Hz  nSU-  S
-
  nUS-  US-  US-  nnn[        R                  " U	SU-  5      n[        R                  " SXU-  -   XU-  -   UU-  -   UUU-  -   UU-  -   UU-  -   /5      nUU-  nUU-  nM|     UU	-  nU[        -  nU[        R                  " USU-  SUS-  -  SUS-  -  /5      -  n[        R
                  " [        * S-  U-  5      n	[        R                   " USS5      nUS-  n["        U-  n[        R                  U-  nU	U-  n [        R$                  " UU -  5      n!U![        [        -  SU-  -  -  n!US==   U!-  ss'   [        R$                  " UU-   UU-
  -  U-  U -  5      n"U"[        [        -  SU-  -  -  n"US==   U"-  ss'   [        R                  " U S-  [        R                   " ['        U5      5      S-  5      n#UU#-  nU(       d  US-  nUS==   S
-  ss'   [%        U5      n$U$$ )a4  Computes the Pelz-Good approximation to Prob(Dn <= x) with 0<=x<=1.

Start with Li-Chien, Korolyuk approximation:
    Prob(Dn <= x) ~ K0(z) + K1(z)/sqrt(n) + K2(z)/n + K3(z)/n**1.5
where z = x*sqrt(n).
Transform each K_(z) using Jacobi theta functions into a form suitable
for small z.
Pelz-Good (1976). [6]
r   r   r   r   r   r   r	         r         @   i      `   iZ   r   r#   H      iP  
   i          @)r    r   sqrt_PI_SQUARED_MIN_LOGexp_PI_FOUR_PI_SIXr'   r%   r&   pir+   powerarray_SQRT2PIr(   _SQRT3sumlen)%r   rV   r   zzsquaredzthreezfourzsixqlogqk1ak1bk2ak2bk2ck3dk3ck3bk3aK0to3maxkr7   r9   msquaredmfourmsixqpowercoeffsksksquaredsqrt3zkspiqpwersk2extrak3extrapowers_of_nKsums%                                        r   _kolmogn_PelzGoodr   #  s    	Cx$S#377Cx$S#377

QA$%qD!Q$1ad$:!He<!h&Dh$S#377
tA )C
/C
d(QY
Cu9q8|#{
2Q
6C
a!h,&
'"
,C
Qh&
'"
,C
cHnsU{2
3b
8C
urDy0
1A
5C
*rAqDy
 CHHQKE rwwrAv~&'D4BEAI !1adAqD%!QU#3X-X-E	9X-E	9CHDF G 	   
QJE	XE	RXXq!e)R!Q$Yq"u=>>E 	|a(*+A	4B	BQwHaZF552:D(]FffX&'G{X%sV|44G	!HHffftm6AFJKG{X%sTz22G	!HH((1s7BIIc%j$9C$?@K	[EaAu:DKr   c                    [         R                  " U 5      (       a  U $ [        U 5      U :w  d  U S::  a  [         R                  $ US:  a  [	        SSUS9$ US::  a  [	        SSUS9$ X-  nUS::  a  US::  a  [	        SSUS9$ U S::  a>  [         R
                  " [         R                  " SU S-   5      SU -  -  SU-  S-
  -  5      nO?[         R                  " [        U 5      U [         R                  " SU-  S-
  5      -  -   5      n[	        USU-
  US9$ X0S-
  :  a  SSU-
  U -  -  n[	        SU-
  XBS9$ US:  a/  S[        R                  R                  X5      -  n[	        SU-
  XBS9$ X1-  nU S::  ak  US	::  a  [        XS
S9n[	        USU-
  US9$ US::  a  [        XS
S9n[	        USU-
  US9$ S[        R                  R                  X5      -  n[	        SU-
  XBS9$ U(       d:  US:  a  gUS:  a-  S[        R                  R                  X5      -  n[        U5      $ US:  a  SnO&U S::  a  XS-  -  S::  a  [        XS
S9nO
[!        XS
S9n[	        USU-
  US9$ )zComputes the CDF(or SF) for the two-sided Kolmogorov-Smirnov statistic.

x must be of type float, n of type integer.

Simard & L'Ecuyer (2011) [7].
r   r   r   rn   r"      r   r   g0q&?Tr   g      w@g@g      2@i g      ?gffffff?)r   isnanr%   nanr    prodr(   r   r   r   scipyspecialsmirnovrF   rl   r   r   )r   rV   r   rW   prob	nxsquaredr   s          r   _kolmognr   v  se    
xx{{
1v{a1fvvCx$S#377Cx$S#377	ACx8(cs;;877299Q!,A6!A#'BCD665a81rvvac!e};LLMD$T3:3??EzC!Ga<$QXt==Cx5==((..$S4Z??ICx  40D(sTzsCC>$Qt4D(sTzsCC5==((..$S4Z?? u}},,Q22Dd##D	
fVs*$/#Ad3 #-SAAr   c                   ^  [         R                  " T 5      (       a  T $ [        T 5      T :w  d  T S::  a  [         R                  $ US:  d  US::  a  gT U-  nUS::  a  US::  a  gT S::  a;  [         R                  " [         R
                  " ST 5      ST -  -  SU-  S-
  -  5      nOB[         R                  " [        T 5      T S-
  [         R                  " SU-  S-
  5      -  -   5      nUS-  T S-  -  $ UT S-
  :  a  SSU-
  T S-
  -  -  T -  $ US:  a-  S[        R                  R                  R                  UT 5      -  $ US-  n[        XAST -  -
  5      n[        USU-
  5      nU 4S	 jn[        XQUS
S9$ )znComputes the PDF for the two-sided Kolmogorov-Smirnov statistic.

x must be of type float, n of type integer.
r   r   r"   r   r   r   r   g      @c                    > [        TU 5      $ N)kolmogn)_xr   s    r   _kk_kolmogn_p.<locals>._kk  s    q"~r   rp   )dxorder)r   r   r%   r   r   r(   r   r   r   r   statsksonepdfrI   r   )r   rV   rW   prddeltar   s   `     r   
_kolmogn_pr     sj   
 
xx{{
1v{a1fvvCx16	AACx88''"))Aq/S1W5QCDC&&4Q71Q3"&&QQRBS:SSTCQwA~AEzC!G1%%))Cx5;;$$((A... KE3q5y!EsQwE s%q11r   c                   ^ ^ [         R                  " T 5      (       a  T $ [        T 5      T :w  d  T S::  a  [         R                  $ TS::  a  ST -  $ US::  a  g[         R                  " [         R
                  " T5      [        R                  R                  T S-   5      -
  T -  5      nUST -  ::  a  UST -  -   S-  $ [         R                  " [         R
                  " US-  5      T -  5      * nUSST -  -
  :  a  U$ [        R                  " T5      [         R                  " T 5      -  n[        USST -  -
  5      nU U4S jn[        R                  R                  UST -  USS9$ )	zYComputes the PPF/ISF of kolmogn.

n of type integer, n>= 1
p is the CDF, q the SF, p+q=1
r   r   r   r   r|   c                 "   > [        TU 5      T-
  $ r   )r   )rV   r   r   s    r   _f_kolmogni.<locals>._f  s    1~!!r   g+=)xtol)r   r   r%   r   r   r   r   r   loggammaexpm1scu	_kolmogcir}   rI   optimizebrentq)r   r   r   r   rV   x1r   s   ``     r   	_kolmognir     s)    
xx{{
1v{a1fvvAv1uAvFFBFF1I 6 6qs ;;Q>?EA~a1$$	"&&3-/	""AAAI~	q	"''!*	$B	Rs1u	B" >>  SUBU ;;r   c                 t   [         R                  " XUS/S/S[         R                  [         R                  [         R                  /S9nU HZ  u  pEpg[         R                  " U5      (       a  XGS'   M'  [        U5      U:w  a  [        SU 35      e[        [        U5      XVS9US'   M\     UR                  S   nU$ )a  Computes the CDF for the two-sided Kolmogorov-Smirnov distribution.

The two-sided Kolmogorov-Smirnov distribution has as its CDF Pr(D_n <= x),
for a sample of size n drawn from a distribution with CDF F(t), where
:math:`D_n &= sup_t |F_n(t) - F(t)|`, and
:math:`F_n(t)` is the Empirical Cumulative Distribution Function of the sample.

Parameters
----------
n : integer, array_like
    the number of samples
x : float, array_like
    The K-S statistic, float between 0 and 1
cdf : bool, optional
    whether to compute the CDF(default=true) or the SF.

Returns
-------
cdf : ndarray
    CDF (or SF it cdf is False) at the specified locations.

The return value has shape the result of numpy broadcasting n and x.
Nzerosize_ok)flags	op_dtypes.n is not integral: rn   r#   )	r   nditerfloat64bool_r   r%   
ValueErrorr   operands)	r   rV   r   it_nr   _cdfr   results	            r   r   r     s    0 
A#t$]O"BJJ"**E
GB88B<<cFr7b=22$788#b'20#  [[_FMr   c                    [         R                  " XS/5      nU H\  u  p4n[         R                  " U5      (       a  X5S'   M'  [        U5      U:w  a  [	        SU 35      e[        [        U5      U5      US'   M^     UR                  S   nU$ )a\  Computes the PDF for the two-sided Kolmogorov-Smirnov distribution.

Parameters
----------
n : integer, array_like
    the number of samples
x : float, array_like
    The K-S statistic, float between 0 and 1

Returns
-------
pdf : ndarray
    The PDF at the specified locations

The return value has shape the result of numpy broadcasting n and x.
N.r   r#   )r   r   r   r%   r   r   r   )r   rV   r   r   r   r   r   s          r   kolmognpr     s    " 
A$<	 B	88B<<cFr7b=22$788CGR(#  [[_FMr   c                 H   [         R                  " XUS/5      nU Hs  u  pEpg[         R                  " U5      (       a  XGS'   M'  [        U5      U:w  a  [	        SU 35      eU(       a  USU-
  4OSU-
  U4u  p[        [        U5      X5      US'   Mu     UR                  S   n
U
$ )a  Computes the PPF(or ISF) for the two-sided Kolmogorov-Smirnov distribution.

Parameters
----------
n : integer, array_like
    the number of samples
q : float, array_like
    Probabilities, float between 0 and 1
cdf : bool, optional
    whether to compute the PPF(default=true) or the ISF.

Returns
-------
ppf : ndarray
    PPF (or ISF if cdf is False) at the specified locations

The return value has shape the result of numpy broadcasting n and x.
N.r   r   r#   )r   r   r   r%   r   r   r   )r   r   r   r   r   _qr   r   _pcdf_psfr   s              r   kolmognir   ;  s    & 
A#t$	%B88B<<cFr7b=22$788$(r1R4jqtRj3r7E0#  [[_FMr   )T)'numpyr   scipy.specialr   scipy.special._ufuncsr   _ufuncsr   scipy._lib._finite_differencesr   r2   r4   
longdoubler1   r3   r}   r   r   r   r   r   r   r~   r   r   r   r   r   r    rF   rQ   rl   r   r   r   r   r   r   r    r   r   <module>r      s
  H   # # 6	"--"E	*	"--"UF	+771ruu966!bee)	eeqj55A:
%%1*I R 
H0V&$QhPf9Bx'2T<:"J:r   