ó
    EñiÏ  ã                   óä   • 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      ÚZ/home/mande/repo/quber/.venv/lib/python3.13/site-packages/torch/distributions/von_mises.pyÚ
_eval_polyr      s7   € Ü�‹:€DØ�X‰X‹Z€FÞ
Ø—‘“˜a™jÑ(ˆ÷ ˆ$à€Mó    )g      ð?g§Œ$æþ@g¤0”¸3¸@g,–Ç?ØNó?gª2çt´Ñ?gýåIˆ¨x¢?gtHÅZ×Ãr?)	ç Þe3EˆÙ?g�-ÿ¥5‹?gÛÕ’+Hub?gJ‰NÁÐY¿gTÑPŠóÃ‚?gÇý'•¿gãZåðæüš?gULÊ+ß�¿gˆ;ý^p?)ç      à?g§ì‘Yÿì?g(„«�Ézà?gê*öúOÃ?gZƒµ9›?gœå.™•³h?gÓ°­Ù©=5?)	r   g¾þÍ.k¤¿g?Œ”V¨m¿g–tZØOÖZ?gÜ<¯Q …¿gÙ'8©`—?gP“þâ¥�¿gqœ©J:N’?g;PÈJ£4q¿c                 ór  • US:w  a  US:w  a  [        SU 35      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   é   zorder must be 0 or 1, got g      @r   )ÚAssertionErrorr   Ú_COEF_SMALLÚabsÚlogÚ_COEF_LARGEÚtorchÚwhere)ÚxÚorderr   ÚsmallÚlarger   s         r   Ú_log_modified_bessel_fnr"   D   sº   € ð
 �ƒz�e˜q“jÜÐ9¸%¸ÐAÓBÐBð 	
ˆD‰€AØ	‰€AÜ�qœ+ eÑ,Ó-€EØ�ƒzØ—‘“˜%‘ˆØ�I‰I‹K€Eð 	ˆq‰€AØ��a—e‘e“g‘Ñ¤
¨1¬k¸%Ñ.@Ó A× EÑ EÓ GÑG€Eä�[Š[˜˜T™ 5Ó0€FØ€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                  " XÈS-
  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_samplerA   \   s4  € ä�;Š;�q—w‘w¤e§j¡j¸¿¹ÑD€Dà�h‰h�jŠjÜ�JŠJ�t˜aŸg™g‘~¨S¯Y©Y¸s¿z¹zÑJˆØ—X‘X“Z‰
ˆ�Ü�IŠI”d—g‘g ‘lÓ#ˆØ�‘Ñ J¡NÑ3ˆØ¨!™^Ñ,ˆØ˜˜A™‘; Ñ# qÑ(¨a©f¯\©\«^¸aÑ-?À!Ñ-CÀqÑ-HÑIˆØ�:‰:�<‰<ä—’˜F¨#¡X§O¡OÓ$5¸¿¹»Ñ$@À!ÓDˆAØ‘=ˆDð �h‰h�jŒjð ”—‘‰K˜#Ñ !¤d§g¡g¡+Ñ.´·±Ñ8Ð8r   c            	       ó’  ^ • \ rS rSrSr\R                  \R                  S.r\R                  r	Sr
 SS\S\S\S-  S	S4U 4S
 j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   én   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
)r5   r6   FNr5   r6   Úvalidate_argsÚreturnc                 ó¬   >• [        X5      u  U l        U l        U R                  R                  n[        R
                  " 5       n[        TU ]  XEU5        g r
   )r   r5   r6   r*   r   ÚSizeÚsuperÚ__init__)Úselfr5   r6   rD   Úbatch_shapeÚevent_shapeÚ	__class__s         €r   rI   ÚVonMises.__init__…   s@   ø€ ô (5°SÓ'HÑ$ˆŒ�$Ô$Ø—h‘h—n‘nˆÜ—j’j“lˆÜ‰Ñ˜°=Õ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_sampler6   r   r/   r5   r0   r   r1   r"   )rJ   ÚvalueÚlog_probs      r   rT   ÚVonMises.log_prob�   sw   € Ø××Ø×!Ñ! %Ô(Ø×%Ñ%¬¯	ª	°%¿(¹(Ñ2BÓ(CÑCˆàÜ�hŠh�qœ4Ÿ7™7‘{Ó#ñ$ä% d×&8Ñ&8ÀÑBñCð 	ð
 ˆr   c                 óT   • U R                   R                  [        R                  5      $ r
   )r5   Útor   Údouble©rJ   s    r   Ú_locÚVonMises._loc›   s   € à�x‰x�{‰{œ5Ÿ<™<Ó(Ð(r   c                 óT   • U R                   R                  [        R                  5      $ r
   )r6   rW   r   rX   rY   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(   gñhãˆµøä>)r]   Úsqrtr   r   )rJ   ÚkappaÚtauÚrhoÚ_proposal_rÚ_proposal_r_taylors         r   re   ÚVonMises._proposal_r£   s†   € à×#Ñ#ˆà�1�q˜5 !™8‘|Ñ#×)Ñ)Ó+Ñ+ˆØ�a˜#‘g—^‘^Ó%Ñ%¨!¨e©)Ñ4ˆà˜3 ™6‘z a¨#¡gÑ.ˆà ™Y¨Ñ.ÐÜ�{Š{˜5 4™<Ð);Ó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   ÚemptyrZ   r%   r5   r&   rA   r]   re   rW   )rJ   Úsample_shaper*   r   s       r   ÚsampleÚVonMises.sample¯   sl   € ð ×$Ñ$ \Ó2ˆÜ�KŠK˜§Y¡Y§_¡_¸T¿X¹X¿_¹_ÑMˆÜ Ø�I‰I�t×*Ñ*¨D×,<Ñ,<¸aó
ç
‰"ˆT�X‰X�^‰^Ó
ð	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)NrQ   )rD   )rH   ÚexpandÚNotImplementedErrorÚ__dict__Úgetr5   r6   Útype)rJ   rK   Ú	_instancerD   r5   r6   rM   s         €r   ro   ÚVonMises.expandÀ   sw   ø€ ð	OÜ‘7‘> +Ó.Ð.øÜ"ó 	OØ ŸM™M×-Ñ-Ð.>Ó?ˆMØ—(‘(—/‘/ +Ó.ˆCØ ×.Ñ.×5Ñ5°kÓBˆMÜ˜”:˜cÀÑNÒNð		Oús   ƒ ’A+B Á?B c                 ó   • U R                   $ )z(
The provided mean is the circular one.
©r5   rY   s    r   ÚmeanÚVonMises.meanÉ   s   € ð
 �x‰xˆr   c                 ó   • U R                   $ r
   rw   rY   s    r   ÚmodeÚVonMises.modeÐ   s   € à�x‰xˆ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   rP   r   )r"   r6   ÚexprY   s    r   ÚvarianceÚVonMises.varianceÔ   s>   € ð ä'¨×(:Ñ(:À!ÑDÜ)¨$×*<Ñ*<ÀAÑFñGç‰c‹eñ	ð	
r   )r6   r5   r
   )Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__r   ÚrealÚpositiveÚarg_constraintsÚsupportÚhas_rsampler   r+   rI   rT   r   rZ   r]   re   r   Úno_gradrG   rl   ro   Úpropertyrx   r{   r   Ú__static_attributes__Ú__classcell__)rM   s   @r   r   r   n   sB  ø† ñð$ *×.Ñ.À×AUÑAUÑV€OØ×Ñ€GØ€Kð &*ñ		Bàð	Bð ð	Bð ˜d‘{ð		Bð
 
÷	Bð 	Bò	ð ð)�fó )ó ð)ð ð3 ó 3ó ð3ð ð	J˜Vó 	Jó ð	Jð ‡]‚]ƒ_Ø"'§*¢*£,ó ó ð÷ Oð ð�fó ó ðð ð�fó ó ðð ð

˜&ó 

ó ö

r   )r   )r0   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_tracingrA   r   © r   r   Ú<module>r›      s‹   ðã ã Û Ý Ý +Ý 9ß Bð ˆ,€òò€ò
€ò€ò
€ð ˜~Ð.€Ø˜~Ð.€ôð0 ‡�×Ññ9ó ð9ô"q
ˆ|õ q
r   