
    [ThH                         S SK r S SKrS SKrS SKJr  S SKJr  S SKJr  S SKJ	r	J
r
  S/rS r/ SQr/ S	Qr/ S
Qr/ SQr\\/r\\/rSS jr\R(                  R*                  S 5       r " S S\5      rg)    N)Tensor)constraints)Distribution)broadcast_alllazy_propertyVonMisesc                     [        U5      nUR                  5       nU(       a  UR                  5       X-  -   nU(       a  M  U$ N)listpop)ycoefresults      U/var/www/auris/envauris/lib/python3.13/site-packages/torch/distributions/von_mises.py
_eval_polyr      s7    :DXXZF
aj( $M    )g      ?g$@g03@g,?N?g2t?gIx?gtHZr?)	 e3E?g-5?gՒ+Hub?gJNYgTPÂ?g'gZ?gUL+ߐg;^p?)      ?gY?g(z?g*O?gZ9?g.h?gӰ٩=5?)	r   g.kg?VmgtZOZ?g<Q g'8`?gP⥝gqJ:N?g;PJ4qc                 Z   US:X  d  US:X  d   eU S-  nX"-  n[        U[        U   5      nUS:X  a  U R                  5       U-  nUR                  5       nSU -  nU SU R                  5       -  -
  [        U[        U   5      R                  5       -   n[
        R                  " U S:  X45      nU$ )zL
Returns ``log(I_order(x))`` for ``x > 0``,
where `order` is either 0 or 1.
r      g      @r   )r   _COEF_SMALLabslog_COEF_LARGEtorchwhere)xorderr   smalllarger   s         r   _log_modified_bessel_fnr!   D   s    
 A:!## 	
DA	Aq+e,-Ez%IIKE 	qAaeeg
1k%.@ A E E GGE[[T50FMr   c                 D   [         R                  " UR                  [         R                  U R                  S9nUR                  5       (       Gd  [         R                  " SUR                  -   U R                  U R                  S9nUR                  5       u  pgn[         R                  " [        R                  U-  5      n	SX)-  -   X)-   -  n
XU
-
  -  nUSU-
  -  U-
  S:  X-  R                  5       S-   U-
  S:  -  nUR                  5       (       a=  [         R                  " XS-
  R                  5       U
R!                  5       -  U5      nXL-  nUR                  5       (       d  GM  U[        R                  -   U -   S[        R                  -  -  [        R                  -
  $ )Ndtypedevice)   r      r   r   )r   zerosshapeboolr%   allrandr$   unbindcosmathpir   anyr   signacos)locconcentration
proposal_rr   doneuu1u2u3zfcaccepts                r   _rejection_sampler@   [   s4   ;;qwwejjDDhhjjJJtagg~SYYszzJXXZ
IIdggl#JN3!^,A;#q(af\\^a-?!-Cq-HI::<<F#XOO$5$@!DA=D hhjj K#!dgg+.88r   c                   v  ^  \ rS rSrSr\R                  \R                  S.r\R                  r	Sr
SU 4S jjrS r\S\4S j5       r\S\4S	 j5       r\S\4S
 j5       r\R&                  " 5       \R(                  " 5       4S j5       rSU 4S jjr\S\4S j5       r\S\4S j5       r\S\4S j5       rSrU =r$ )r   k   a(  
A circular von Mises distribution.

This implementation uses polar coordinates. The ``loc`` and ``value`` args
can be any real number (to facilitate unconstrained optimization), but are
interpreted as angles modulo 2 pi.

Example::
    >>> # xdoctest: +IGNORE_WANT("non-deterministic")
    >>> m = VonMises(torch.tensor([1.0]), torch.tensor([1.0]))
    >>> m.sample()  # von Mises distributed with loc=1 and concentration=1
    tensor([1.9777])

:param torch.Tensor loc: an angle in radians.
:param torch.Tensor concentration: concentration parameter
)r4   r5   Fc                    > [        X5      u  U l        U l        U R                  R                  n[        R
                  " 5       n[        TU ]  XEU5        g r
   )r   r4   r5   r)   r   Sizesuper__init__)selfr4   r5   validate_argsbatch_shapeevent_shape	__class__s         r   rF   VonMises.__init__   s>    '4S'H$$$hhnnjjl=Ar   c                 &   U R                   (       a  U R                  U5        U R                  [        R                  " XR
                  -
  5      -  nU[        R                  " S[        R                  -  5      -
  [        U R                  SS9-
  nU$ )Nr'   r   r   )
_validate_args_validate_sampler5   r   r.   r4   r/   r   r0   r!   )rG   valuelog_probs      r   rR   VonMises.log_prob   sw    !!%(%%		%((2B(CChhq477{#$%d&8&8BC 	
 r   returnc                 T    U R                   R                  [        R                  5      $ r
   )r4   tor   doublerG   s    r   _locVonMises._loc   s    xx{{5<<((r   c                 T    U R                   R                  [        R                  5      $ r
   )r5   rV   r   rW   rX   s    r   _concentrationVonMises._concentration   s    !!$$U\\22r   c                     U R                   nSSSUS-  -  -   R                  5       -   nUSU-  R                  5       -
  SU-  -  nSUS-  -   SU-  -  nSU-  U-   n[        R                  " US:  XT5      $ )Nr      r'   gh㈵>)r\   sqrtr   r   )rG   kappataurho_proposal_r_proposal_r_taylors         r   rd   VonMises._proposal_r   s    ##1q5!8|#))++a#g^^%%!e)436za#g.Y.{{54<);IIr   c                 <   U R                  U5      n[        R                  " X R                  R                  U R
                  R                  S9n[        U R                  U R                  U R                  U5      R                  U R
                  R                  5      $ )a  
The sampling algorithm for the von Mises distribution is based on the
following paper: D.J. Best and N.I. Fisher, "Efficient simulation of the
von Mises distribution." Applied Statistics (1979): 152-157.

Sampling is always done in double precision internally to avoid a hang
in _rejection_sample() for small values of the concentration, which
starts to happen for single precision around 1e-4 (see issue #88443).
r#   )_extended_shaper   emptyrY   r$   r4   r%   r@   r\   rd   rV   )rG   sample_shaper)   r   s       r   sampleVonMises.sample   sl     $$\2KKYY__TXX__M IIt**D,<,<a

"TXX^^
	r   c                   >  [         TU ]  U5      $ ! [         ad    U R                  R	                  S5      nU R
                  R                  U5      nU R                  R                  U5      n[        U 5      " XEUS9s $ f = f)NrO   )rH   )rE   expandNotImplementedError__dict__getr4   r5   type)rG   rI   	_instancerH   r4   r5   rK   s         r   rn   VonMises.expand   sw    	O7>+.." 	O MM--.>?M((//+.C ..55kBM:cNN		Os    A+B ?B c                     U R                   $ )z(
The provided mean is the circular one.
r4   rX   s    r   meanVonMises.mean   s    
 xxr   c                     U R                   $ r
   rv   rX   s    r   modeVonMises.mode   s    xxr   c                 v    S[        U R                  SS9[        U R                  SS9-
  R                  5       -
  $ )z,
The provided variance is the circular one.
r   rN   r   )r!   r5   exprX   s    r   varianceVonMises.variance   s>     '(:(:!D)$*<*<AFGce		
r   )r5   r4   r
   )__name__
__module____qualname____firstlineno____doc__r   realpositivearg_constraintssupporthas_rsamplerF   rR   r   r   rY   r\   rd   r   no_gradrD   rk   rn   propertyrw   rz   r~   __static_attributes____classcell__)rK   s   @r   r   r   k   s	   " *..AUAUVOGKB	 )f ) ) 3 3 3 JV J J ]]_"'**,   O f   f   

& 

 

r   )r   )r/   r   	torch.jitr   torch.distributionsr    torch.distributions.distributionr   torch.distributions.utilsr   r   __all__r   _I0_COEF_SMALL_I0_COEF_LARGE_I1_COEF_SMALL_I1_COEF_LARGEr   r   r!   jitscript_if_tracingr@   r    r   r   <module>r      s        + 9 B ,

 ~.~.. 9 9i
| i
r   