
    Αi)                    p   % S SK Jr  S SKJr  S SKrS SKJ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  S SKJr  S S	KJr  \(       aY  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  \\\\   \\   \R<                  \\R>                  \R@                  4      \4   r!S\"S'    " S S\RF                  5      r$g)    )annotations)TYPE_CHECKINGN)_C_ops)
check_typeconvert_dtype)Variable)distribution)in_dynamic_mode)random)Sequence)Union)	TypeAlias)Tensor)NestedSequencer   _UniformBoundaryc                     ^  \ rS rSr% SrS\S'   S\S'    S       SU 4S jjjr/ S4SS jjrSS	 jrSS
 jr	SS jr
SrU =r$ )Uniform/   a	  Uniform distribution with `low` and `high` parameters.

Mathematical Details

The probability density function (pdf) is

.. math::

    pdf(x; a, b) = \frac{1}{Z}, \ a <=x <b

.. math::

    Z = b - a

In the above equation:

* :math:`low = a`,
* :math:`high = b`,
* :math:`Z`: is the normalizing constant.

The parameters `low` and `high` must be shaped in a way that supports
`Broadcasting` (e.g., `high - low` is a valid operation).

Note:
    If you want know more about broadcasting, please refer to `Introduction to Tensor`_ .

    .. _Introduction to Tensor: ../../guides/beginner/tensor_en.html#chapter5-broadcasting-of-tensor

Args:
    low(int|float|list|tuple|numpy.ndarray|Tensor): The lower boundary of
        uniform distribution.The data type is float32 and float64.
    high(int|float|list|tuple|numpy.ndarray|Tensor): The higher boundary
        of uniform distribution.The data type is float32 and float64.
    name (str, optional): For details, please refer to :ref:`api_guide_Name`. Generally, no setting is required. Default: None.

Examples:
    .. code-block:: python

        >>> import paddle
        >>> from paddle.distribution import Uniform
        >>> paddle.seed(2023)

        >>> # Without broadcasting, a single uniform distribution [3, 4]:
        >>> u1 = Uniform(low=3.0, high=4.0)
        >>> # 2 distributions [1, 3], [2, 4]
        >>> u2 = Uniform(low=[1.0, 2.0], high=[3.0, 4.0])
        >>> # 4 distributions
        >>> u3 = Uniform(low=[[1.0, 2.0], [3.0, 4.0]],
        ...             high=[[1.5, 2.5], [3.5, 4.5]])
        ...
        >>> # With broadcasting:
        >>> u4 = Uniform(low=3.0, high=[5.0, 6.0, 7.0])

        >>> # Complete example
        >>> value_tensor = paddle.to_tensor([0.8], dtype="float32")

        >>> uniform = Uniform([0.], [2.])

        >>> sample = uniform.sample([2])
        >>> # a random tensor created by uniform distribution with shape: [2, 1]
        >>> entropy = uniform.entropy()
        >>> print(entropy)
        Tensor(shape=[1], dtype=float32, place=Place(cpu), stop_gradient=True,
            [0.69314718])

        >>> lp = uniform.log_prob(value_tensor)
        >>> print(lp)
        Tensor(shape=[1], dtype=float32, place=Place(cpu), stop_gradient=True,
            [-0.69314718])

        >>> p = uniform.probs(value_tensor)
        >>> print(p)
        Tensor(shape=[1], dtype=float32, place=Place(cpu), stop_gradient=True,
            [0.50000000])
r   lowhighc                  > [        5       (       d  [        US[        [        [        R
                  [        [        R                  R                  [        [        4S5        [        US[        [        [        R
                  [        [        R                  R                  [        [        4S5        SU l        SU l        Ub  UOSU l        SU l        [!        U[        5      (       a  [        U5      n[!        U[        5      (       a  [        U5      nU R#                  X5      (       a(  Xl        X l        [)        UR                  5      U l        GOk[!        U[        5      (       a  [!        U[        5      (       a  SU l        [!        U[        R
                  5      (       a+  [+        UR                  5      S;   a  UR                  U l        OI[!        U[        R
                  5      (       a*  [+        UR                  5      S;   a  UR                  U l        U R-                  X5      u  U l        U l        U R                  [)        U R$                  R                  5      :w  a\  [        R.                  " U R$                  U R                  S9U l        [        R.                  " U R&                  U R                  S9U l        [0        TU ]e  U R$                  R4                  5        g )	Nr   r   r   Ffloat32T)r   float64dtype)r
   r   intfloatnpndarrayr   paddlepirValuelisttupleall_arg_is_floatbatch_size_unknownnamer   
isinstance_validate_argsr   r   r   str
_to_tensorcastsuper__init__shape)selfr   r   r'   	__class__s       [/var/www/html/banglarbhumi/venv/lib/python3.13/site-packages/paddle/distribution/uniform.pyr.   Uniform.__init__   s      JJJJ$$  JJJJ$$  !&"' ,D)	
c3*CdC  ;Ds))HI&syy1DJ#u%%*T5*A*A(,%#rzz**s399~ B 0 !YY
D"**--#djj/ F 3 "ZZ
"&//#"<DHdizz]488>>::!;;txxtzzB"KK		D	(    r   c           	     p   [        5       (       d*  [        US[        [        4S5        [        US[        S5        [        U5      nU R
                  S-   n[        U R                  U R                  -   R                  5      nSU;   Ga  X-   n[        XA-   5      n[        R                  " U R                  U R                  -   5      S   R                  5       US'   [        R                  " USU R                  5      n[        R                  " UUR                  U R                  SSUS	9n[        R                  " Xu5      n	[        R                  " X5      n
U
XR                  -   U R                  -
  -  n[        R                   " XR                  US
9nU$ X-   n[        R"                  " XPR                  SSUS	9[        R$                  " XPR                  S9U R                  U R                  -
  -   -  n[        R                   " XR                  US
9nU R&                  (       a  [        R                  " XUS
9$ U$ )a  Generate samples of the specified shape.

Args:
    shape (Sequence[int], optional): 1D `int32`. Shape of the generated samples.
        Defaults to [].
    seed (int): Python integer number.

Returns:
    Tensor, A tensor with prepended dimensions shape. The data type is float32.

r/   sampleseed_sampler   g        g      ?)r   minmaxr7   r'   r   )r
   r   r#   r$   r   r'   r   r   r/   r    itemfullr   r   uniform_random_batch_size_likereshapeadduniformzerosr%   )r0   r/   r7   r'   batch_shapeoutput_shape
fill_shapezero_tmpuniform_random_tmpzero_tmp_reshapeuniform_random_tmp_reshapeoutputs               r2   r6   Uniform.sample   s      uge}h?tVcH5Uyy9$DHHtyy0778 .Lk12J"LLDII)=>qAFFHJqM{{:sDJJ?H!'!F!Fjj"  &~~hE)/"*& 0 99,txx7F ZZt<FM .L^^JJCSt \<99txx')F ZZt<F$$~~f$??r4   c                   U R                  U R                  U5      n[        5       (       a  U R                  U:  nXR                  :  n[        R
                  " X!R                  5      n[        R
                  " X1R                  5      n[        R                  " XE-  5      [        R                  " U R                  U R                  -
  5      -
  $ U R                  S-   nU R                  U:  nXR                  :  n[        R
                  " X!R                  S9n[        R
                  " X1R                  S9n[        R                  " [        R                  " XE-  5      [        R                  " U R                  U R                  -
  5      US9$ )zLog probability density/mass function.

Args:
    value (Tensor): The input tensor.

Returns:
    Tensor, log probability.The data type is same with value.

	_log_probr   r<   )_check_values_dtype_in_probsr   r
   r   r   r,   r   r    logr'   subtractr0   valuelb_boolub_boollbubr'   s          r2   log_probUniform.log_prob   s    11$((EBhh&Gii'GWkk2BWkk2B::bg&DII4H)III99{*Dhh&Gii'GWKK8BWKK8B??

27#VZZ		DHH0D%ED r4   c                |   U R                  U R                  U5      n[        5       (       a{  U R                  U:  nXR                  :  n[        R
                  " X!R                  5      n[        R
                  " X1R                  5      nXE-  U R                  U R                  -
  -  $ U R                  S-   nU R                  U:  nXR                  :  n[        R
                  " X!R                  S9n[        R
                  " X1R                  S9n[        R                  " XE-  U R                  U R                  -
  US9$ )zProbability density/mass function.

Args:
    value (Tensor): The input tensor.

Returns:
    Tensor, probability. The data type is same with value.

_probsr   r<   )
rO   r   r
   r   r   r,   r   r'   r    dividerR   s          r2   probsUniform.probs  s     11$((EBhh&Gii'GWkk2BWkk2BG		DHH 45599x'Dhh&Gii'GWKK8BWKK8B=="'TYY-ANNr4   c                x    U R                   S-   n[        R                  " U R                  U R                  -
  US9$ )zShannon entropy in nats.

The entropy is

.. math::

    entropy(low, high) = \\log (high - low)

Returns:
    Tensor, Shannon entropy of uniform distribution.The data type is float32.

_entropyr<   )r'   r    rP   r   r   )r0   r'   s     r2   entropyUniform.entropy1  s0     yy:%zz$))dhh.T::r4   )r%   r&   r   r   r   r'   )N)r   r   r   r   r'   z
str | NonereturnNone)r/   zSequence[int]r7   r   rc   r   )rS   r   rc   r   )rc   r   )__name__
__module____qualname____firstlineno____doc____annotations__r.   r6   rX   r]   ra   __static_attributes____classcell__)r1   s   @r2   r   r   /   st    JX 
K
L  	D)D) D) 	D)
 
D) D)L -/A 4l:O2; ;r4   r   )%
__future__r   typingr   numpyr   numpy.typingnptr    r   paddle.base.data_feederr   r   paddle.base.frameworkr   paddle.distributionr	   paddle.frameworkr
   paddle.tensorr   collections.abcr   r   typing_extensionsr   r   paddle._typingr   r   NDArrayr   r   r   rj   Distributionr    r4   r2   <module>r}      s    #       = * , ,  (+-"'uE"**bjj012		#i P;l'' P;r4   