o
    Qe/                     @   s(  d dl mZ d dl mZmZ d dl mZ d dlmZmZmZm	Z	 d dl
mZ ddlZddlmZmZ dd	lmZ dd
lmZmZmZ g Zd-ddZd-ddZd.ddZd/ddZd0ddZd0ddZd/ddZd1ddZed2d d!Zdddgddfd"d#Zd3d$d%Z d4d'd(Z!d0d)d*Z"d5d+d,Z#dS )6   )core)convert_np_dtype_to_dtype_dygraph_only)LayerHelper)check_variable_and_dtype
check_typecheck_dtypecheck_shape)utils    N)_C_ops_legacy_C_ops)Variable)in_dygraph_mode_in_legacy_dygraph_current_expected_placec                 C   st   t  rt| S t rt| S t| dddgd tdi t }|j| j	d}|j
dd| id|ii d	 d
|_|S )a  

    For each element :math:`x_i` in input ``x``, take a sample from the Bernoulli distribution, also called two-point distribution, with success probability :math:`x_i`. The Bernoulli distribution with success probability :math:`x_i` is a discrete probability distribution with probability mass function

    .. math::
        p(y)=\begin{cases}
            x_i,&y=1\\
            1-x_i,&y=0
        \end{cases}.

    Args:
        x (Tensor): The input Tensor, it's data type should be float32, float64.
        name (str, optional): For details, please refer to :ref:`api_guide_Name`. Generally, no setting is required. Default: None.

    Returns: 
        Tensor: A Tensor filled samples from Bernoulli distribution, whose shape and dtype are same as ``x``.

    Examples:
        .. code-block:: python

            import paddle

            paddle.set_device('cpu')  # on CPU device
            paddle.seed(100) 

            x = paddle.rand([2,3])
            print(x)
            # [[0.55355281, 0.20714243, 0.01162981],
            #  [0.51577556, 0.36369765, 0.26091650]]

            out = paddle.bernoulli(x)
            print(out)
            # [[1., 0., 1.],
            #  [0., 1., 0.]]

    xfloat32float64	bernoullirandintdtypeXOuttypeinputsoutputsattrsTNr   )r   r   r   r   r   r   r   locals"create_variable_for_type_inferencer   	append_opstop_gradientr   namehelperout r)   DD:\Projects\ConvertPro\env\Lib\site-packages\paddle/tensor/random.pyr      s    &

r   c                 C   sp   t  rt| S t rt| S t| dddgd td
i t }|j	| j
d}|jdd| id|ii d |S )ag  
    Returns a tensor filled with random number from a Poisson Distribution.

    .. math::

        out_i \sim Poisson (lambda = x_i)

    Args:
        x(Tensor):  A tensor with rate parameter of poisson Distribution. The data type 
            should be float32, float64.
        name(str, optional): The default value is None. Normally there is no
            need for user to set this property. For more information, please
            refer to :ref:`api_guide_Name`.
    Returns: 
        Tensor: A Tensor filled with random number with the same shape and dtype as ``x``.

    Examples:
        .. code-block:: python

            import paddle
            paddle.set_device('cpu')
            paddle.seed(100)

            x = paddle.uniform([2,3], min=1.0, max=5.0)
            out = paddle.poisson(x)
            #[[2., 5., 0.],
            # [5., 1., 3.]]

    r   r   r   poissonr   r   r   r   N)r+   )r   r   r+   paddlein_dynamic_moder   r   r   r!   r"   r   r#   r%   r)   r)   r*   r+   W   s   

r+      Fc                 C   s   t  dks
J dt rt| ||S t r t| d|d|S t| dddgd tdi t	 }|j
td	d
}|jdd| id|i||dd d|_|S )aN  
    Returns a Tensor filled with random values sampled from a Multinomical
    distribution. The input ``x`` is a tensor with probabilities for generating the
    random number. Each element in ``x`` should be larger or equal to 0, but not all
    0. ``replacement`` indicates whether it is a replaceable sample. If ``replacement``
    is True, a category can be sampled more than once.

    Args:
        x(Tensor):  A tensor with probabilities for generating the random number. The data type
            should be float32, float64.
        num_samples(int, optional): Number of samples, default is 1.
        replacement(bool, optional): Whether it is a replaceable sample, default is False.
        name(str, optional): The default value is None. Normally there is no
            need for user to set this property. For more information, please
            refer to :ref:`api_guide_Name`.
    Returns:
        Tensor: A Tensor filled with sampled category index after ``num_samples`` times samples.

    Examples:
        .. code-block:: python

            import paddle

            paddle.seed(100) # on CPU device
            x = paddle.rand([2,4])
            print(x)
            # [[0.5535528  0.20714243 0.01162981 0.51577556]
            # [0.36369765 0.2609165  0.18905126 0.5621971 ]]

            paddle.seed(200) # on CPU device
            out1 = paddle.multinomial(x, num_samples=5, replacement=True)
            print(out1)
            # [[3 3 0 0 0]
            # [3 3 3 1 0]]

            # out2 = paddle.multinomial(x, num_samples=5)
            # InvalidArgumentError: When replacement is False, number of samples
            #  should be less than non-zero categories

            paddle.seed(300) # on CPU device
            out3 = paddle.multinomial(x, num_samples=3)
            print(out3)
            # [[3 0 1]
            # [3 1 0]]

    Fz,multinomial op is not supported on ROCM yet.num_samplesreplacementr   r   r   multinomialint64r   r   r   )r/   r0   r   TN)r1   )r   Zis_compiled_with_rocmr   r   r1   r   r   r   r   r!   r"   r   r#   r$   )r   r/   r0   r&   r'   r(   r)   r)   r*   r1      s.   0
r1                 ?c                 C   s*  d}d}|du rt j }|dvrtd||t|tjjs$t	|}t
 r=t| } t }t| t|t||||S t rWt| } td| dt|dt|d	|d
|
S t| | t|d
ddg| i }||||dd}	tj||	| |d tdi t }
|
|}|
jd|d|i|	d d|_|S )a  
    Returns a Tensor filled with random values sampled from a Gaussian
    distribution, with ``shape`` and ``dtype``.

    Args:
        shape (list|tuple|Tensor): The shape of the output Tensor. If ``shape``
            is a list or tuple, the elements of it should be integers or Tensors
            (with the shape [1], and the data type int32 or int64). If ``shape``
            is a Tensor, it should be a 1-D Tensor(with the data type int32 or
            int64).
        mean (float|int, optional): Mean of the output tensor, default is 0.0.
        std (float|int, optional): Standard deviation of the output tensor, default
            is 1.0.
        seed (int, optional): Random seed of generator.
        dtype (str|np.dtype, optional): The data type of the output Tensor.
            Supported data types: float32, float64.
            Default is None, use global default dtype (see ``get_default_dtype``
            for details).
        name (str, optional): Name for the operation (optional, default is None). For more information, please refer to :ref:`api_guide_Name`.

    Returns:
        Tensor: A Tensor filled with random values sampled from a Gaussian
        distribution, with ``shape`` and ``dtype``. 
    z%gaussian/standard_normal/randn/normalr   Nr   r   z@{} only supports [float32, float64], but the default dtype is {}shapemeanstdseedr   r   r   F)r7   r8   r9   r   Z
use_mkldnnr   r   r6   Zop_typegaussiangaussian_randomr   r   Tr;   )r,   	frameworkget_default_dtype	TypeErrorformat
isinstancer   VarDescVarTyper   r   r
   convert_shape_to_listr   r   r<   floatr   r   r	   r   get_shape_tensor_inputsr   r!   r"   r#   r$   )r6   r7   r8   r   r&   Zop_type_for_checkr9   placer   r   r'   r(   r)   r)   r*   r;      s^   





r;   c                 C   s   t | dd||dS )a	  
    Returns a Tensor filled with random values sampled from a standard
    normal distribution with mean 0 and standard deviation 1, with ``shape``
    and ``dtype``.

    Args:
        shape (list|tuple|Tensor): The shape of the output Tensor. If ``shape``
            is a list or tuple, the elements of it should be integers or Tensors
            (with the shape [1], and the data type int32 or int64). If ``shape``
            is a Tensor, it should be a 1-D Tensor(with the data type int32 or
            int64).
        dtype (str|np.dtype, optional): The data type of the output Tensor.
            Supported data types: float32, float64.
            Default is None, use global default dtype (see ``get_default_dtype``
            for details).
        name (str, optional): Name for the operation (optional, default is None).
            For more information, please refer to :ref:`api_guide_Name`.

    Returns:
        Tensor: A Tensor filled with random values sampled from a standard
        normal distribution with mean 0 and standard deviation 1, with
        ``shape`` and ``dtype``.

    Examples:
        .. code-block:: python

            import paddle

            # example 1: attr shape is a list which doesn't contain Tensor.
            out1 = paddle.standard_normal(shape=[2, 3])
            # [[-2.923464  ,  0.11934398, -0.51249987],  # random
            #  [ 0.39632758,  0.08177969,  0.2692008 ]]  # random

            # example 2: attr shape is a list which contains Tensor.
            dim1 = paddle.to_tensor([2], 'int64')
            dim2 = paddle.to_tensor([3], 'int32')
            out2 = paddle.standard_normal(shape=[dim1, dim2, 2])
            # [[[-2.8852394 , -0.25898588],  # random
            #   [-0.47420555,  0.17683524],  # random
            #   [-0.7989969 ,  0.00754541]],  # random
            #  [[ 0.85201347,  0.32320443],  # random
            #   [ 1.1399018 ,  0.48336947],  # random
            #   [ 0.8086993 ,  0.6868893 ]]]  # random

            # example 3: attr shape is a Tensor, the data type must be int64 or int32.
            shape_tensor = paddle.to_tensor([2, 3])
            out3 = paddle.standard_normal(shape_tensor)
            # [[-2.878077 ,  0.17099959,  0.05111201]  # random
            #  [-0.3761474, -1.044801  ,  1.1870178 ]]  # random

    r3   r4   )r6   r7   r8   r   r&   r=   r6   r   r&   r)   r)   r*   standard_normal  s   4rJ   c                 C   s   t | ||S )a  
    Returns a Tensor filled with random values sampled from a standard
    normal distribution with mean 0 and standard deviation 1, with ``shape``
    and ``dtype``.

    Args:
        shape (list|tuple|Tensor): The shape of the output Tensor. If ``shape``
            is a list or tuple, the elements of it should be integers or Tensors
            (with the shape [1], and the data type int32 or int64). If ``shape``
            is a Tensor, it should be a 1-D Tensor(with the data type int32 or
            int64).
        dtype (str|np.dtype, optional): The data type of the output Tensor.
            Supported data types: float32, float64.
            Default is None, use global default dtype (see ``get_default_dtype``
            for details).
        name (str, optional): Name for the operation (optional, default is None).
            For more information, please refer to :ref:`api_guide_Name`.

    Returns:
        Tensor: A Tensor filled with random values sampled from a standard
        normal distribution with mean 0 and standard deviation 1, with
        ``shape`` and ``dtype``.

    Examples:
        .. code-block:: python

            import paddle

            # example 1: attr shape is a list which doesn't contain Tensor.
            out1 = paddle.randn(shape=[2, 3])
            # [[-2.923464  ,  0.11934398, -0.51249987],  # random
            #  [ 0.39632758,  0.08177969,  0.2692008 ]]  # random

            # example 2: attr shape is a list which contains Tensor.
            dim1 = paddle.to_tensor([2], 'int64')
            dim2 = paddle.to_tensor([3], 'int32')
            out2 = paddle.randn(shape=[dim1, dim2, 2])
            # [[[-2.8852394 , -0.25898588],  # random
            #   [-0.47420555,  0.17683524],  # random
            #   [-0.7989969 ,  0.00754541]],  # random
            #  [[ 0.85201347,  0.32320443],  # random
            #   [ 1.1399018 ,  0.48336947],  # random
            #   [ 0.8086993 ,  0.6868893 ]]]  # random

            # example 3: attr shape is a Tensor, the data type must be int64 or int32.
            shape_tensor = paddle.to_tensor([2, 3])
            out3 = paddle.randn(shape_tensor)
            # [[-2.878077 ,  0.17099959,  0.05111201]  # random
            #  [-0.3761474, -1.044801  ,  1.1870178 ]]  # random
    )rJ   rI   r)   r)   r*   randnS  s   3rK   c                 C   s<  t  sAt| dtttfd t|dtttfd t| tr(t| jdddgdd t|tr8t|jdddgdd |durAt	|d t| trst|trd|j| jkrXt 
|| j}t | }t ||}nt|}tt | | j|}nt|trt| } tt ||j|}nt|| ||d	S || |  }t  sd
|_|S )a_
  
    Returns a Tensor filled with random values sampled from a normal
    distribution with ``mean`` and ``std`` (standard deviation) .

    If ``mean`` is a Tensor, the output Tensor has the same shape and data type as ``mean``.
    If ``mean`` is not a Tensor and ``std`` is a Tensor, the output Tensor has the same shape and data type as ``std``.
    If ``mean`` and ``std`` are not a Tensor, the output Tensor has the same shape as ``shape``, with data type float32.

    If ``mean`` and ``std`` are Tensor, the num of elements of ``mean`` and ``std`` should be the same.

    Args:
        mean (float|Tensor, optional): The mean of the output Tensor's normal distribution.
            If ``mean`` is float, all elements of the output Tensor shared the same mean.
            If ``mean`` is a Tensor(data type supports float32, float64), it has per-element means.
            Default is 0.0
        std (float|Tensor, optional): The  standard deviation of the output Tensor's normal distribution.
            If ``std`` is float, all elements of the output Tensor shared the same standard deviation.
            If ``std`` is a Tensor(data type supports float32, float64), it has per-element standard deviations.
            Defaule is 1.0
        shape (list|tuple|Tensor, optional): The shape of the output Tensor. If ``shape``
            is a list or tuple, the elements of it should be integers or Tensors
            (with the shape [1], and the data type int32 or int64). If ``shape``
            is a Tensor, it should be a 1-D Tensor(with the data type int32 or
            int64). If ``mean`` or ``std`` is a Tensor, the shape of the output
            Tensor is the same as ``mean`` or ``std`` , attr ``shape`` is ignored.
            Default is None
        name (str, optional): Name for the operation (optional, default is None).
            For more information, please refer to :ref:`api_guide_Name`.

    Returns:
        A Tensor filled with random values sampled from a normal distribution with ``mean`` and ``std`` .

    Examples:
        .. code-block:: python

            import paddle

            out1 = paddle.normal(shape=[2, 3])
            # [[ 0.17501129  0.32364586  1.561118  ]  # random
            #  [-1.7232178   1.1545963  -0.76156676]]  # random

            mean_tensor = paddle.to_tensor([1.0, 2.0, 3.0])
            out2 = paddle.normal(mean=mean_tensor)
            # [ 0.18644847 -1.19434458  3.93694787]  # random

            std_tensor = paddle.to_tensor([1.0, 2.0, 3.0])
            out3 = paddle.normal(mean=mean_tensor, std=std_tensor)
            # [1.00780561 3.78457445 5.81058198]  # random

    r7   normalr8   r   r   z@If mean is Tensor, it's data type only support float32, float64.z?If std is Tensor, it's data type only support float32, float64.N)r6   r7   r8   r&   T)r,   r-   r   intrF   r   rB   r   r   r	   castr6   ZreshaperJ   r;   Zstop_grediant)r7   r8   r6   r&   Z
mean_shaper(   r)   r)   r*   rL     s>   3






rL         c           
      C   sJ  |du rt j }|dvrtd|t|tjjst	|}t
 r6t| } t| |t|t||t S t rPt| } td| dt|dt|d|d|
S t| dtttfd	 t|ddd	 t|dtttfd	 t|dtttfd	 t }||||d
}tj||| d	d tdi t }||}	|jd||d|	id d|	_|	S )a  
    Returns a Tensor filled with random values sampled from a uniform
    distribution in the range [``min``, ``max``), with ``shape`` and ``dtype``.

    Examples:

    .. code-block:: text

        Input:
          shape = [1, 2]
        Output:
          result=[[0.8505902, 0.8397286]]

    Args:
        shape(list|tuple|Tensor): The shape of the output Tensor. If ``shape``
            is a list or tuple, the elements of it should be integers or Tensors
            (with the shape [1], and the data type int32 or int64). If ``shape``
            is a Tensor, it should be a 1-D Tensor(with the data type int32 or
            int64).
        dtype(str|np.dtype, optional): The data type of the output Tensor.
            Supported data types: float32, float64.
            Default is None, use global default dtype (see ``get_default_dtype``
            for details).
        min(float|int, optional): The lower bound on the range of random values
            to generate, ``min`` is included in the range. Default is -1.0.
        max(float|int, optional): The upper bound on the range of random values
            to generate, ``max`` is excluded in the range. Default is 1.0.
        seed(int, optional): Random seed used for generating samples. If seed is 0,
            it will use the seed of the global default generator (which can be set by paddle.seed). 
            Note that if seed is not 0, this operator will always generate the same random numbers every
            time. Default is 0.
        name(str, optional): Name for the operation (optional, default is None).
            For more information, please refer to :ref:`api_guide_Name`.

    Returns:
        Tensor: A Tensor filled with random values sampled from a uniform
        distribution in the range [``min``, ``max``), with ``shape`` and ``dtype``.

    Examples:
        .. code-block:: python
          :name: code-example1
            
            import paddle

            # example 1:
            # attr shape is a list which doesn't contain Tensor.
            out1 = paddle.uniform(shape=[3, 4])
            # [[ 0.84524226,  0.6921872,   0.56528175,  0.71690357], # random
            #  [-0.34646994, -0.45116323, -0.09902662, -0.11397249], # random
            #  [ 0.433519,    0.39483607, -0.8660099,   0.83664286]] # random

            # example 2:
            # attr shape is a list which contains Tensor.
            dim1 = paddle.to_tensor([2], 'int64')
            dim2 = paddle.to_tensor([3], 'int32')
            out2 = paddle.uniform(shape=[dim1, dim2])
            # [[-0.9951253,   0.30757582, 0.9899647 ], # random
            #  [ 0.5864527,   0.6607096,  -0.8886161]] # random

            # example 3:
            # attr shape is a Tensor, the data type must be int64 or int32.
            shape_tensor = paddle.to_tensor([2, 3])
            out3 = paddle.uniform(shape_tensor)
            # [[-0.8517412,  -0.4006908,   0.2551912 ], # random
            #  [ 0.3364414,   0.36278176, -0.16085452]] # random
    Nr5   zJuniform/rand only supports [float32, float64], but the default dtype is {}r6   minmaxr9   r   zuniform/rand)r9   rP   rQ   r   r:   uniformuniform_randomr   )r   r   r   r   TrR   ) r,   r>   r?   r@   rA   rB   r   rC   rD   r   r   r
   rE   r   rS   rF   r   r   r   r   listtupler   r   rM   dictrG   r   r!   r"   r#   r$   )
r6   r   rP   rQ   r9   r&   r   r   r'   r(   r)   r)   r*   rR     sR   C



rR   c              	   C   s2   t  rt| |||dddS t| d|d|d|S )a  
    This is the inplace version of OP ``uniform``, which returns a Tensor filled 
    with random values sampled from a uniform distribution. The output Tensor will
    be inplaced with input ``x``. Please refer to :ref:`api_tensor_uniform`.
    
    Args:
        x(Tensor): The input tensor to be filled with random values.
        min(float|int, optional): The lower bound on the range of random values
            to generate, ``min`` is included in the range. Default is -1.0.
        max(float|int, optional): The upper bound on the range of random values
            to generate, ``max`` is excluded in the range. Default is 1.0.
        seed(int, optional): Random seed used for generating samples. If seed is 0, 
            it will use the seed of the global default generator (which can be set by paddle.seed). 
            Note that if seed is not 0, this operator will always generate the same random numbers every
            time. Default is 0.
        name(str, optional): The default value is None. Normally there is no
            need for user to set this property. For more information, please
            refer to :ref:`api_guide_Name`.
    Returns:
        Tensor: The input tensor x filled with random values sampled from a uniform
        distribution in the range [``min``, ``max``).
    Examples:
        .. code-block:: python
            
            import paddle
            # example:
            x = paddle.ones(shape=[3, 4])
            x.uniform_()
            print(x)
            # [[ 0.84524226,  0.6921872,   0.56528175,  0.71690357], # random
            #  [-0.34646994, -0.45116323, -0.09902662, -0.11397249], # random
            #  [ 0.433519,    0.39483607, -0.8660099,   0.83664286]] # random
    r   r4   rP   rQ   r9   )r   r   Zuniform_random_inplace_r   )r   rP   rQ   r9   r&   r)   r)   r*   uniform_P  s
   #rX   c           
      C   s2  |du r| dkrt d| | }d} |du rd}t|tjjs$t|}t r8t	|}t
 }t| ||||S t rNt	|}td|d| d|ddd	|
S t|d
 t|d	ddgd
 | |krht d| |t }| |d|d}tj|||d
d tdi t }|j|d}	|jd
|d|	i|d d|	_|	S )a
  
    Returns a Tensor filled with random integers from a discrete uniform
    distribution in the range [``low``, ``high``), with ``shape`` and ``dtype``.
    If ``high`` is None (the default), the range is [0, ``low``).

    Args:
        low (int, optional): The lower bound on the range of random values to generate.
            The ``low`` is included in the range. If ``high`` is None, the
            range is [0, ``low``). Default is 0.
        high (int, optional): The upper bound on the range of random values to
            generate, the ``high`` is excluded in the range. Default is None
            (see above for behavior if high = None). Default is None.
        shape (list|tuple|Tensor, optional): The shape of the output Tensor. If ``shape``
            is a list or tuple, the elements of it should be integers or Tensors
            (with the shape [1], and the data type int32 or int64). If ``shape``
            is a Tensor, it should be a 1-D Tensor(with the data type int32 or
            int64). Default is [1].
        dtype (str|np.dtype, optional): The data type of the
            output tensor. Supported data types: int32, int64. If ``dytpe``
            is None, the data type is int64. Default is None.
        name (str, optional): The default value is None.  Normally there is no
            need for user to set this property.  For more information, please
            refer to :ref:`api_guide_Name`.

    Returns: 
        Tensor: A Tensor filled with random integers from a discrete uniform
        distribution in the range [``low``, ``high``), with ``shape`` and ``dtype``.

    Examples:
        .. code-block:: python

            import paddle

            # example 1:
            # attr shape is a list which doesn't contain Tensor.
            out1 = paddle.randint(low=-5, high=5, shape=[3])
            # [0, -3, 2]  # random

            # example 2:
            # attr shape is a list which contains Tensor.
            dim1 = paddle.to_tensor([2], 'int64')
            dim2 = paddle.to_tensor([3], 'int32')
            out2 = paddle.randint(low=-5, high=5, shape=[dim1, dim2])
            # [[0, -1, -3],  # random
            #  [4, -2,  0]]  # random

            # example 3:
            # attr shape is a Tensor
            shape_tensor = paddle.to_tensor(3)
            out3 = paddle.randint(low=-5, high=5, shape=shape_tensor)
            # [-2, 2, 3]  # random

            # example 4:
            # data type is int32
            out4 = paddle.randint(low=-5, high=5, shape=[3], dtype='int32')
            # [-5, 4, -4]  # random

            # example 5:
            # Input only one parameter
            # low=0, high=10, shape=[1], dtype='int64'
            out5 = paddle.randint(10)
            # [7]  # random

    Nr   DIf high is None, low must be greater than 0, but received low = {0}.r2   r6   lowhighr9   r   r   int32zErandint's low must less then high, but received low = {0}, high = {1}rZ   r[   r9   r   r:   r   r   r   Tr    )
ValueErrorrA   rB   r   rC   rD   r   r   r
   rE   r   r   r   r   r   r	   r   rW   rG   r   r!   r"   r#   r$   )
rZ   r[   r6   r   r&   rH   r   r   r'   r(   r)   r)   r*   r   z  sX   A


r   c           
      C   s6  |du r|dkrt d||}d}|du r| j}t|tjjs%t|}t	| }||kr6t d||t
 rXt|}td|d|d|ddd	tjjj
}t||}|S t|d
 t|d	g dd
 d|i}||dtjjjd}tdi t }	|	jtjjjd}|	jd|d|i|d d|_t||}|S )a  
    Returns a Tensor filled with random integers from a discrete uniform
    distribution in the range [``low``, ``high``), with the same shape as ``x``.
    (use ``dtype`` if ``dtype`` is not None) 
    If ``high`` is None (the default), the range is [0, ``low``).

    Args:
        x (Tensor): The input tensor which specifies shape. The dtype of ``x`` 
            can be bool, int32, int64, float16, float32, float64.
        low (int): The lower bound on the range of random values to generate.
            The ``low`` is included in the range. If ``high`` is None, the
            range is [0, ``low``). Default is 0.
        high (int, optional): The upper bound on the range of random values to
            generate, the ``high`` is excluded in the range. Default is None
            (see above for behavior if high = None). Default is None.
        dtype (str|np.dtype, optional): The data type of the
            output tensor. Supported data types: bool, int32, int64, float16, 
            float32, float64. If ``dytpe`` is None, the data type is the
            same as x's data type. Default is None.
        name (str, optional): The default value is None.  Normally there is no
            need for user to set this property.  For more information, please
            refer to :ref:`api_guide_Name`.

    Returns: 
        Tensor: A Tensor filled with random integers from a discrete uniform
        distribution in the range [``low``, ``high``), with ``shape`` and ``dtype``.

    Examples:
        .. code-block:: python

            import paddle

            # example 1:
            # dtype is None and the dtype of x is float16
            x = paddle.zeros((1,2)).astype("float16")
            out1 = paddle.randint_like(x, low=-5, high=5)
            print(out1)
            print(out1.dtype)
            # [[0, -3]]  # random
            # paddle.float16

            # example 2:
            # dtype is None and the dtype of x is float32
            x = paddle.zeros((1,2)).astype("float32")
            out2 = paddle.randint_like(x, low=-5, high=5)
            print(out2)
            print(out2.dtype)
            # [[0, -3]]  # random
            # paddle.float32

            # example 3:
            # dtype is None and the dtype of x is float64
            x = paddle.zeros((1,2)).astype("float64")
            out3 = paddle.randint_like(x, low=-5, high=5)
            print(out3)
            print(out3.dtype)
            # [[0, -3]]  # random
            # paddle.float64

            # example 4:
            # dtype is None and the dtype of x is int32
            x = paddle.zeros((1,2)).astype("int32")
            out4 = paddle.randint_like(x, low=-5, high=5)
            print(out4)
            print(out4.dtype)
            # [[0, -3]]  # random
            # paddle.int32

            # example 5:
            # dtype is None and the dtype of x is int64
            x = paddle.zeros((1,2)).astype("int64")
            out5 = paddle.randint_like(x, low=-5, high=5)
            print(out5)
            print(out5.dtype)
            # [[0, -3]]  # random
            # paddle.int64

            # example 6:
            # dtype is float64 and the dtype of x is float32
            x = paddle.zeros((1,2)).astype("float32")
            out6 = paddle.randint_like(x, low=-5, high=5, dtype="float64")
            print(out6)
            print(out6.dtype)
            # [[0, -1]]  # random
            # paddle.float64

            # example 7:
            # dtype is bool and the dtype of x is float32
            x = paddle.zeros((1,2)).astype("float32")
            out7 = paddle.randint_like(x, low=-5, high=5, dtype="bool")
            print(out7)
            print(out7.dtype)
            # [[0, -1]]  # random
            # paddle.bool

            # example 8:
            # dtype is int32 and the dtype of x is float32
            x = paddle.zeros((1,2)).astype("float32")
            out8 = paddle.randint_like(x, low=-5, high=5, dtype="int32")
            print(out8)
            print(out8.dtype)
            # [[0, -1]]  # random
            # paddle.int32

            # example 9:
            # dtype is int64 and the dtype of x is float32
            x = paddle.zeros((1,2)).astype("float32")
            out9 = paddle.randint_like(x, low=-5, high=5, dtype="int64")
            print(out9)
            print(out9.dtype)
            # [[0, -1]]  # random
            # paddle.int64

            # example 10:
            # dtype is int64 and the dtype of x is bool
            x = paddle.zeros((1,2)).astype("bool")
            out10 = paddle.randint_like(x, low=-5, high=5, dtype="int64")
            print(out10)
            print(out10.dtype)
            # [[0, -1]]  # random
            # paddle.int64

    Nr   rY   zJrandint_like's low must less then high, but received low = {0}, high = {1}r6   rZ   r[   r9   r   randint_like)boolZfloat16r   r   r\   r2   ZShapeTensorr]   r   r   r   r   Tr    )r^   rA   r   rB   r   rC   rD   r   r,   r6   r-   r
   rE   r   r   ZINT64rN   r	   r   r   r!   r"   r#   r$   )
r   rZ   r[   r   r&   r6   r(   r   r   r'   r)   r)   r*   r_     sb   |


r_   r2   c                 C   s   t |tjjst|}t rt| |t S t	 r#t
d| ddd|S | dk r+tdt|dg dd tdi t }||}| |dd	}|jdi d
|i|d d|_|S )a  
    Returns a 1-D Tensor filled with random permutation values from 0
    to n-1, with ``dtype``.

    Args:
        n (int): The upper bound (exclusive), and it should be greater than 0.
        dtype (str|np.dtype, optional): The data type of
            the output Tensor. Supported data types: int32, int64, float32,
            float64. Default is int64.
        name (str, optional): The default value is None. Normally there is no
            need for user to set this property. For more information, please
            refer to :ref:`api_guide_Name`.

    Returns:
        Tensor: A 1-D Tensor filled with random permutation values from 0
        to n-1, with ``dtype``.

    Examples:
        .. code-block:: python

            import paddle

            out1 = paddle.randperm(5)
            # [4, 1, 2, 3, 0]  # random

            out2 = paddle.randperm(7, 'int32')
            # [1, 6, 2, 0, 4, 3, 5]  # random
 
    nr9   r   r   r.   z4The input n should be greater than 0 in randperm op.)r2   r\   r   r   randperm)ra   r   r9   r   r   TN)rb   )rB   r   rC   rD   r   r   r   rb   r   r   r   r^   r   r   r!   r"   r#   r$   )ra   r   r&   r'   r(   r   r)   r)   r*   rb     s*   
rb   c                 C   s   t | |dd|dS )a  
    Returns a Tensor filled with random values sampled from a uniform
    distribution in the range [0, 1), with ``shape`` and ``dtype``.

    Args:
        shape (list|tuple|Tensor): The shape of the output Tensor. If ``shape``
            is a list or tuple, the elements of it should be integers or Tensors
            (with the shape [1], and the data type int32 or int64). If ``shape``
            is a Tensor, it should be a 1-D Tensor(with the data type int32 or
            int64).
        dtype (str|np.dtype, optional): The data type of the output Tensor.
            Supported data types: float32, float64.
            Default is None, use global default dtype (see ``get_default_dtype``
            for details).
        name (str, optional): The default value is None. Normally there is no
            need for user to set this property. For more information, please
            refer to :ref:`api_guide_Name`.

    Returns:
        Tensor: A Tensor filled with random values sampled from a uniform
        distribution in the range [0, 1), with ``shape`` and ``dtype``.

    Examples:
        .. code-block:: python

            import paddle

            # example 1: attr shape is a list which doesn't contain Tensor.
            out1 = paddle.rand(shape=[2, 3])
            # [[0.451152  , 0.55825245, 0.403311  ],  # random
            #  [0.22550228, 0.22106001, 0.7877319 ]]  # random

            # example 2: attr shape is a list which contains Tensor.
            dim1 = paddle.to_tensor([2], 'int64')
            dim2 = paddle.to_tensor([3], 'int32')
            out2 = paddle.rand(shape=[dim1, dim2, 2])
            # [[[0.8879919 , 0.25788337],  # random
            #   [0.28826773, 0.9712097 ],  # random
            #   [0.26438272, 0.01796806]],  # random
            #  [[0.33633623, 0.28654453],  # random
            #   [0.79109055, 0.7305809 ],  # random
            #   [0.870881  , 0.2984597 ]]]  # random

            # example 3: attr shape is a Tensor, the data type must be int64 or int32.
            shape_tensor = paddle.to_tensor([2, 3])
            out3 = paddle.rand(shape_tensor)
            # [[0.22920267, 0.841956  , 0.05981819],  # random
            #  [0.4836288 , 0.24573246, 0.7516129 ]]  # random

    r3   r4   )rP   rQ   r&   rT   rI   r)   r)   r*   rand  s   3rc   c                 C   sl   t  r	t| |S t rt| d|S t| dddgd td
i t }|j	dd| id| id|id | S )a  
    This inplace OP fill input Tensor ``x`` with random number from a Exponential Distribution.

    ``lam`` is :math:`\lambda` parameter of Exponential Distribution. 
    
    .. math::

        f(x) = \lambda e^{-\lambda x}

    Args:
        x(Tensor):  Input tensor. The data type should be float32, float64.
        lam(float, optional): :math:`\lambda` parameter of Exponential Distribution. Default, 1.0.
        name(str, optional): The default value is None. Normally there is no
            need for user to set this property. For more information, please
            refer to :ref:`api_guide_Name`.
    Returns: 
        Tensor: Input Tensor ``x``.

    Examples:
        .. code-block:: python

            import paddle
            paddle.set_device('cpu')
            paddle.seed(100)

            x = paddle.empty([2,3])
            x.exponential_()
            # [[0.80643415, 0.23211166, 0.01169797],
            #  [0.72520673, 0.45208144, 0.30234432]]

    lambdar   r   r   exponentialr   r   r   N)re   )
r   r   exponential_r,   r-   r   r   r   r!   r#   )r   Zlamr&   r'   r)   r)   r*   rf     s    rf   )N)r.   FN)r3   r4   NN)NN)NrO   r4   r   N)rO   r4   r   N)r   NNN)r2   N)r4   N)$r>   r   r   r   r   Zfluid.data_feederr   r   r   r	   Zfluid.layersr
   r,   r   r   Zpaddle.staticr   Zpaddle.fluid.frameworkr   r   r   __all__r   r+   r1   r;   rJ   rK   rL   rR   rX   r   r_   rb   rc   rf   r)   r)   r)   r*   <module>   s4   

9
/
J
L
7
6
Xo)
n 
0
66