
    9iD                     ~    S SK JrJ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
  S SKJrJr  S/rS	 r " S
 S\5      rg)    )OptionalUnionN)Tensor)constraints)ExponentialFamily)broadcast_all)_Number_sizeGammac                 .    [         R                  " U 5      $ N)torch_standard_gamma)concentrations    Y/var/www/html/land-doc-ocr/venv/lib/python3.13/site-packages/torch/distributions/gamma.pyr   r      s      //    c            	       z  ^  \ rS rSrSr\R                  \R                  S.r\R                  r	Sr
Sr\S\4S j5       r\S\4S j5       r\S\4S	 j5       r SS\\\4   S\\\4   S\\   SS
4U 4S jjjrSU 4S jjr\R0                  " 5       4S\S\4S jjrS rS r\S\\\4   4S j5       rS rS r Sr!U =r"$ )r      a#  
Creates a Gamma distribution parameterized by shape :attr:`concentration` and :attr:`rate`.

Example::

    >>> # xdoctest: +IGNORE_WANT("non-deterministic")
    >>> m = Gamma(torch.tensor([1.0]), torch.tensor([1.0]))
    >>> m.sample()  # Gamma distributed with concentration=1 and rate=1
    tensor([ 0.1046])

Args:
    concentration (float or Tensor): shape parameter of the distribution
        (often referred to as alpha)
    rate (float or Tensor): rate parameter of the distribution
        (often referred to as beta), rate = 1 / scale
r   rateTr   returnc                 4    U R                   U R                  -  $ r   r   selfs    r   mean
Gamma.mean-   s    !!DII--r   c                 T    U R                   S-
  U R                  -  R                  SS9$ )N   r   min)r   r   clampr   s    r   mode
Gamma.mode1   s*    ##a'4994;;;BBr   c                 R    U R                   U R                  R                  S5      -  $ )N   )r   r   powr   s    r   varianceGamma.variance5   s     !!DIIMM!$444r   Nr   r   validate_argsc                   > [        X5      u  U l        U l        [        U[        5      (       a+  [        U[        5      (       a  [
        R                  " 5       nOU R                  R                  5       n[        TU ]%  XCS9  g )Nr)   )
r   r   r   
isinstancer	   r   Sizesizesuper__init__)r   r   r   r)   batch_shape	__class__s        r   r0   Gamma.__init__9   sa     )6m(J%DImW--*T72K2K**,K,,113KBr   c                 &  > U R                  [        U5      n[        R                  " U5      nU R                  R                  U5      Ul        U R                  R                  U5      Ul        [        [        U]#  USS9  U R                  Ul	        U$ )NFr+   )
_get_checked_instancer   r   r-   r   expandr   r/   r0   _validate_args)r   r1   	_instancenewr2   s       r   r6   Gamma.expandF   sy    ((	:jj- ..55kB99##K0eS";e"D!00
r   sample_shapec                 2   U R                  U5      n[        U R                  R                  U5      5      U R                  R                  U5      -  nUR                  5       R                  [        R                  " UR                  5      R                  S9  U$ )Nr   )_extended_shaper   r   r6   r   detachclamp_r   finfodtypetiny)r   r;   shapevalues       r   rsampleGamma.rsampleO   s    $$\2 2 2 9 9% @ADIIDTDTE
 
 	EKK(-- 	 	
 r   c                    [         R                  " XR                  R                  U R                  R                  S9nU R
                  (       a  U R                  U5        [         R                  " U R                  U R                  5      [         R                  " U R                  S-
  U5      -   U R                  U-  -
  [         R                  " U R                  5      -
  $ )N)rA   devicer   )
r   	as_tensorr   rA   rH   r7   _validate_samplexlogyr   lgammar   rD   s     r   log_probGamma.log_probY   s    YY__TYYEUEUV!!%(KK**DII6kk$,,q0%89ii%  ll4--./	
r   c                     U R                   [        R                  " U R                  5      -
  [        R                  " U R                   5      -   SU R                   -
  [        R
                  " U R                   5      -  -   $ )Ng      ?)r   r   logr   rL   digammar   s    r   entropyGamma.entropyd   sf    ii		"#ll4--./ T'''5==9K9K+LLM	
r   c                 :    U R                   S-
  U R                  * 4$ Nr   r   r   s    r   _natural_paramsGamma._natural_paramsl   s    ""Q&
33r   c                     [         R                  " US-   5      US-   [         R                  " UR                  5       * 5      -  -   $ rV   )r   rL   rQ   
reciprocal)r   xys      r   _log_normalizerGamma._log_normalizerp   s4    ||AE"a!euyy!,,./I%IIIr   c                     U R                   (       a  U R                  U5        [        R                  R	                  U R
                  U R                  U-  5      $ r   )r7   rJ   r   specialgammaincr   r   rM   s     r   cdf	Gamma.cdfs   s?    !!%(}}%%d&8&8$))e:KLLr   r   )#__name__
__module____qualname____firstlineno____doc__r   positivearg_constraintsnonnegativesupporthas_rsample_mean_carrier_measurepropertyr   r   r"   r'   r   floatr   boolr0   r6   r   r-   r
   rE   rN   rS   tuplerW   r]   rb   __static_attributes____classcell__)r2   s   @r   r   r      sA   $ %--$$O %%GK.f . . Cf C C 5& 5 5 )-	CVU]+C FEM"C  ~	C
 
C C -2JJL E V 	

 4vv~!6 4 4JM Mr   )typingr   r   r   r   torch.distributionsr   torch.distributions.exp_familyr   torch.distributions.utilsr   torch.typesr	   r
   __all__r   r    r   r   <module>r|      s9    "   + < 3 & )0cM cMr   