
    Αi!.                        S SK Jr  S SKrS SKJr  S SKrS SKrS SKJr  S SK	J
r
Jr  S SKJr  S SKJrJr  \(       a  S SKJr  S S	KJr  S S
KJr  S SKJrJr   " S S5      rg)    )annotationsN)TYPE_CHECKING)_C_ops)check_variable_and_dtypeconvert_dtype)Variable)in_dynamic_or_pir_modein_pir_mode)Sequence)	TypeGuard)Tensor)NestedNumericSequence
TensorLikec                  l  ^  \ rS rSrSr S     SU 4S jjjr\SS j5       r\SS j5       r\SS j5       r	\SS j5       r
/ 4SS jjr/ 4SS	 jjrSS
 jrSS jrSS jrSS jrSS jrSS jr    SS jr    S S jr      S!S jr S"     S#S jjr S"     S$S jjr    S S jrSrU =r$ )%Distribution(   a  
The abstract base class for probability distributions. Functions are
implemented in specific distributions.

Args:
    batch_shape(Sequence[int], optional):  independent, not identically
        distributed draws, aka a "collection" or "bunch" of distributions.
    event_shape(Sequence[int], optional): the shape of a single
        draw from the distribution; it may be dependent across dimensions.
        For scalar distributions, the event shape is []. For n-dimension
        multivariate distribution, the event shape is [n].
c                   > [        U[        5      (       a  UO
[        U5      U l        [        U[        5      (       a  UO
[        U5      U l        [        TU ]  5         g N)
isinstancetuple_batch_shape_event_shapesuper__init__)selfbatch_shapeevent_shape	__class__s      `/var/www/html/banglarbhumi/venv/lib/python3.13/site-packages/paddle/distribution/distribution.pyr   Distribution.__init__6   sX    
 +u-- {# 	 +u-- {# 	 	    c                    U R                   $ )zMReturns batch shape of distribution

Returns:
    Sequence[int]: batch shape
)r   r   s    r   r   Distribution.batch_shapeF           r!   c                    U R                   $ )zMReturns event shape of distribution

Returns:
    Sequence[int]: event shape
)r   r#   s    r   r   Distribution.event_shapeO   r%   r!   c                    [         e)zMean of distributionNotImplementedErrorr#   s    r   meanDistribution.meanX   
     "!r!   c                    [         e)zVariance of distributionr)   r#   s    r   varianceDistribution.variance]   r-   r!   c                    [         e)zSampling from the distribution.r)   r   shapes     r   sampleDistribution.sampleb       !!r!   c                    [         e)zreparameterized sampler)   r2   s     r   rsampleDistribution.rsamplef   r6   r!   c                    [         e)z The entropy of the distribution.r)   r#   s    r   entropyDistribution.entropyj   r6   r!   c                    [         e)z7The KL-divergence between self distributions and other.r)   )r   others     r   kl_divergenceDistribution.kl_divergencen   r6   r!   c                @    U R                  U5      R                  5       $ )zoProbability density/mass function evaluated at value.

Args:
    value (Tensor): value which will be evaluated
)log_probexpr   values     r   probDistribution.probr   s     }}U#''))r!   c                    [         e)z&Log probability density/mass function.r)   rD   s     r   rB   Distribution.log_probz   r6   r!   c                    [         e)z|Probability density/mass function.

Note:

    This method will be deprecated in the future, please use `prob`
    instead.
r)   rD   s     r   probsDistribution.probs~   s
     "!r!   c                p    [        U5      [        U R                  5      -   [        U R                  5      -   $ )zcompute shape of the sample

Args:
    sample_shape (Sequence[int]|Tensor): sample shape

Returns:
    Tensor: generated sample data shape
)r   r   r   )r   sample_shapes     r   _extend_shapeDistribution._extend_shape   s7     ,D%%&'D%%&'	
r!   c                    SnSnU H8  n[        U[        [        R                  R                  45      (       a  SnM6  SnM:     U(       a  U(       a  [        S5      eU$ )z
Argument validation for distribution args
Args:
    value (float, list, numpy.ndarray, Tensor)
Raises
    ValueError: if one argument is Tensor, all arguments should be Tensor
FTz9if one argument is Tensor, all arguments should be Tensor)r   r   paddlepirValue
ValueError)r   argsis_variable	is_numberargs        r   _validate_argsDistribution._validate_args   s]     	C#&***:*:;<<" 		  9K  r!   c           
     ,   / n/ nSnU GH   n[        U[        [        [        [        R
                  [        [        R                  R                  45      (       d  [        S[        U5       35      e[        U[        R                  R                  5      (       a  UR                  U5        M  [        R                  " U5      nUR                  n[        U5      S:w  a6  [        U5      S:w  a  [         R"                  " S5        UR%                  S5      nXF-   nUR                  U5        GM#     UR                  nU H  n[        U[        R                  R                  5      (       a  UR                  U5        M?  [        R&                  " XT5      u  p[)        5       (       a!  [        R*                  " U	R,                  5      nO[        R.                  R1                  US9n[        R2                  " X5        UR                  U5        M     [        U5      $ )zt
Argument convert args to Tensor

Args:
    value (float, list, numpy.ndarray, Tensor)
Returns:
    Tensor of args.
g        ZType of input args must be float, list, tuple, numpy.ndarray or Tensor, but received type float32float64zadata type of argument only support float32 and float64, your argument will be convert to float32.dtype)r   floatlistr   npndarrayr   rR   rS   rT   	TypeErrortypeappendarrayra   strwarningswarnastypebroadcast_arraysr
   zerosr3   tensorcreate_tensorassign)r   rV   
numpy_argsvariable_argstmprY   arg_np	arg_dtypera   arg_broadcasted_arg_variables               r   
_to_tensorDistribution._to_tensor   s    
CeRZZ6::;K;KL   pquvyqzp{|  #vzz//00!!#&XXc]FI9~*y>Y. MM{  y1,Cf%3 6 		C#vzz//00$$S)!#!4!4S!>O}}%||O,A,AB%}}:::GMM/8  .  ]##r!   c                `   [         R                  " U5      (       a  UR                  UR                  5      $ [	        5       (       a  [        5       (       a  [        USSS/S5        UR                  UR                  :w  aO  [        UR                  5      S;   a6  [        R                  " S5        [        R                  " X!R                  5      $ U$ [        USSS/S5        UR                  UR                  :w  a4  [        R                  " S5        [         R                  " X!R                  S9$ U$ )as  
Log_prob and probs methods have input ``value``, if value's dtype is different from param,
convert value's dtype to be consistent with param's dtype.

Args:
    param (Tensor): low and high in Uniform class, loc and scale in Normal class.
    value (Tensor): The input tensor.

Returns:
    value (Tensor): Change value's dtype if value's dtype is different from param.
rE   r^   r_   rB   )r^   r_   ztdtype of input 'value' needs to be the same as parameters of distribution class. dtype of 'value' will be converted.r`   )rR   
is_complexrm   ra   r	   r
   r   r   rk   rl   r   cast)r   paramrE   s      r   _check_values_dtype_in_probs)Distribution._check_values_dtype_in_probs   s     U##<<,,!##}}(7Y	$:J {{ekk)mEKK.H M /  K {{5++66L 	"		
 ;;%++%MM G ;;uKK88r!   c                    U(       a.  [         R                  " U5      [         R                  " U* 5      -
  $ [         R                  " U5      $ )z
Converts probabilities into logits. For the binary, probs denotes the
probability of occurrence of the event indexed by `1`. For the
multi-dimensional, values of last axis denote the probabilities of
occurrence of each of the events.
)rR   loglog1p)r   rK   	is_binarys      r   _probs_to_logitsDistribution._probs_to_logits  s=      ZZuf!55	
 E"	
r!   c                    U(       a)  [         R                  R                  R                  U5      $ [         R                  R                  R	                  USS9$ )z
Converts logits into probabilities. For the binary, each value denotes
log odds, whereas for the multi-dimensional case, the values along the
last dimension denote the log probabilities of the events.
)axis)rR   nn
functionalsigmoidsoftmax)r   logitsr   s      r   _logits_to_probsDistribution._logits_to_probs(  sJ      II  ((0	
 %%--f2->	
r!   c           
        U Hg  n[        U[        [        [        [        R
                  [        [        R                  R                  45      (       a  MR  [        S[        U5       35      e   [        S U 5       5      (       d  [        R                  " 5       nU H@  n[        U[        [        R                  R                  45      (       d  M4  UR                  n  O   U Vs/ s HH  n[        U[        [        R                  R                  45      (       a  UO[        R                  " X#S9PMJ     nn[        R                   " U5      $ [        R                   " U5      $ s  snf )aP  
Returns a list where each arg is broadcasted. Scalar args are upcast to tensors
having the same data type as the first Tensor passed to `args`.  If all the
args are scalars, then they are upcasted to Tensors with paddle default data type.

Args:
    value (float, list, numpy.ndarray, Tensor)

Returns:
    Broadcasted Tensor of args.
r]   c              3  v   #    U  H/  n[        U[        [        R                  R                  45      v   M1     g 7fr   )r   r   rR   rS   rT   ).0rY   s     r   	<genexpr>.Distribution._broadcast_all.<locals>.<genexpr>L  s,      
EIcJsXvzz'7'7899Ts   79r`   )r   rb   rc   r   rd   re   r   rR   rS   rT   rf   rg   allget_default_dtypera   	to_tensorbroadcast_tensors)r   rV   rY   ra   new_argss        r   _broadcast_allDistribution._broadcast_all6  s;    CeRZZ6::;K;KL   pquvyqzp{|    
EI
 
 
 ,,.EcHfjj.>.>#?@@IIE     C "#&**2B2B'CDD ))#;<     ++H55''--s   $AE!)r   r   ) r   )r   Sequence[int]r   r   returnNone)r   r   )r   r   )r3   r   r   r   )r>   r   r   r   )rE   r   r   r   )rN   zSequence[int] | Tensorr   r   )rV   "TensorLike | NestedNumericSequencer   zTypeGuard[Tensor])rV   r   r   ztuple[Tensor, ...])r   r   rE   r   r   r   )F)rK   float | Tensorr   boolr   r   )r   r   r   r   r   r   )__name__
__module____qualname____firstlineno____doc__r   propertyr   r   r+   r/   r4   r8   r;   r?   rF   rB   rK   rO   rZ   r{   r   r   r   r   __static_attributes____classcell__)r   s   @r   r   r   (   sZ    MO(<I	   ! ! ! ! " " " " -/ " .0 """*""
7	29$79$	9$v,,$*,	,^ 8=
#
04
	
  9>
$
15
	
'.7'.	'. '.r!   r   )
__future__r   rk   typingr   numpyrd   rR   r   paddle.base.data_feederr   r   paddle.base.frameworkr   paddle.frameworkr	   r
   collections.abcr   typing_extensionsr   r   paddle._typingr   r   r   r   r!   r   <module>r      sA    #       K *
 (+@u. u.r!   