
    [Th20                     v    S SK r S SKJr  S SK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/r " S	 S5      rg)
    N)Optional)
deprecated)Tensor)constraints)lazy_property)_sizeDistributionc                   x  ^  \ rS rSrSrSrSrSr\S\	SS4S j5       r
\R                  " 5       \R                  " 5       S4S	\R                  S
\R                  S\\	   4U 4S jjjrS)S	\4S jjr\S\R                  4S j5       r\S\R                  4S j5       r\S\\\R.                  4   4S j5       r\S\\R.                     4S j5       r\S\4S j5       r\S\4S j5       r\S\4S j5       r\S\4S j5       r\R                  " 5       4S\S\4S jjr\R                  " 5       4S\S\4S jjr \!" S\"S9S\#S\4S j5       r$S\S\4S jr%S\S\4S jr&S\S\4S jr'S*S \	S\4S! jjr(S\4S" jr)S\4S# jr*\R                  " 5       4S\S\R                  4S$ jjr+S\SS4S% jr,S)S& jr-S\4S' jr.S(r/U =r0$ )+r	      zH
Distribution is the abstract base class for probability distributions.
FTvaluereturnNc                 2    U S;  a  [         eU [        l        g)a]  
Sets whether validation is enabled or disabled.

The default behavior mimics Python's ``assert`` statement: validation
is on by default, but is disabled if Python is run in optimized mode
(via ``python -O``). Validation may be expensive, so you may want to
disable it once a model is working.

Args:
    value (bool): Whether to enable validation.
)TFN)
ValueErrorr	   _validate_args)r   s    X/var/www/auris/envauris/lib/python3.13/site-packages/torch/distributions/distribution.pyset_default_validate_args&Distribution.set_default_validate_args   s     %&+#    batch_shapeevent_shapevalidate_argsc                   > Xl         X l        Ub  X0l        U R                  (       Ga   U R                  nUR                  5        H  u  pV[        R                  " U5      (       a  M"  XPR                  ;  a*  [        [        [        U 5      U5      [        5      (       a  M[  [        X5      nUR!                  U5      n["        R$                  " U5      (       a  M  ['        SU S[        U5      R(                   S[+        UR,                  5       S[/        U 5       S[/        U5       S	U 35      e   [0        T	U ]e  5         g ! [         a/    0 n[
        R                  " U R                   S3S-   S-   5         GNBf = f)
Nz$ does not define `arg_constraints`. zAPlease set `arg_constraints = {}` or initialize the distribution z2with `validate_args=False` to turn off validation.zExpected parameter z (
 of shape z) of distribution z to satisfy the constraint , but found invalid values:
)_batch_shape_event_shaper   arg_constraintsNotImplementedErrorwarningswarn	__class__itemsr   is_dependent__dict__
isinstancegetattrtyper   checktorch_is_all_truer   __name__tupleshapereprsuper__init__)
selfr   r   r   r   param
constraintr   validr!   s
            r   r0   Distribution.__init__*   st    ('$"/"&"6"6 &5%:%:%<!++J77-*DJ.3 3 ,"((/))%00$-eW 5 K001E%++<N;O P++/:, 7559*5E4F G66;W	>  &=" 	1 ' "$~~&&JKYZJKs   E   5E98E9c                     [         e)a  
Returns a new distribution instance (or populates an existing instance
provided by a derived class) with batch dimensions expanded to
`batch_shape`. This method calls :class:`~torch.Tensor.expand` on
the distribution's parameters. As such, this does not allocate new
memory for the expanded distribution instance. Additionally,
this does not repeat any args checking or parameter broadcasting in
`__init__.py`, when an instance is first created.

Args:
    batch_shape (torch.Size): the desired expanded size.
    _instance: new instance provided by subclasses that
        need to override `.expand`.

Returns:
    New distribution instance with batch dimensions expanded to
    `batch_size`.
r   )r1   r   	_instances      r   expandDistribution.expandQ   s
    & "!r   c                     U R                   $ )z6
Returns the shape over which parameters are batched.
)r   r1   s    r   r   Distribution.batch_shapef       
    r   c                     U R                   $ )z:
Returns the shape of a single sample (without batching).
)r   r<   s    r   r   Distribution.event_shapem   r>   r   c                     [         e)z
Returns a dictionary from argument names to
:class:`~torch.distributions.constraints.Constraint` objects that
should be satisfied by each argument of this distribution. Args that
are not tensors need not appear in this dict.
r7   r<   s    r   r   Distribution.arg_constraintst   
     "!r   c                     [         e)zq
Returns a :class:`~torch.distributions.constraints.Constraint` object
representing this distribution's support.
r7   r<   s    r   supportDistribution.support~   
     "!r   c                     [         e)z'
Returns the mean of the distribution.
r7   r<   s    r   meanDistribution.mean   
    
 "!r   c                 2    [        U R                   S35      e)z'
Returns the mode of the distribution.
z does not implement mode)r   r!   r<   s    r   modeDistribution.mode   s    
 "T^^$44L"MNNr   c                     [         e)z+
Returns the variance of the distribution.
r7   r<   s    r   varianceDistribution.variance   rK   r   c                 6    U R                   R                  5       $ )z5
Returns the standard deviation of the distribution.
)rP   sqrtr<   s    r   stddevDistribution.stddev   s    
 }}!!##r   sample_shapec                     [         R                  " 5          U R                  U5      sSSS5        $ ! , (       d  f       g= f)z|
Generates a sample_shape shaped sample or sample_shape shaped batch of
samples if the distribution parameters are batched.
N)r)   no_gradrsampler1   rV   s     r   sampleDistribution.sample   s#    
 ]]_<<- __s   1
?c                     [         e)z
Generates a sample_shape shaped reparameterized sample or sample_shape
shaped batch of reparameterized samples if the distribution parameters
are batched.
r7   rZ   s     r   rY   Distribution.rsample   rG   r   z=`sample_n(n)` will be deprecated. Use `sample((n,))` instead.)categorync                 N    U R                  [        R                  " U45      5      $ )zY
Generates n samples or n batches of samples if the distribution
parameters are batched.
)r[   r)   Size)r1   r`   s     r   sample_nDistribution.sample_n   s     {{5::qd+,,r   c                     [         e)zk
Returns the log of the probability density/mass function evaluated at
`value`.

Args:
    value (Tensor):
r7   r1   r   s     r   log_probDistribution.log_prob   rC   r   c                     [         e)z_
Returns the cumulative density/mass function evaluated at
`value`.

Args:
    value (Tensor):
r7   rf   s     r   cdfDistribution.cdf   rC   r   c                     [         e)zg
Returns the inverse cumulative density/mass function evaluated at
`value`.

Args:
    value (Tensor):
r7   rf   s     r   icdfDistribution.icdf   rC   r   r9   c                     [         e)a  
Returns tensor containing all values supported by a discrete
distribution. The result will enumerate over dimension 0, so the shape
of the result will be `(cardinality,) + batch_shape + event_shape`
(where `event_shape = ()` for univariate distributions).

Note that this enumerates over all batched tensors in lock-step
`[[0, 0], [1, 1], ...]`. With `expand=False`, enumeration happens
along dim 0, but with the remaining batch dimensions being
singleton dimensions, `[[0], [1], ..`.

To iterate over the full Cartesian product use
`itertools.product(m.enumerate_support())`.

Args:
    expand (bool): whether to expand the support over the
        batch dims to match the distribution's `batch_shape`.

Returns:
    Tensor iterating over dimension 0.
r7   )r1   r9   s     r   enumerate_supportDistribution.enumerate_support   s
    , "!r   c                     [         e)zg
Returns entropy of distribution, batched over batch_shape.

Returns:
    Tensor of shape batch_shape.
r7   r<   s    r   entropyDistribution.entropy   s
     "!r   c                 J    [         R                  " U R                  5       5      $ )zj
Returns perplexity of distribution, batched over batch_shape.

Returns:
    Tensor of shape batch_shape.
)r)   exprs   r<   s    r   
perplexityDistribution.perplexity   s     yy((r   c                     [        U[        R                  5      (       d  [        R                  " U5      n[        R                  " XR                  -   U R                  -   5      $ )a@  
Returns the size of the sample returned by the distribution, given
a `sample_shape`. Note, that the batch and event shapes of a distribution
instance are fixed at the time of construction. If this is empty, the
returned shape is upcast to (1,).

Args:
    sample_shape (torch.Size): the size of the sample to be drawn.
)r%   r)   rb   r   r   rZ   s     r   _extended_shapeDistribution._extended_shape  sF     ,

33 ::l3Lzz,):)::T=N=NNOOr   c                    [        U[        R                  5      (       d  [        S5      e[	        UR                  5       5      [	        U R                  5      -
  nUR                  5       US U R                  :w  a*  [        SUR                  5        SU R                   S35      eUR                  5       nU R                  U R                  -   n[        [        U5      [        U5      5       H,  u  pVUS:w  d  M  US:w  d  M  XV:w  d  M  [        SU SU S35      e    U R                  nUc   eUR                  U5      n[        R                   " U5      (       dR  [        S[#        U5      R$                   S['        UR(                  5       S[+        U5       S[+        U 5       SU 3
5      eg! [         a,    [        R                  " U R                   S3S	-   S
-   5         gf = f)a  
Argument validation for distribution methods such as `log_prob`,
`cdf` and `icdf`. The rightmost dimensions of a value to be
scored via these methods must agree with the distribution's batch
and event shapes.

Args:
    value (Tensor): the tensor whose log probability is to be
        computed by the `log_prob` method.
Raises
    ValueError: when the rightmost dimensions of `value` do not match the
        distribution's batch and event shapes.
z/The value argument to log_prob must be a TensorNz5The right-most size of value must match event_shape: z vs .   z9Value is not broadcastable with batch_shape+event_shape: z% does not define `support` to enable z;sample validation. Please initialize the distribution with z-`validate_args=False` to turn off validation.zExpected value argument (r   z) to be within the support (z) of the distribution r   )r%   r)   r   r   lensizer   r   zipreversedrE   r   r   r    r!   r(   r*   r'   r+   r,   r-   r.   )	r1   r   event_dim_startactual_shapeexpected_shapeijrE   r4   s	            r   _validate_sampleDistribution._validate_sample  s    %..NOOejjl+c$2C2C.DD::<()T->->>G

~UYZ^ZkZkYllmn  zz|**T->->>.0HIDAAv!q&QV OP\~]abpaqqrs  J
	llG """e$!!%((K(()E%++4F3G H--1']O <''+Dzl 3..3W	6  ) # 	MM>>""GHOPAB
 	s   F- -3G#"G#c                     UcS  [        U 5      R                  UR                  :w  a0  [        SU R                  R                   SUR                   S35      eUc  U R                  [        U 5      5      $ U$ )Nz	Subclass z of zR that defines a custom __init__ method must also define a custom .expand() method.)r'   r0   r   r!   r+   __new__)r1   clsr8   s      r   _get_checked_instance"Distribution._get_checked_instanceE  sp    d!4!4!D%DNN334D G> >  ,5+<t||DJ'K)Kr   c           	         U R                   R                  5        VVs/ s H  u  pXR                  ;   d  M  UPM     nnnSR                  U Vs/ s HU  nU SU R                  U   R	                  5       S:X  a  U R                  U   OU R                  U   R                  5        3PMW     sn5      nU R                  R                  S-   U-   S-   $ s  snnf s  snf )Nz, z: r~   ())r   r"   r$   joinnumelr   r!   r+   )r1   k_param_namespargs_strings         r   __repr__Distribution.__repr__M  s    %)%9%9%?%?%AX%ATQQ--EWq%AXii %$A #RDMM!,<,B,B,D,Ia(t}}]^O_OdOdOfgh$
 ~~&&,{:S@@ Ys   CCAC)r   r   r   )N)T)1r+   
__module____qualname____firstlineno____doc__has_rsamplehas_enumerate_supportr   staticmethodboolr   r)   rb   r   r0   r   r9   propertyr   r   dictstrr   
Constraintr   rE   r   rI   rM   rP   rT   r[   rY   r   FutureWarningintrc   rg   rj   rm   rp   rs   rw   rz   r   r   r   __static_attributes____classcell__)r!   s   @r   r	   r	      s    K!N, ,$ , ,$ #(**,"'**,(,	%ZZ% ZZ%  ~	% %N"% "* !UZZ ! ! !UZZ ! ! "c;+A+A&A!B " " "+"8"89 " " "f " " Of O O "& " " $ $ $ ,1::< .5 .F . -2JJL "E "V " G-# -& -	-"f " "" "F ""& "V "" " "0" ")F ) 5:JJL PE PUZZ P0f 0 0dLA# A Ar   )r   typingr   typing_extensionsr   r)   r   torch.distributionsr   torch.distributions.utilsr   torch.typesr   __all__r	    r   r   <module>r      s5      (   + 3  
EA EAr   