o
    #j                    @   sB  d dl Z d dlZd dlZd dlZd dlZd dlmZ d dlmZ ddl	m
Z
mZmZmZ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mZmZmZmZmZmZ g Zd	d
 Z dd Z!	d^ddZ"	d_ddZ#d`ddZ$daddZ%dbddZ&dcddZ'daddZ(dcddZ)dad d!Z*ddd"d#Z+dad$d%Z,dad&d'Z-dad(d)Z.dad*d+Z/ded,d-Z0dad.d/Z1dfd1d2Z2d3d4 Z3dgd5d6Z4edgd7d8Z5dgd9d:Z6edgd;d<Z7d=d> Z8dhdAdBZ9dgdCdDZ:didEdFZ;dadGdHZ<dadIdJZ=djdKdLZ>djdMdNZ?dadOdPZ@djdQdRZAdkdTdUZBdldVdWZCdjdXdYZDedmdZd[ZEedjd\d]ZFdS )n    N)_C_ops)inplace_apis_in_dygraph_only   )check_dtype
check_typecheck_variable_and_dtypeconvert_dtypeconvert_float_to_uint16)Variabledevice_guard)	ParamAttr)
LayerHelper_current_expected_place_current_expected_place__get_paddle_placeconvert_np_dtype_to_dtype_coredygraph_onlyin_dynamic_modein_dynamic_or_pir_modein_pir_modec                 C   4   | t jjjkrt jjjS | t jjjkrt jjjS | S N)r   VarDescVarType	COMPLEX64FP32
COMPLEX128FP64dtype r!   W/var/www/html/Deteccion_Ine/venv/lib/python3.10/site-packages/paddle/tensor/creation.py_complex_to_real_dtype4   
   

r#   c                 C   r   r   )r   r   r   r   r   r   r   r   r!   r!   r"   _real_to_complex_dtype=   r$   r%   Fc           	   
   C   s   t | dtttjfd | D ]}t |dttjtjtjtj	tj
fd qt|dg dd tdi t }|j|| ||dd}|j|tjjjt||d	d
 |S )a4  
    This function creates a new tensor variable with value in the global block(block 0).

    Args:
        shape (list[int]|tuple[int]): Shape of the variable
        value (float): The value of the variable. The new created
                      variable will be filled with it.
        dtype (str): Data type of the variable
        persistable (bool, optional): If this variable is persistable.
                           Default: False
        force_cpu (bool, optional): Force this variable to be on CPU.
                         Default: False
        name (str, optional): For detailed information, please refer to
           :ref:`api_guide_Name` . Usually name is no need to set and None by default.

    Returns:
        Variable: The created Variable

    Examples:
        .. code-block:: python

            >>> import paddle
            >>> paddle.enable_static()
            >>> var = paddle.static.create_global_var(shape=[2,3], value=1.0, dtype='float32',
            ...                                persistable=True, force_cpu=True, name='new_var')
    shapecreate_global_varitem of shaper    )
boolfloat16float32float64int8int16int32int64uint8uint16
global_varT)r    r&   persistablenamestop_gradient)value	force_cpu)initializerN)r3   )r   listtuplenpndarrayintr1   r-   r.   r/   r0   r   r   localsZcreate_global_variableZset_variable_initializerpaddlennr9   ZConstantInitializerfloat)	r&   r7   r    r4   r8   r5   itemhelpervarr!   r!   r"   r'   F   sF   r'   c              
   C   s   t | dtttjfd | D ]}t |dttjtjtjtj	tj
fd qt|dg dd t |dtdtfd t |dtdtjjjfd td
i t }|du rUt|d	}||| t|||S )a  
    This function creates a parameter. The parameter is a learnable variable, which can have
    gradient, and can be optimized.

    Note:
        This is a very low-level API. This API is useful when you create operator by your self, instead of using layers.

    Args:
        shape (list of int): Shape of the parameter
        dtype (str): Data type of the parameter. It can be set as 'float16', 'float32', 'float64'.
        name (str, optional): For detailed information, please refer to
           :ref:`api_guide_Name` . Usually name is no need to set and None by default.
        attr (ParamAttr, optional): Attribute object of the specified argument. For detailed information, please refer to
           :ref:`api_paddle_ParamAttr` None by default, which means that ParamAttr will be initialized as it is.
        is_bias (bool, optional): This can affect which default initializer is chosen
                       when default_initializer is None. If is_bias,
                       initializer.Constant(0.0) will be used. Otherwise,
                       Xavier() will be used.
        default_initializer (Initializer, optional): Initializer for the parameter

    Returns:
        The created parameter.

    Examples:
        .. code-block:: python

            >>> import paddle
            >>> paddle.enable_static()
            >>> W = paddle.create_parameter(shape=[784, 200], dtype='float32')
    r&   create_parameterr(   r    )
r)   r*   r2   r+   r,   r-   r.   r/   r0   r1   attrNdefault_initializer)r5   )rF   )r   r:   r;   r<   r=   r>   r1   r-   r.   r/   r0   r   typer   r@   rA   r9   ZInitializerr   r?   rF   r   )r&   r    r5   rG   Zis_biasrH   rC   rD   r!   r!   r"   rF      sB   !
rF   c                 C   s4   t | dg dd tdi t }|j|j| |dS )a  
    Create a variable, which will hold a Tensor with data type dtype.

    Args:
        dtype(string|numpy.dtype): the data type of Tensor to be created, the
            data type is bool, float16, float32, float64, int8, int16, int32 and int64.
        name(string, 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`
        persistable(bool): Set the persistable flag of the create tensor.
            default value is False.

    Returns:
        Variable: The tensor to be created according to dtype.

    Examples:
        .. code-block:: python

            >>> import paddle
            >>> tensor = paddle.tensor.create_tensor(dtype='float32')
    r    )r)   r*   r+   r,   r-   r/   r/   r0   create_tensorr5   r    r4   N)rJ   )r   r   r?   create_variabler5   )r    r5   r4   rD   r!   r!   r"   rJ      s   
rJ   c                 C   s  |du rt  }|}| }|}t|tt jjfst|dtd t|tj	j
s)t|}t| tt jjfsOtd tdg|| dd}W d   n1 sJw   Y  t|tt jjfsutd tdg||dd}W d   n1 spw   Y  t|tt jjfstd tdgd|dd}W d   n1 sw   Y  t rt||||t S tdi t }t|j}	t|j}
t|}t| trt| jd	g d
d n	t| d	ttfd t|trt|jdg d
d n	t|dttfd t|trt|jddgd t|dg d
d |
dks|	dkr|dv s%|
dks |	dkr.|dkr.td|	|
||j|d}|jd|||dd|id|gid t|trS|j|f |S )a  
    Return fixed number of evenly spaced values within a given interval. Note: no gradient calculation is performed.

    Args:
        start(int|float|Tensor): The input :attr:`start` is start of range. It is a int, float, \
            or a 0-D Tensor with data type int32, int64, float32 or float64.
        stop(int|float|Tensor): The input :attr:`stop` is end of range. It is a int, float, \
            or a 0-D Tensor with data type int32, int64, float32 or float64.
        num(int|Tensor): The input :attr:`num` is given num of the sequence. It is an int, \
            or a 0-D Tensor with data type int32.
        dtype(np.dtype|str, optional): The data type of output tensor, it could be
            int32, int64, float32 and float64. Default: if None, the data type is float32.
        name(str, optional): For details, please refer to :ref:`api_guide_Name`. Generally, no setting is required. Default: None.

    Returns:
        Tensor: the output data type will be float32, float64. The 1-D tensor with fixed number of evenly spaced values, \
        the data shape of this tensor is :math:`[num]` . If the :attr:`num` is set 1, the output tensor just has \
        the value with input :attr:`start`.

    Examples:
        .. code-block:: python

            >>> import paddle
            >>> data = paddle.linspace(0, 10, 5, 'float32')
            >>> print(data.numpy())
            [0. 2.5 5. 7.5 10.]
            >>> data = paddle.linspace(0, 10, 1, 'float32')
            >>> print(data.numpy())
            [0.]

    Nnumlinspacecpu   Tr8   r/   startr*   r2   r+   r,   r/   r0   stopr    r,   r+   r/   r0   zThe dtype of start/stop is {}/{} but the attr(dtype) of linspace is {}, which may cause data type overflows. Please reset attr(dtype) of linspace.r   )StartStopNumOutrI   inputsattrsoutputs)rN   )r@   get_default_dtype
isinstancer
   pirOpResultr   r>   r   r   r   r   r   fill_constantr   r   rN   r   r   r?   r   r    r   rB   
ValueErrorformat"create_variable_for_type_inference	append_opdesc	set_shape)rR   rT   rM   r    r5   
tensor_numtensor_starttensor_stoprD   start_dtype
stop_dtype	out_dtypeoutr!   r!   r"   rN     s    










rN         $@c                 C   sL  |du rt  }|}| }|}|}	t|tt jjfs t|dtd t|tj	j
tjfs.t|}t| tt jjfsRtd tdg|| }W d   n1 sMw   Y  t|tt jjfsvtd tdg||}W d   n1 sqw   Y  t|tt jjfstd tdgd|}W d   n1 sw   Y  t|tt jjfstd tdg||}	W d   n1 sw   Y  t rt||||	|t S tdi t }
t|j}t|j}t|	j}t|}t| trt| jdg dd n	t| dttfd t|trt|jd	g dd n	t|d	ttfd t|tr)t|jddgd t|tr:t|jd
g dd n	t|d
ttfd t|dg dd |dks[|dks[|dkr`|dv st|dkso|dkso|dkr~|dkr~td|||||
j|d}|
jd||||	dd|id|gid t|tr|j|f |S )a   
    Return fixed number of logarithmical-evenly spaced values within the interval \
    :math:`[base^{start}, base^{stop}]`.

    Notes:
        This API does not compute the gradient.

    Args:
        start(int|float|Tensor): The input :attr:`start` is exponent of first entry in \
            the sequence. It is a scalar, or a 0-D Tensor of shape [] with input data \
            type int32, int64, float32 or float64.
        stop(int|float|Tensor): The input :attr:`stop` is exponent of last entry in the \
            sequence. It is a scalar, or a 0-D Tensor of shape [] with input data \
            type int32, int64, float32 or float64.
        num(int|Tensor): The input :attr:`num` is given number of items in the sequence. \
            It is an int scalar, or a 0-D Tensor of shape [] with data type int32.
        base(int|float|Tensor): The input :attr:`base` is base of the logarithm function. \
            It is a scalar, or a 0-D Tensor of shape [] with input data type int32, int64, \
            float32 or float64.
        dtype(np.dtype|str, optional): The data type of output tensor, it could be \
            int32, int64, float32 or float64. Default: if None, the data type is float32. \
        name(str, optional): For details, please refer to :ref:`api_guide_Name`. Generally, no setting is required. Default: None.

    Returns:
        Tensor: The output data type will be float32, float64. The 1-D tensor with \
        fixed number of logarithmical-evenly spaced values, the data shape of this \
        tensor is :math:`[num]`. If the :attr:`num` is set 1, the output tensor \
        just has the value with exponential of :attr:`start` with base :attr:`base`.

    Examples:
        .. code-block:: python

            >>> import paddle
            >>> data = paddle.logspace(0, 10, 5, 2, 'float32')
            >>> print(data.numpy())
            [1.0000000e+00 5.6568542e+00 3.2000000e+01 1.8101933e+02 1.0240000e+03]
            >>> data = paddle.logspace(0, 10, 1, 2, 'float32')
            >>> print(data.numpy())
            [1.]
    NrM   logspacerO   rP   r/   rR   )r+   r,   r/   r0   rT   baser    )r/   r0   r+   r,   r,   rU   r0   zThe dtype of start/stop/base is {}/{}/{} but the attr(dtype) of logspace is {}, which may cause data type overflows. Please reset attr(dtype) of logspace.r   )rV   rW   rX   ZBaserY   rZ   )rq   )r@   r^   r_   r
   r`   ra   r   r>   r   r   r   DataTyper   r   rb   r   r   rq   r   r   r?   r   r    r   rB   rc   rd   re   rf   rg   rh   )rR   rT   rM   rr   r    r5   ri   rj   rk   Ztensor_baserD   rl   rm   Z
base_dtypern   ro   r!   r!   r"   rq     s   )



	











rq   Tc                 C   s  dd }dd }t | tjrt| } t | tjst| r)t | ts)t| } nt | ttfr@t| } | j	tj
kr?tdnjt | tjrYt sY| |d} || |} || _| S t | tjjrst rs| |d} || |} || _| S t | tjtjfrt rtj| } nt| } | j|s| |d} || |} || _| S tdt| |s| j	dv rt }t| r|d	v rd
nd}|| |} | j	dv r| d} |r|| |} t | tjrtjj| |ddd |dS tj| |dd|dS )Nc                 S   s(   |rt |t | jkr| t |S | S r   )r   r    astype)Ztensorr    r!   r!   r"   _handle_tensor_dtype)  s   z3_to_tensor_non_static.<locals>._handle_tensor_dtypec                 S   sB   |rt |t | jkrt |dv rt| dS | t |S | S )N)r2   r+   )r   r    r	   rt   )r=   r    r!   r!   r"   _handle_np_dtype/  s   z/_to_tensor_non_static.<locals>._handle_np_dtypez
	Faild to convert input data to a regular ndarray :
	 - Usually this means the input data contains nested lists with different lengths. FzrCan't constructs a 'paddle.Tensor' with data type {}, data type must be scalar|list|tuple|np.ndarray|paddle.Tensor)r*   r+   r,   	complex64
complex128)r*   r+   rw   rx   r/   r0   )r7   placer4   	zero_copyr5   r6   )r7   rz   r4   r{   r6   )r_   r<   numberarrayr=   isscalarstrr:   r;   r    Zobject_rc   r@   Tensorr   Z_copy_tor6   r   eagerZ	LoDTensorrz   Z_equals	TypeErrorrd   rI   r^   Ziscomplexobjrt   )datar    rz   r6   ru   rv   Zdefault_typer!   r!   r"   _to_tensor_non_static(  s   











	r   c                 C   s  t | ttjjfr| }|d ur|| jkrt||}nt | tjr&t	| } t | tj
st| r<t | ts<t	| } nEt | ttfrwz	 t	| } | jdkrStdW n,   d gt|  }t| D ]\}}t|||||< qct|} Y n
tdt|  d| jdv r| t } n
| jdv r| d} |r|}nt| dr| jdkr| j}nt }t|}| jd	kr| d
} t| }t|j|krt||}||_|S )NobjectzNumpy get dtype `object`.zDo not support transform type `z` to tensor)r*   r+   r,   ry   r0   r    r.   r/   )r_   r
   r@   r`   ra   r    castr<   r|   r}   r=   r~   r   r:   r;   RuntimeErrorlen	enumerate_to_tensor_staticstackrI   rt   r^   hasattrr   assignr6   )r   r    r6   outputto_stack_listidxdZtarget_dtyper!   r!   r"   r     sX   








r   c                 C   s   t |}|du rt }t rt| |||S tdtj}t|t|d }t	j
| t| ||W  d   S 1 s=w   Y  dS )u:  
    Constructs a ``paddle.Tensor`` from ``data`` ,
    which can be scalar, tuple, list, numpy\.ndarray, paddle\.Tensor.

    If the ``data`` is already a Tensor, copy will be performed and return a new tensor.
    If you only want to change stop_gradient property, please call ``Tensor.stop_gradient = stop_gradient`` directly.

    .. code-block:: text

        We use the dtype conversion rules following this:
                Keep dtype
        np.number ───────────► paddle.Tensor
                                (0-D Tensor)
                    default_dtype
        Python Number ───────────────► paddle.Tensor
                                        (0-D Tensor)
                    Keep dtype
        np.ndarray ───────────► paddle.Tensor

    Args:
        data(scalar|tuple|list|ndarray|Tensor): Initial data for the tensor.
            Can be a scalar, list, tuple, numpy\.ndarray, paddle\.Tensor.
        dtype(str|np.dtype, optional): The desired data type of returned tensor. Can be 'bool' , 'float16' ,
            'float32' , 'float64' , 'int8' , 'int16' , 'int32' , 'int64' , 'uint8',
            'complex64' , 'complex128'. Default: None, infers dtype from ``data``
            except for python float number which gets dtype from ``get_default_type`` .
        place(CPUPlace|CUDAPinnedPlace|CUDAPlace|str, optional): The place to allocate Tensor. Can be
            CPUPlace, CUDAPinnedPlace, CUDAPlace. Default: None, means global place. If ``place`` is
            string, It can be ``cpu``, ``gpu:x`` and ``gpu_pinned``, where ``x`` is the index of the GPUs.
        stop_gradient(bool, optional): Whether to block the gradient propagation of Autograd. Default: True.

    Returns:
        Tensor: A Tensor constructed from ``data`` .

    Examples:
        .. code-block:: python

            >>> import paddle

            >>> type(paddle.to_tensor(1))
            <class 'paddle.Tensor'>

            >>> paddle.to_tensor(1)
            Tensor(shape=[], dtype=int64, place=Place(cpu), stop_gradient=True,
            1)

            >>> x = paddle.to_tensor(1, stop_gradient=False)
            >>> print(x)
            Tensor(shape=[], dtype=int64, place=Place(cpu), stop_gradient=False,
            1)

            >>> paddle.to_tensor(x)  # A new tensor will be created with default stop_gradient=True
            Tensor(shape=[], dtype=int64, place=Place(cpu), stop_gradient=True,
            1)

            >>> paddle.to_tensor([[0.1, 0.2], [0.3, 0.4]], place=paddle.CPUPlace(), stop_gradient=False)
            Tensor(shape=[2, 2], dtype=float32, place=Place(cpu), stop_gradient=False,
            [[0.10000000, 0.20000000],
             [0.30000001, 0.40000001]])

            >>> type(paddle.to_tensor([[1+1j, 2], [3+2j, 4]], dtype='complex64'))
            <class 'paddle.Tensor'>

            >>> paddle.to_tensor([[1+1j, 2], [3+2j, 4]], dtype='complex64')
            Tensor(shape=[2, 2], dtype=complex64, place=Place(cpu), stop_gradient=True,
            [[(1+1j), (2+0j)],
             [(3+2j), (4+0j)]])
    Nz[(](.+?)[)]r   )r   r   r   r   recompileSfindallr   r@   Zstaticr   r   )r   r    rz   r6   Zre_expZ	place_strr!   r!   r"   	to_tensor  s   E
$r   c                 C   s   |du r| j }nt|tjjtjfst|}t r"t	| ||| j
S t r/t	| ||t S tdi t }t| dg dd t|dg dd |j|d}|jdd	| gi||d
d|gid d|_|S )a   

    This function creates a tensor filled with ``fill_value`` which has identical shape of ``x`` and ``dtype``.
    If the ``dtype`` is None, the data type of Tensor is same with ``x``.

    Args:
        x(Tensor): The input tensor which specifies shape and data type. The data type can be bool, float16, float32, float64, int32, int64.
        fill_value(bool|float|int): The value to fill the tensor with. Note: this value shouldn't exceed the range of the output data type.
        dtype(np.dtype|str, optional): The data type of output. The data type can be one
            of bool, float16, float32, float64, int32, int64. The default value is None, which means the output
            data type is the same as input.
        name(str, optional): For details, please refer to :ref:`api_guide_Name`. Generally, no setting is required. Default: None.

    Returns:
        Tensor: Tensor which is created according to ``x``, ``fill_value`` and ``dtype``.

    Examples:
        .. code-block:: python

            >>> import paddle

            >>> input = paddle.full(shape=[2, 3], fill_value=0.0, dtype='float32', name='input')
            >>> output = paddle.full_like(input, 2.0)
            >>> print(output.numpy())
            [[2. 2. 2.]
             [2. 2. 2.]]
    N	full_likex)r)   r*   r+   r,   r.   r/   r0   r2   r    zfull_like/zeros_like/ones_liker   Zfill_any_likeX)r7   r    rY   rZ   Tr   )r    r_   r   r   r   rs   r   r   r   r   rz   r   Placer   r?   r   r   re   rf   r6   )r   
fill_valuer    r5   rD   ro   r!   r!   r"   r   $  s<   

r   c           
      C   s^  t  rt }|rt }t|tjjtjfst|}t	 r+t|tjjr+t
jjj| }t r@t|}t| ttfr?t
j| } n!t| ttfrUt
j| rTt
j| |} nt| t
jjr]ntd |d u rrt| |||}d|_|S |d urt|| ||| d|_|S d S d|i}t|}t|ts|dv rtt||d< t||d< ntt||d< t||d< tdi t  }i }	t|trt|j!|krt
"||}||	d< t
j#|  t$|d	g d
d t%| dtttfd |d urt&|dt|gd tdi t  }t
jj'|	|| dd |d u r|j(|d}|j!|d	< |j)d|	d|gi|dd d|_|S )Nz0Shape only supports OpReslut, or list, or tuple.Tr8   )r-   r1   r.   r/   r0   Z	str_valuer7   rb   ZValueTensorr    )r)   r*   r+   r,   r-   r1   r.   r/   r0   rw   rx   r2   r&   ro   r[   r\   r&   op_typer   rY   rI   r[   r]   r\   r6   )rb   )*r   r   r   ZCPUPlacer_   r   r   rs   r   r   r@   r`   Zvartype_to_datatyper   rB   r:   r;   utilsconvert_shape_to_listZ_contain_varZget_int_tensor_listra   r   r   fullr6   Zfull_r   r
   r   r>   r   r?   r    r   Zcheck_shaper   r   r   get_shape_tensor_inputsre   rf   )
r&   r    r7   r8   ro   r5   rz   r\   rD   r[   r!   r!   r"   rb   w  s   



rb   c                 C       |du rt  }td| ||dS )a^  
    Create a Tensor of specified :attr:`shape` and :attr:`dtype` and fill it with 1.

    Args:
        shape (tuple|list|Tensor): Shape of the Tensor to be created. The data type is ``int32`` or ``int64`` .
            If ``shape`` is a list or tuple, the elements of it should be integers or 0-D Tensor with shape [].
            If ``shape`` is an Tensor, it should be an 1-D Tensor which represents a list.
        dtype (np.dtype|str, optional): Data type of output Tensor, it should be one of
            bool, float16, float32, float64, int32 and int64. If it is set to None, the data type will be float32.
        name (str, optional): For details, please refer to :ref:`api_guide_Name`. Generally, no setting is required. Default: None.

    Returns:
        Tensor: A Tensor of data type :attr:`dtype` with shape :attr:`shape` and all elements are 1.

    Examples:
        .. code-block:: python

            >>> import paddle

            >>> # shape is a list/tuple
            >>> data1 = paddle.ones(shape=[3, 2])
            >>> print(data1.numpy())
            [[1. 1.]
             [1. 1.]
             [1. 1.]]

            >>> # shape is a Tensor
            >>> shape = paddle.to_tensor([3, 2])
            >>> data2 = paddle.ones(shape=shape)
            >>> print(data2.numpy())
            [[1. 1.]
             [1. 1.]
             [1. 1.]]

            >>> # shape is a Tensor List
            >>> shape = [paddle.to_tensor(3), paddle.to_tensor(2)]
            >>> data3 = paddle.ones(shape=shape)
            >>> print(data3.numpy())
            [[1. 1.]
             [1. 1.]
             [1. 1.]]
    Ng      ?r7   r&   r    r5   r@   r^   rb   r&   r    r5   r!   r!   r"   ones  s   +r   c                 C      t | d||dS )a  
    Returns a Tensor filled with the value 1, with the same shape and
    data type (use ``dtype`` if ``dtype`` is not None) as ``x``.

    Args:
        x(Tensor): The input tensor which specifies shape and dtype. The
            dtype of ``x`` can be bool, float16, float32, float64, int32, int64.
        dtype(str|np.dtype, optional): The data type of the
            output tensor. Supported data types: bool, float16, float32, float64,
            int32, int64. If ``dtype`` is None, the data type is the same as ``x``.
            Default is None.
        name(str, optional): For details, please refer to :ref:`api_guide_Name`. Generally, no setting is required. Default: None.

    Returns:
        Tensor: A Tensor filled with the value 1, with the same shape and
        data type (use ``dtype`` if ``dtype`` is not None) as ``x``.

    Examples:
        .. code-block:: python

            >>> import paddle

            >>> x = paddle.to_tensor([1,2,3])
            >>> out1 = paddle.ones_like(x)
            >>> print(out1.numpy())
            [1 1 1]
            >>> out2 = paddle.ones_like(x, dtype='int32')
            >>> print(out2.numpy())
            [1 1 1]

    rP   r   r   r    r5   r   r   r    r5   r!   r!   r"   	ones_like  s    r   c                 C   r   )a  
    Creates a tensor of specified :attr:`shape` and :attr:`dtype`, and fills it with 0.

    Args:
        shape (tuple|list|Tensor): Shape of the Tensor to be created. The data type is ``int32`` or ``int64`` .
            If ``shape`` is a list or tuple, each element of it should be integer or 0-D Tensor with shape [].
            If ``shape`` is an Tensor, it should be an 1-D Tensor which represents a list.
        dtype(np.dtype|str, optional): Data type of output Tensor, it supports
            bool, float16, float32, float64, int32 and int64. Default: if None, the data type is float32.
        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 of data type :attr:`dtype` with shape :attr:`shape` and all elements set to 0.

    Examples:
        .. code-block:: python

            >>> import paddle

            >>> # shape is a list/tuple
            >>> data1 = paddle.zeros(shape=[3, 2])
            >>> print(data1.numpy())
            [[0. 0.]
             [0. 0.]
             [0. 0.]]

            >>> # shape is a Tensor
            >>> shape = paddle.to_tensor([3, 2])
            >>> data2 = paddle.zeros(shape=shape)
            >>> print(data2.numpy())
            [[0. 0.]
             [0. 0.]
             [0. 0.]]

            >>> # shape is a Tensor List
            >>> shape = [paddle.to_tensor(3), paddle.to_tensor(2)]
            >>> data3 = paddle.zeros(shape=shape)
            >>> print(data3.numpy())
            [[0. 0.]
             [0. 0.]
             [0. 0.]]
    Ng        r   r   r   r!   r!   r"   zeros.  s   ,r   c                 C   r   )a  
    Returns a Tensor filled with the value 0, with the same shape and
    data type (use ``dtype`` if ``dtype`` is not None) as ``x``.

    Args:
        x(Tensor): The input tensor which specifies shape and dtype. The
            dtype of ``x`` can be bool, float16, float32, float64, int32, int64.
        dtype(str|np.dtype, optional): The data type of the
            output tensor. Supported data types: bool, float16, float32, float64,
            int32, int64. If ``dtype`` is None, the data type is the same as ``x``.
            Default is None.
        name (str, optional): For details, please refer to :ref:`api_guide_Name`. Generally, no setting is required. Default: None.

    Returns:
        Tensor: A Tensor filled with the value 0, with the same shape and
        data type (use ``dtype`` if ``dtype`` is not None) as ``x``.


    Examples:
        .. code-block:: python

            >>> import paddle

            >>> x = paddle.to_tensor([1, 2, 3])
            >>> out1 = paddle.zeros_like(x)
            >>> print(out1.numpy())
            [0 0 0]
            >>> out2 = paddle.zeros_like(x, dtype='int32')
            >>> print(out2.numpy())
            [0 0 0]

    r   r   r   r   r!   r!   r"   
zeros_like_  s   !r   c                 C   s   dd }|| d |du rt  }t|tjjst|}|dur&||d n| }t r5t	| ||t
 }n(tdi t }t|dg dd |j|d	}|jdi d
|gi| ||ddd d|_|S )a6  

    This function constructs 2-D Tensor with ones on the diagonal and zeros elsewhere.

    Args:
        num_rows(int): the number of rows in each batch Tensor.
        num_columns(int, optional): the number of columns in each batch Tensor.
            If None, default: num_rows.
        dtype(np.dtype|str, optional): The data type of the returned Tensor.
            It should be int32, int64, float16, float32, float64. Default: if None, the data type
            is float32.
        name(str, optional): For details, please refer to :ref:`api_guide_Name`. Generally, no setting is required. Default: None.

    Returns:
        Tensor: An identity Tensor or LoDTensor of shape [num_rows, num_columns].

    Examples:
        .. code-block:: python

            >>> import paddle

            >>> data = paddle.eye(3, dtype='int32')
            >>> print(data.numpy())
            [[1 0 0]
             [0 1 0]
             [0 0 1]]
            >>> data = paddle.eye(2, 3, dtype='int32')
            >>> print(data.numpy())
            [[1 0 0]
             [0 1 0]]
    c                 S   s`   t | ttjjtjjfrt| j	dkr| j	d dv sJ d S t | t
r'| dk r.t| dd S )NrP   r   )rP   z should be a non-negative int.)r_   r
   r   r   r   r@   r`   ra   r   r&   r>   r   )rG   messager!   r!   r"   _check_attr  s   $zeye.<locals>._check_attrnum_rowsNnum_columnseyer    r*   r+   r,   r/   r0   r   rY   )r   r   r    Tr   )r   )r@   r^   r_   r   r   r   r   r   r   r   r   r   r?   r   re   rf   r6   )r   r   r    r5   r   ro   rD   r!   r!   r"   r     sB   !

r   c                 C   s    |du rt  }t| |||dS )a\  

    Return a Tensor with the ``fill_value`` which size is same as ``shape``.

    Args:
        shape (tuple|list|Tensor): Shape of the Tensor to be created. The data type is ``int32`` or ``int64`` .
            If ``shape`` is a list or tuple, each element of it should be integer or 0-D Tensor with shape [].
            If ``shape`` is an Tensor, it should be an 1-D Tensor which represents a list.
        fill_value(bool|float|int|Tensor): The constant value used to initialize the Tensor to be created.
            If ``fill_value`` is an Tensor, it shoule be an 0-D Tensor which represents a scalar.
        dtype(np.dtype|str, optional): Data type of the output Tensor
            which can be float16, float32, float64, int32, int64, if dytpe is `None`, the data
            type of created Tensor is `float32`.
        name (str, optional): For details, please refer to :ref:`api_guide_Name`. Generally, no setting is required. Default: None.

    Returns:
        Tensor: Tensor which is created according to ``shape``, ``fill_value`` and ``dtype``.

    Examples:
        .. code-block:: python

            >>> import paddle

            >>> # shape is a list/tuple
            >>> data1 = paddle.full(shape=[3, 2], fill_value=1.)
            >>> print(data1.numpy())
            [[1. 1.]
             [1. 1.]
             [1. 1.]]

            >>> # shape is a Tensor
            >>> shape = paddle.to_tensor([3, 2])
            >>> data2 = paddle.full(shape=shape, fill_value=2.)
            >>> print(data2.numpy())
            [[2. 2.]
             [2. 2.]
             [2. 2.]]

            >>> # shape is a Tensor List
            >>> shape = [paddle.to_tensor(3), paddle.to_tensor(2)]
            >>> data3 = paddle.full(shape=shape, fill_value=3.)
            >>> print(data3.numpy())
            [[3. 3.]
             [3. 3.]
             [3. 3.]]

            >>> # fill_value is a Tensor.
            >>> val = paddle.full([], 2.0, "float32")
            >>> data5 = paddle.full(shape=[3, 2], fill_value=val)
            >>> print(data5.numpy())
            [[2. 2.]
             [2. 2.]
             [2. 2.]]
    N)r&   r    r7   r5   r   )r&   r   r    r5   r!   r!   r"   r     s   8r   rP   c           
      C   s  |du r| }d} |du r>| ||fD ],}t |ttjjfr*t|s't } nd}qt |tjs;t |t	s;t } nd}qd}t | ttjjf o]t |ttjjf o]t |ttjjf }t
 so|rot	t||  | g}t |tjjtjfs}t|}|rt rt| |||t S t | ttjjfstd tdg|| dd} W d   n1 sw   Y  n| j|krt| |} t |ttjjfstd tdg||dd}W d   n1 sw   Y  n|j|krt||}t |ttjjfstd tdg||dd}W d   n	1 sw   Y  n|j|kr%t||}t r3t| |||t S t|dg d	d
 tdi t }|j||d}	|jd| ||dd|	id d|	_ |durg|	j!"| |	S )a)
  
    Returns a 1-D Tensor with spaced values within a given interval.

    Values are generated into the half-open interval [``start``, ``end``) with
    the ``step``. (the interval including ``start`` but excluding ``end``).

    If ``dtype`` is float32 or float64, we advise adding a small epsilon to
    ``end`` to avoid floating point rounding errors when comparing against ``end``.

    Parameters:
        start(float|int|Tensor): Start of interval. The interval includes this
            value. If ``end`` is None, the half-open interval is [0, ``start``).
            If ``start`` is a Tensor, it is a 0-D Tensor which represents a scalar
            and data type is int32, int64, float32, float64. Default is 0.
        end(float|int|Tensor, optional): End of interval. The interval does not
            include this value. If ``end`` is a Tensor, it is a 0-D Tensor which
            represents a scalar and data type is int32, int64, float32, float64.
            If ``end`` is None, the half-open interval is [0, ``start``).
            Default is None.
        step(float|int|Tensor, optional): Spacing between values. For any out,
            it is the istance between two adjacent values, out[i+1] - out[i].
            If ``step`` is a Tensor, it is a 0-D Tensor which represents a scalar
            and data type is int32, int64, float32, float64. . Default is 1.
        dtype(str|np.dtype, optional): The data type of the
            output tensor. Supported data types: int32, int64, float32, float64.
            If ``dytpe`` is None, the data type is float32. Default is None.
        name (str, optional): For details, please refer to :ref:`api_guide_Name`. Generally, no setting is required. Default: None.

    Returns:
        Tensor: A 1-D Tensor with values from the interval [``start``, ``end``)
        taken with common difference ``step`` beginning from ``start``. Its
        data type is set by ``dtype``.

    Examples:
        .. code-block:: python

            >>> import paddle

            >>> out1 = paddle.arange(5)
            >>> print(out1.numpy())
            [0 1 2 3 4]

            >>> out2 = paddle.arange(3, 9, 2.0)
            >>> print(out2.numpy())
            [3. 5. 7.]

            >>> # use 4.999 instead of 5.0 to avoid floating point rounding errors
            >>> out3 = paddle.arange(4.999, dtype='float32')
            >>> print(out3.numpy())
            [0. 1. 2. 3. 4.]

            >>> start_var = paddle.to_tensor(3)
            >>> out4 = paddle.arange(start_var, 7)
            >>> print(out4.numpy())
            [3 4 5 6]

    Nr   r0   rO   rP   TrQ   r    )r+   r,   r/   r0   r*   r2   zrange/arangerange)r&   )rV   ZEndZSteprY   rI   r[   r]   )r   )#r_   r
   r@   r`   ra   
is_integerr^   r<   integerr>   r   mathceilr   r   r   rs   r   r   r   aranger   r   rb   r    r   r   r   r   r?   re   rf   r6   rg   rh   )
rR   endstepr    r5   valZ	out_shapeZis_value_inputrD   ro   r!   r!   r"   r     s   :









r   c                 C   s   | j }| jdd}|dusJ d| t|dg d| t|jdk r-td| d| jdd	}t|tfsBt	d
| d| jdd}|du rU| j
|jd}n	| j||jdd}| jdd|i||dkrkdnddd|id |S )zBase op of tril_op and triu_opr   Nzx cannot be None in )	r*   r2   r+   r,   r/   r0   r)   rw   rx   r   zx shape in z must be at least 2-Ddiagonalr   zdiagonal in z must be a python Intr5   r   FrK   Z	tril_triur   trilT)r   lowerrY   rZ   )Z
layer_typekwargsgetr   r   r&   rc   r_   r>   r   re   r    rL   rf   )rD   r   r   r   r5   ro   r!   r!   r"   _tril_triu_op  s:   
r   c                 C   &   t  r	t| |S ttdi t S )a	  
    Returns the lower triangular part of a matrix (2-D tensor) or batch
    of matrices :attr:`x`, the other elements of the result tensor are set
    to 0. The lower triangular part of the matrix is defined as the elements
    on and below the diagonal.

    Args:
        x (Tensor): The input x which is a Tensor.
            Support data types: ``bool``, ``float64``, ``float32``, ``int32``, ``int64``, ``complex64``, ``complex128``.
        diagonal (int, optional): The diagonal to consider, default value is 0.
            If :attr:`diagonal` = 0, all elements on and below the main diagonal are
            retained. A positive value includes just as many diagonals above the main
            diagonal, and similarly a negative value excludes just as many diagonals below
            the main diagonal. The main diagonal are the set of indices
            :math:`\{(i, i)\}` for :math:`i \in [0, \min\{d_{1}, d_{2}\} - 1]` where
            :math:`d_{1}, d_{2}` are the dimensions of the matrix.
        name (str, optional): For details, please refer to :ref:`api_guide_Name`. Generally, no setting is required. Default: None.

    Returns:
        Tensor: Results of lower triangular operation by the specified diagonal of input tensor x,
        it's data type is the same as x's Tensor.

    Examples:
        .. code-block:: python

            >>> import paddle

            >>> data = paddle.arange(1, 13, dtype="int64").reshape([3,-1])
            >>> print(data)
            Tensor(shape=[3, 4], dtype=int64, place=Place(cpu), stop_gradient=True,
            [[1 , 2 , 3 , 4 ],
             [5 , 6 , 7 , 8 ],
             [9 , 10, 11, 12]])

            >>> tril1 = paddle.tril(data)
            >>> print(tril1)
            Tensor(shape=[3, 4], dtype=int64, place=Place(cpu), stop_gradient=True,
            [[1 , 0 , 0 , 0 ],
             [5 , 6 , 0 , 0 ],
             [9 , 10, 11, 0 ]])

            >>> # example 2, positive diagonal value
            >>> tril2 = paddle.tril(data, diagonal=2)
            >>> print(tril2)
            Tensor(shape=[3, 4], dtype=int64, place=Place(cpu), stop_gradient=True,
            [[1 , 2 , 3 , 0 ],
             [5 , 6 , 7 , 8 ],
             [9 , 10, 11, 12]])

            >>> # example 3, negative diagonal value
            >>> tril3 = paddle.tril(data, diagonal=-1)
            >>> print(tril3)
            Tensor(shape=[3, 4], dtype=int64, place=Place(cpu), stop_gradient=True,
            [[0 , 0 , 0 , 0 ],
             [5 , 0 , 0 , 0 ],
             [9 , 10, 0 , 0 ]])
    r   N)r   )r   r   r   r   r   r?   r   r   r5   r!   r!   r"   r     s   :r   c                 C      t  r	t| |S dS )z
    Inplace version of ``tril`` API, the output Tensor will be inplaced with input ``x``.
    Please refer to :ref:`api_paddle_tril`.
    N)r   r   tril_r   r!   r!   r"   r        r   c                 C   r   )a
  
    Return the upper triangular part of a matrix (2-D tensor) or batch of matrices
    :attr:`x`, the other elements of the result tensor are set to 0.
    The upper triangular part of the matrix is defined as the elements on and
    above the diagonal.

    Args:
        x (Tensor): The input x which is a Tensor.
            Support data types: ``float64``, ``float32``, ``int32``, ``int64``, ``complex64``, ``complex128``.
        diagonal (int, optional): The diagonal to consider, default value is 0.
            If :attr:`diagonal` = 0, all elements on and above the main diagonal are
            retained. A positive value excludes just as many diagonals above the main
            diagonal, and similarly a negative value includes just as many diagonals below
            the main diagonal. The main diagonal are the set of indices
            :math:`\{(i, i)\}` for :math:`i \in [0, \min\{d_{1}, d_{2}\} - 1]` where
            :math:`d_{1}, d_{2}` are the dimensions of the matrix.
        name (str, optional): For details, please refer to :ref:`api_guide_Name`. Generally, no setting is required. Default: None.

    Returns:
        Tensor: Results of upper triangular operation by the specified diagonal of input tensor x,
        it's data type is the same as x's Tensor.

    Examples:
        .. code-block:: python

            >>> import paddle

            >>> x = paddle.arange(1, 13, dtype="int64").reshape([3,-1])
            >>> print(x)
            Tensor(shape=[3, 4], dtype=int64, place=Place(cpu), stop_gradient=True,
            [[1 , 2 , 3 , 4 ],
             [5 , 6 , 7 , 8 ],
             [9 , 10, 11, 12]])

            >>> # example 1, default diagonal
            >>> triu1 = paddle.tensor.triu(x)
            >>> print(triu1)
            Tensor(shape=[3, 4], dtype=int64, place=Place(cpu), stop_gradient=True,
            [[1 , 2 , 3 , 4 ],
             [0 , 6 , 7 , 8 ],
             [0 , 0 , 11, 12]])

            >>> # example 2, positive diagonal value
            >>> triu2 = paddle.tensor.triu(x, diagonal=2)
            >>> print(triu2)
            Tensor(shape=[3, 4], dtype=int64, place=Place(cpu), stop_gradient=True,
            [[0, 0, 3, 4],
             [0, 0, 0, 8],
             [0, 0, 0, 0]])

            >>> # example 3, negative diagonal value
            >>> triu3 = paddle.tensor.triu(x, diagonal=-1)
            >>> print(triu3)
            Tensor(shape=[3, 4], dtype=int64, place=Place(cpu), stop_gradient=True,
            [[1 , 2 , 3 , 4 ],
             [5 , 6 , 7 , 8 ],
             [0 , 10, 11, 12]])

    triuN)r   )r   r   r   r   r   r?   r   r!   r!   r"   r     s   <r   c                 C   r   )z
    Inplace version of ``triu`` API, the output Tensor will be inplaced with input ``x``.
    Please refer to :ref:`api_paddle_triu`.
    N)r   r   triu_r   r!   r!   r"   r   U  r   r   c                     s   t  dkrt d ttfr d  t rtt S |dd}tdi t	 t ttfs6t
dt D ]\}}t|jdg dd q:t  } fd	d
t|D }jddt id|id |S )a5  

    Takes a list of N tensors as input :attr:`*args`, each of which is 1-dimensional vector, and creates N-dimensional grids.

    Args:
        *args(Tensor|list of Tensor) : tensors (tuple(list) of tensor): the shapes of input k tensors are (N1,),
            (N2,),..., (Nk,). Support data types: ``float64``, ``float16``, ``float32``, ``int32``, ``int64``.
        **kwargs (optional): Currently, only accept name in **kwargs
            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: k tensors. The shape of each tensor is (N1, N2, ..., Nk)

    Examples:
        .. code-block:: python

            >>> import paddle

            >>> x = paddle.randint(low=0, high=100, shape=[100])
            >>> y = paddle.randint(low=0, high=100, shape=[200])

            >>> grid_x, grid_y = paddle.meshgrid(x, y)

            >>> print(grid_x.shape)
            [100, 200]
            >>> print(grid_y.shape)
            [100, 200]

    rP   r   r5   Nmeshgridz2The type of input args in meshgrid should be list.zcreate data type)r2   r*   r+   r,   r/   r0   c                    s   g | ]}j  | jd qS )r   )re   r    ).0iargsrD   r!   r"   
<listcomp>  s    zmeshgrid.<locals>.<listcomp>r   rY   r   )r   )r   r_   r:   r;   r   r   r   r   r   r?   r   r   r   r    r   rf   )r   r   r5   idZinput_rM   ro   r!   r   r"   r   `  s2    r   r   c           	      C   s   t | ts	t| } t rt| |||S d| gi}|||d}dd }|| ||| tdi t }|j| j	d}|j
dd| gi|||dd|gid d	|_|S )aH
  
    Creates a tensor whose diagonals of certain 2D planes (specified by dim1 and dim2)
    are filled by ``input``. By default, a 2D plane formed by the last two dimensions
    of the returned tensor will be selected.

    The argument ``offset`` determines which diagonal is generated:

    - If offset = 0, it is the main diagonal.
    - If offset > 0, it is above the main diagonal.
    - If offset < 0, it is below the main diagonal.

    Args:
        input(Tensor|numpy.ndarray): The input tensor. Must be at least 1-dimensional. The input data type should be float32, float64, int32, int64.
        offset(int, optional): Which diagonal to consider. Default: 0 (main diagonal).
        dim1(int, optional): The first dimension with respect to which to take diagonal. Default: -2.
        dim2(int, optional): The second dimension with respect to which to take diagonal. Default: -1.

    Returns:
        Tensor, the output data type is the same as input data type.

    Examples:
        .. code-block:: python

            >>> import paddle

            >>> diag_embed_input = paddle.arange(6)

            >>> diag_embed_output1 = paddle.diag_embed(diag_embed_input)
            >>> print(diag_embed_output1)
            Tensor(shape=[6, 6], dtype=int64, place=Place(cpu), stop_gradient=True,
            [[0, 0, 0, 0, 0, 0],
             [0, 1, 0, 0, 0, 0],
             [0, 0, 2, 0, 0, 0],
             [0, 0, 0, 3, 0, 0],
             [0, 0, 0, 0, 4, 0],
             [0, 0, 0, 0, 0, 5]])

            >>> diag_embed_output2 = paddle.diag_embed(diag_embed_input, offset=-1, dim1=0,dim2=1 )
            >>> print(diag_embed_output2)
            Tensor(shape=[7, 7], dtype=int64, place=Place(cpu), stop_gradient=True,
            [[0, 0, 0, 0, 0, 0, 0],
             [0, 0, 0, 0, 0, 0, 0],
             [0, 1, 0, 0, 0, 0, 0],
             [0, 0, 2, 0, 0, 0, 0],
             [0, 0, 0, 3, 0, 0, 0],
             [0, 0, 0, 0, 4, 0, 0],
             [0, 0, 0, 0, 0, 5, 0]])

            >>> diag_embed_input_2dim = paddle.reshape(diag_embed_input,[2,3])
            >>> print(diag_embed_input_2dim)
            Tensor(shape=[2, 3], dtype=int64, place=Place(cpu), stop_gradient=True,
            [[0, 1, 2],
            [3, 4, 5]])
            >>> diag_embed_output3 = paddle.diag_embed(diag_embed_input_2dim,offset= 0, dim1=0, dim2=2 )
            >>> print(diag_embed_output3)
            Tensor(shape=[3, 2, 3], dtype=int64, place=Place(cpu), stop_gradient=True,
            [[[0, 0, 0],
              [3, 0, 0]],
             [[0, 1, 0],
              [0, 4, 0]],
             [[0, 0, 2],
              [0, 0, 5]]])
    Input)offsetdim1dim2c                 S   s   t | jdg dd t| j}t|dksJ dt| t|t|ks6J dt|d  t||f t|t|ksOJ dt|d  t||f |dkrU|nt|| d }|dkrc|nt|| d }||kswJ d	||f d S )
Nr   )r/   r0   r*   r+   r,   
diag_embedrP   zLInput must be at least 1-dimensional, But received Input's dimensional: %s.
zHDim1 is out of range (expected to be in range of [%d, %d], but got %d).
zHDim2 is out of range (expected to be in range of [%d, %d], but got %d).
r   zMdim1 and dim2 cannot be the same dimension.But received dim1 = %d, dim2 = %d
)r   r    r:   r&   r   r<   abs)inputr   r   r   Zinput_shapeZdim1_Zdim2_r!   r!   r"   __check_input  s:   

z!diag_embed.<locals>.__check_inputr   r   rY   rZ   TN)r   )r_   r
   r   r   r   r   r   r?   re   r    rf   r6   )	r   r   r   r   r[   r\   r   rD   ro   r!   r!   r"   r     s$   
@

r   c           	      C   s,  t  rt| jdkrt| |dS t| dd}t||dS d}t| dtd t| j	dg dd t|dt
d tdi t }|j| j	d}|| j	}|j| j	d}t| jdkrm|jd	d
| id|i||dd n$|jdd
| i||ddddd d|_|jd	d
|id|i||dd d|_|S )a  
    If ``x`` is a vector (1-D tensor), a 2-D square tensor with the elements of ``x`` as the diagonal is returned.

    If ``x`` is a tensor (more than 1-D), a 2-D square tensor with the elements of flattened ``x`` as the diagonal is returned.

    The argument ``offset`` controls the diagonal offset.


    If ``offset`` = 0, it is the main diagonal.

    If ``offset`` > 0, it is superdiagonal.

    If ``offset`` < 0, it is subdiagonal.

    Args:
        x (Tensor): The input tensor. It can be any shape. Its data type should be float16, float32, float64, int32, int64.
        offset (int, optional): The diagonal offset. A positive value represents superdiagonal, 0 represents the main diagonal, and a negative value represents subdiagonal. Default: 0 (main diagonal).
        name (str, optional): For details, please refer to :ref:`api_guide_Name`. Generally, no setting is required. Default: None.

    Returns:
        Tensor, a square matrix. The output data type is the same as input data type.

    Examples:
        .. code-block:: python
            :name: code-example-1

            >>> import paddle

            >>> x = paddle.to_tensor([1, 2, 3])
            >>> y = paddle.diagflat(x)
            >>> print(y)
            Tensor(shape=[3, 3], dtype=int64, place=Place(cpu), stop_gradient=True,
            [[1, 0, 0],
             [0, 2, 0],
             [0, 0, 3]])

            >>> y = paddle.diagflat(x, offset=1)
            >>> print(y)
            Tensor(shape=[4, 4], dtype=int64, place=Place(cpu), stop_gradient=True,
            [[0, 1, 0, 0],
             [0, 0, 2, 0],
             [0, 0, 0, 3],
             [0, 0, 0, 0]])

            >>> y = paddle.diagflat(x, offset=-1)
            >>> print(y)
            Tensor(shape=[4, 4], dtype=int64, place=Place(cpu), stop_gradient=True,
            [[0, 0, 0, 0],
             [1, 0, 0, 0],
             [0, 2, 0, 0],
             [0, 0, 3, 0]])

        .. code-block:: python
            :name: code-example-2

            >>> import paddle

            >>> x = paddle.to_tensor([[1, 2], [3, 4]])
            >>> y = paddle.diagflat(x)
            >>> print(y)
            Tensor(shape=[4, 4], dtype=int64, place=Place(cpu), stop_gradient=True,
            [[1, 0, 0, 0],
             [0, 2, 0, 0],
             [0, 0, 3, 0],
             [0, 0, 0, 4]])

            >>> y = paddle.diagflat(x, offset=1)
            >>> print(y)
            Tensor(shape=[5, 5], dtype=int64, place=Place(cpu), stop_gradient=True,
            [[0, 1, 0, 0, 0],
             [0, 0, 2, 0, 0],
             [0, 0, 0, 3, 0],
             [0, 0, 0, 0, 4],
             [0, 0, 0, 0, 0]])

            >>> y = paddle.diagflat(x, offset=-1)
            >>> print(y)
            Tensor(shape=[5, 5], dtype=int64, place=Place(cpu), stop_gradient=True,
            [[0, 0, 0, 0, 0],
             [1, 0, 0, 0, 0],
             [0, 2, 0, 0, 0],
             [0, 0, 3, 0, 0],
             [0, 0, 0, 4, 0]])

    rP   r   r   r   diagflatr   r   r   diag_v2r   rY   r   padding_valuerI   r[   r]   r\   Zflatten_contiguous_range)rY   ZXShape)Z
start_axisZ	stop_axisTN)r   )r   r   r&   r   diagflattenr   r
   r   r    r>   r   r?   re   rf   r6   )	r   r   r5   yr   rD   Zout1Z
out1_shapeZout2r!   r!   r"   r     sP   Vr   c                 C   s   t  r
t| ||S t| dtd t| jdg dd t|dtd t|dttfd t	| j
dkrCt	| j
dkrCtdt	| j
tdi t }|j| jd	}|jdd
| id|i||dd d|_|S )a
  
    If ``x`` is a vector (1-D tensor), a 2-D square tensor with the elements of ``x`` as the diagonal is returned.

    If ``x`` is a matrix (2-D tensor), a 1-D tensor with the diagonal elements of ``x`` is returned.

    The argument ``offset`` controls the diagonal offset:

    If ``offset`` = 0, it is the main diagonal.

    If ``offset`` > 0, it is superdiagonal.

    If ``offset`` < 0, it is subdiagonal.

    Args:
        x (Tensor): The input tensor. Its shape is either 1-D or 2-D. Its data type should be float16, float32, float64, int32, int64.
        offset (int, optional): The diagonal offset. A positive value represents superdiagonal, 0 represents the main diagonal, and a negative value represents subdiagonal.
        padding_value (int|float, optional): Use this value to fill the area outside the specified diagonal band. Only takes effect when the input is a 1-D Tensor. The default value is 0.
        name (str, optional): For details, please refer to :ref:`api_guide_Name`. Generally, no setting is required. Default: None.

    Returns:
        Tensor, a square matrix or a vector. The output data type is the same as input data type.

    Examples:
        .. code-block:: python
            :name: code-example-1

            >>> import paddle

            >>> paddle.disable_static()
            >>> x = paddle.to_tensor([1, 2, 3])
            >>> y = paddle.diag(x)
            >>> print(y)
            Tensor(shape=[3, 3], dtype=int64, place=Place(cpu), stop_gradient=True,
            [[1, 0, 0],
             [0, 2, 0],
             [0, 0, 3]])

            >>> y = paddle.diag(x, offset=1)
            >>> print(y)
            Tensor(shape=[4, 4], dtype=int64, place=Place(cpu), stop_gradient=True,
            [[0, 1, 0, 0],
             [0, 0, 2, 0],
             [0, 0, 0, 3],
             [0, 0, 0, 0]])

            >>> y = paddle.diag(x, padding_value=6)
            >>> print(y)
            Tensor(shape=[3, 3], dtype=int64, place=Place(cpu), stop_gradient=True,
            [[1, 6, 6],
             [6, 2, 6],
             [6, 6, 3]])

        .. code-block:: python
            :name: code-example-2

            >>> import paddle

            >>> paddle.disable_static()
            >>> x = paddle.to_tensor([[1, 2, 3], [4, 5, 6]])
            >>> y = paddle.diag(x)
            >>> print(y)
            Tensor(shape=[2], dtype=int64, place=Place(cpu), stop_gradient=True,
            [1, 5])

            >>> y = paddle.diag(x, offset=1)
            >>> print(y)
            Tensor(shape=[2], dtype=int64, place=Place(cpu), stop_gradient=True,
            [2, 6])

            >>> y = paddle.diag(x, offset=-1)
            >>> print(y)
            Tensor(shape=[1], dtype=int64, place=Place(cpu), stop_gradient=True,
            [4])
    r   r   rS   r   r   rP   r   z?The dimension of input x must be either 1 or 2, but received {}r   r   rY   r   r   TN)r   )r   r   r   r   r
   r   r    r>   rB   r   r&   rc   rd   r   r?   re   rf   r6   )r   r   r   r5   rD   ro   r!   r!   r"   r     s6   Kr   c                 C   s   |du rt  }t|}t r$t j| } t| t|t	 }d|_
|S tdi t }i }t|dg dd t| dtttfd t| trPt| jdddgd i }t jj||| dd	 |j|d
}t||d< |jd|d|gi|dd d|_
|S )a]  
    Returns a Tensor with uninitialized data which size is same as ``shape``.

    Args:
        shape (tuple|list|Tensor): Shape of the Tensor to be created. The data type is ``int32`` or ``int64`` .
            If ``shape`` is a list or tuple, each element of it should be integer or 0-D Tensor with shape [].
            If ``shape`` is an Tensor, it should be an 1-D Tensor which represents a list.
        dtype(np.dtype|str, optional): Data type of the output Tensor
            which can be bool, float16, float32, float64, int32, int64, complex64, complex128 if dytpe is `None`, the data
            type of created Tensor use global default dtype (see ``get_default_dtype``
            for details).
        name(str, optional): For details, please refer to :ref:`api_guide_Name`. Generally, no setting is required. Default: None.

    Returns:
        Tensor: Tensor which is created according to ``shape`` and ``dtype``, and is uninitialized.

    Examples:
        .. code-block:: python

            >>> import paddle

            >>> # shape is a list/tuple
            >>> data1 = paddle.empty(shape=[3, 2])
            >>> print(data1.numpy())
            >>> # doctest: +SKIP('change everytime')
            [[1. 1.]
             [1. 1.]
             [1. 1.]]

            >>> # shape is a Tensor
            >>> shape = paddle.to_tensor([3, 2])
            >>> data2 = paddle.empty(shape=shape)
            >>> print(data2.numpy())
            >>> # doctest: +SKIP('change everytime')
            [[1. 1.]
             [1. 1.]
             [1. 1.]]

            >>> # shape is a Tensor List
            >>> shape = [paddle.to_tensor(3), paddle.to_tensor(2)]
            >>> data3 = paddle.empty(shape=shape)
            >>> print(data3.numpy())
            >>> # doctest: +SKIP('change everytime')
            [[1. 1.]
             [1. 1.]
             [1. 1.]]
    NTemptyr    )r)   r*   r+   r,   r/   r0   rw   rx   r&   r/   r0   r   r   rY   r   )r   )r@   r^   r   r   r   r   r   r   r   r   r6   r   r?   r   r   r
   r:   r;   r_   r    r   re   rf   )r&   r    r5   ro   rD   r[   r\   r!   r!   r"   r     sH   1

r   c                 C   s   |du r| j }t|}t rt| jt|t }d|_|S t	 r5t
| }t|t|t }d|_|S tdi t }t| dg dd t|dg dd |j|d}i }i }t||d< t
| }t
jj|||dd |jd	|d
|gi|dd d|_|S )a  
    Returns a Tensor with uninitialized data which has identical shape of ``x`` and ``dtype``.
    If the ``dtype`` is None, the data type of Tensor is same with ``x``.

    Args:
        x(Tensor): The input tensor which specifies shape and data type. The data type can be bool, float16, float32, float64, int32, int64.
        dtype(np.dtype|str, optional): The data type of output. The data type can be one
            of bool, float16, float32, float64, int32, int64. The default value is None, which means the output
            data type is the same as input.
        name(str, optional): For details, please refer to :ref:`api_guide_Name`. Generally, no setting is required. Default: None.

    Returns:
        Tensor: Tensor which is created according to ``x`` and ``dtype``, and is uninitialized.

    Examples:
        .. code-block:: python

            >>> import paddle

            >>> paddle.set_device("cpu")  # and use cpu device

            >>> x = paddle.randn([2, 3], 'float32')
            >>> output = paddle.empty_like(x)
            >>> print(output)
            >>> # doctest: +SKIP('change everytime')
            [[1.8491974e+20 1.8037303e+28 1.7443726e+28]
             [4.9640171e+28 3.0186127e+32 5.6715899e-11]]
    NT
empty_liker   )r)   r*   r+   r,   r/   r0   r2   r    r   r   r   rY   r   )r   )r    r   r   r   r   r&   r   r   r6   r   r@   r   r?   r   r   re   r   r   rf   )r   r    r5   ro   r&   rD   r[   r\   r!   r!   r"   r   r  sd   
		
r   c           
      C   s  | |u rt | ttjjfr| S | }td%i t }t|dttjjtj	t
ttttfd t|r<t |ts<t|g}nt |t
tfrHt|}t |ttjjtjjfrt rj|du rbt|}|S t|| |S t r|du rxt|}|S t||}|S t|jdg ddd |du r|j|jd}|jdd|gid|gid	 |S t |tj	rt|jd
krt dd |D rt!dd |D st"ddd }t
t#||}t$|}t%|d}|S |jdkr	 t"dt&|j}|tj'j(j)krt*+d tj'j(j,}|tj-j.krt*+d tj-j/}|tj'j(j0tj-j0fv r*d}dd |j1D }	nM|tj'j(j,tj-j/fv rAd}dd |j1D }	n6|tj'j(j2tj-j2fv rXd}dd |j1D }	n|tj'j(j3tj-j3fv rod}dd |j1D }	nt"dt4| |j5dkrt6d t7 r|du rt8t
|j|}t rt9|t
|j||	t:  |S t9|t
|j||	t: }|S |du r|j|jd}|jd!d|gid"|d#t
|j||	id$ |S )&al  

    Copy value of the :attr:`x` to the :attr:`output`.

    Parameters:
        x (Tensor|np.ndarray|list|tuple|scalar): A Tensor, numpy ndarray, tuple/list of scalar,
            or scalar. Its data type can be float16, float32, float64, int32, int64 or bool. Note: the float64 data will be converted to float32 because of current platform protobuf
            data limitation.
        output (Tensor, optional): A Tensor. If :attr:`output` is None, a new Tensor will be created as :attr:`output`. Default: None.

    Returns:
        Tensor: A Tensor with the same shape, data type and value as :attr:`x`.

    Examples:
        .. code-block:: python

            >>> import paddle
            >>> import numpy as np
            >>> data = paddle.full(shape=[3, 2], fill_value=2.5, dtype='float64')
            >>> print(data.numpy())
            [[2.5 2.5]
             [2.5 2.5]
             [2.5 2.5]]
            >>> array = np.array([[1, 1],
            ...                     [3, 4],
            ...                     [1, 3]]).astype(np.int64)
            >>> result1 = paddle.zeros(shape=[3, 3], dtype='float32')
            >>> paddle.assign(array, result1)
            >>> print(result1.numpy())
            [[1 1]
             [3 4]
             [1 3]]
            >>> result2 = paddle.assign(data)
            >>> print(result2.numpy())
            [[2.5 2.5]
             [2.5 2.5]
             [2.5 2.5]]
            >>> result3 = paddle.assign(np.array([[2.5, 2.5], [2.5, 2.5], [2.5, 2.5]], dtype='float32'))
            >>> print(result3.numpy())
            [[2.5 2.5]
             [2.5 2.5]
             [2.5 2.5]]
    r   r   N	r*   r2   r+   r,   r/   r0   r1   r-   r)   z/(When the type of input in assign is Variable.)r   r   rY   r   r   c                 s   s"    | ]}t |ttjjfV  qd S r   )r_   r
   r@   r`   ra   r   r   r!   r!   r"   	<genexpr>I	  s    
zassign.<locals>.<genexpr>c                 s   s2    | ]}t |ttjjtjjfr|jd kV  qdS ))rP   N)	r_   r
   r   r   r   r@   r`   ra   r&   r   r!   r!   r"   r   M	  s    
zJUnsupport paddle.assign([Variable, Variable...]) with non-scalar variable.c                 S   s$   t | ttjjtjjfst| S | S r   )	r_   r
   r   r   r   r@   r`   ra   r   )r   r!   r!   r"   convert_scalarX	  s
   zassign.<locals>.convert_scalarr   r   zrThe type of received input == `object`, it is not supported to convert to tensor, such as [[Var], [Var], [3], [4]]zzpaddle.assign doesn't support float64 input now due to current platform protobuf data limitation, we convert it to float32Zbool_valuesc                 S      g | ]}t |qS r!   r>   r   vr!   r!   r"   r   	      zassign.<locals>.<listcomp>Zfp32_valuesc                 S   r   r!   )rB   r   r!   r!   r"   r   	  r   Zint32_valuesc                 S   r   r!   r   r   r!   r!   r"   r   	  r   Zint64_valuesc                 S   r   r!   r   r   r!   r!   r"   r   	  r   zWhen the type of 'input' in assign is numpy.ndarray, the data type of 'input' must be bool, float32, int32 or int64, but received %s.i   zXThe size of input is too big. Please consider saving it to file and 'load_op' to load itZassign_valuer    r&   )rI   r]   r\   )r   );r_   r
   r@   r`   ra   r   r?   r   r<   r=   r:   r;   rB   r>   r)   r~   r   r}   r   r   r   r   r   r   Zassign_out_r   r   r    re   rf   r   r&   anyallr   mapr   Zsqueezer   r   r   r   warningswarnr   rs   ZFLOAT64ZFLOAT32ZBOOLZflatZINT32ZINT64r   sizerc   r   r   Zassign_value_r   )
r   r   r   rD   r   r   retr    Z
value_namevaluesr!   r!   r"   r     s  -


    
    t







r   c                 C   s   |   S )a  
    Returns a copy of input Tensor. It will always have a Tensor copy.

    In addition, This function is derivable, so gradients will flow back from the output to input.

    Parameters:
        x (Tensor): The input Tensor.
        name(str, optional): For details, please refer to :ref:`api_guide_Name`. Generally, no setting is required. Default: None.

    Returns:
        Tensor, A Tensor copied from ``input``.

    Examples:
        .. code-block:: python

            >>> import paddle
            >>> import numpy as np

            >>> x = paddle.ones([2])
            >>> x.stop_gradient = False
            >>> x.retain_grads()
            >>> clone_x = paddle.clone(x)
            >>> clone_x.retain_grads()

            >>> y = clone_x**3
            >>> y.backward()
            >>> print(clone_x.grad.numpy())
            [3. 3.]
            >>> print(x.grad.numpy())
            [3. 3.]
    )clone)r   r5   r!   r!   r"   r   	  s    r   c                 C   s   t di t }t| dtd t| ttjjfr#t| j	dg ddd |du r.|j
| j	d}d}|du r7d}n$t }|| | rGd}n| rNd	}n| rUd
}n| r[d}d|i}|jdd| gid|gi|d |S )a  

    The OP copies the :attr:`input` to the :attr:`output`.
    NOTE: currently, only support CUDAPlace <-> CUDAPinnedPlace.

    Parameters:
        input (Tensor): A tensor. Its data type supports float16, float32, float64, int32, int64, and bool.
        device (Place): Target place for the output.
        output (Tensor, optional): A tensor. If :attr:`output` is None, a new tensor will
            be created as :attr:`output`. Default: None.

    Returns:
        Tensor, A tensor with the same shape, data type and value as :attr:`input`.

    Examples:
        .. code-block:: python

            >>> import paddle

            >>> data = paddle.full(shape=[3, 2], fill_value=2.5, dtype='float64')
            >>> print(data.numpy())
            [[2.5 2.5]
             [2.5 2.5]
             [2.5 2.5]]
            >>> # doctest: +SKIP('NOTE(zhiqiu): not public')
            >>> result = paddle._memcpy(data, place=paddle.CPUPlace())
            >>> print(result2)
            [[2.5 2.5]
             [2.5 2.5]
             [2.5 2.5]]
    memcpyr   r   z/(When the type of input in memcpy is Variable.)Nr   r   r   rP   r      dst_place_typer   rY   r   )r   )r   r?   r   r
   r_   r   r   r   r   r    re   r   Z	set_placeZis_cpu_placeZis_gpu_placeZis_cuda_pinned_placeZis_xpu_placerf   )r   rz   r   rD   r   pr\   r!   r!   r"   _memcpy	  sB    
r   c           	      C   s   t  r	t| |S t| dddgd t|dddgd d}t|fi t }| |d}|jt| jd}d|i}i }|j	||||d	 |S )
a  Return a compelx tensor given the real and image component.

    Args:
        real (Tensor): The real component. The data type should be 'float32' or 'float64'.
        imag (Tensor): The image component. The data type should be the same as ``real``.
        name (str, optional): For details, please refer to :ref:`api_guide_Name`. Generally, no setting is required. Default: None.

    Returns:
        Tensor: The output tensor. The data type is 'complex64' or 'complex128', with the same precision as ``real`` and ``imag``.

    Note:
        ``paddle.complex`` supports broadcasting. 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

    Examples:
        .. code-block:: python

            >>> import paddle
            >>> x = paddle.arange(2, dtype=paddle.float32).unsqueeze(-1)
            >>> y = paddle.arange(3, dtype=paddle.float32)
            >>> z = paddle.complex(x, y)
            >>> print(z)
            Tensor(shape=[2, 3], dtype=complex64, place=Place(cpu), stop_gradient=True,
            [[0j    , 1j    , 2j    ],
             [(1+0j), (1+1j), (1+2j)]])
    realr+   r,   compleximag)r   Yr   rY   rZ   )
r   r   r   r   r   r?   re   r%   r    rf   )	r   r   r5   r   rD   r[   ro   r]   r\   r!   r!   r"   r   0
  s(   
r   r0   c              	   C      t |tjjst|}t r |du r| }t| |||t }|S t | t	r)| dk r-t
d|dur?t |t	r:|dk r>t
dn| }t |t	sJt
dtdi t }|j|d}|jdi d|gi| |||d	d
 |S )a0  
    Return the indices of the lower triangular part of the 2-D matrix
    whose row and col is knowed.Indices are ordered based on row and then columns.
    The lower triangular part of the matrix is defined as the elements on
    and below the diagonal.

    Args:
        row (int): The input x which is a int number describe the number of row of the matrix.
        col (int): The input x which is a int number describe the number of col of the matrix.
        offset (int, optional): The offset to consider, default value is 0.

            - If offset = 0, all elements on and below the main diagonal are retained.
            - If offset > 0, include just as many diagonals above the main diagonal.
            - If offset < 0, excludes just as many diagonals below the main diagonal.

        dtype (int, optional): the data type of the output tensor, can be int32, int64.

    Returns:
        Tensor: Results of the indices of lower triangular part of a row * col matrix,
        where the first row contains row coordinates of and the second row contains column coordinates.

    Examples:
        .. code-block:: python

            >>> import paddle

            >>> # example 1, default offset value
            >>> data1 = paddle.tril_indices(4,4,0)
            >>> print(data1)
            Tensor(shape=[2, 10], dtype=int64, place=Place(cpu), stop_gradient=True,
            [[0, 1, 1, 2, 2, 2, 3, 3, 3, 3],
             [0, 0, 1, 0, 1, 2, 0, 1, 2, 3]])

            >>> # example 2, positive offset value
            >>> data2 = paddle.tril_indices(4,4,2)
            >>> print(data2)
            Tensor(shape=[2, 15], dtype=int64, place=Place(cpu), stop_gradient=True,
            [[0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3],
             [0, 1, 2, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3]])

            >>> # example 3, negative offset value
            >>> data3 = paddle.tril_indices(4,4,-1)
            >>> print(data3)
            Tensor(shape=[2, 6], dtype=int64, place=Place(cpu), stop_gradient=True,
            [[1, 2, 2, 3, 3, 3],
             [0, 0, 1, 0, 1, 2]])
    Nr    row should be a non-negative int col should be a non-negative intzoffset should be a  inttril_indicesr   ro   )rowscolsr   r    r   )r  )r_   r   r   r   r   r   r   r  r   r>   r   r   r?   re   rf   rowcolr   r    ro   rD   r!   r!   r"   r  d
  s6   0
r  c              	   C   r  )a  
    Return the indices of the upper triangular part of the 2-D matrix
    whose row and col is known. Indices are ordered based on row and then columns.
    The upper triangular part of the matrix is defined as the elements on
    and above the diagonal.

    Args:
        row (int): The input x which is a int number describe the number of row of the matrix.
        col (int, optional): The input x which is a int number describe the number of col of the matrix.
            default value for col is None, then it will be set equal to row, indicting a square matix.
        offset (int, optional): The offset to consider, default value is 0.

            - If offset = 0, all elements on and above the main diagonal are retained.
            - If offset > 0, include just as few diagonals above the main diagonal.
            - If offset < 0, excludes just as few diagonals below the main diagonal.

        dtype (str|np.dtype|paddle.dtype, optional): the data type of the output tensor,
            can be int32, int64, default value is int64.
    Returns:
        Tensor: Results of the indices of upper triangular part of a row * col matrix,
        where the first row contains row coordinates of and the second row contains column coordinates.

    Examples:
        .. code-block:: python

            >>> import paddle
            >>> # example 1, default offset value
            >>> data1 = paddle.triu_indices(4,4,0)
            >>> print(data1.numpy())
            [[0 0 0 0 1 1 1 2 2 3]
             [0 1 2 3 1 2 3 2 3 3]]
            >>> # example 2, positive offset value
            >>> data2 = paddle.triu_indices(4,4,2)
            >>> print(data2.numpy())
            [[0 0 1]
             [2 3 3]]
            >>> # example 3, negative offset value
            >>> data3 = paddle.triu_indices(4,4,-1)
            >>> print(data3.numpy())
            [[0 0 0 0 1 1 1 1 2 2 2 3 3]
             [0 1 2 3 0 1 2 3 1 2 3 2 3]]
    Nr   r  r  zoffset should be a inttriu_indicesr   ro   )r	  r
  r   r    r   )r  )r_   r   r   r   r   r   r   r  r   r>   r   r   r?   re   rf   r  r!   r!   r"   r  
  s6   +
r  c                 C   sD   t | dddgd t |dddgd t| t| | t| S )as  Return a Cartesian coordinates corresponding to the polar coordinates compelx tensor given the ``abs`` and ``angle`` component.

    Args:
        abs (Tensor): The abs component. The data type should be 'float32' or 'float64'.
        angle (Tensor): The anglee component. The data type should be the same as ``abs``.
        name (str, optional): For details, please refer to :ref:`api_guide_Name`. Generally, no setting is required. Default: None.

    Returns:
        Tensor: The output tensor. The data type is 'complex64' or 'complex128', with the same precision as ``abs`` and ``angle``.

    Note:
        ``paddle.polar`` supports broadcasting. 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

    Examples:
        .. code-block:: python

            >>> import paddle
            >>> import numpy as np

            >>> abs = paddle.to_tensor([1, 2], dtype=paddle.float64)
            >>> angle = paddle.to_tensor([np.pi / 2, 5 * np.pi / 4], dtype=paddle.float64)
            >>> out = paddle.polar(abs, angle)
            >>> print(out)
            Tensor(shape=[2], dtype=complex128, place=Place(cpu), stop_gradient=True,
            [ (6.123233995736766e-17+1j)             ,
             (-1.4142135623730954-1.414213562373095j)])
    r   r+   r,   zpaddle.polarangle)r   r@   r   cossin)r   r  r5   r!   r!   r"   polar  s
    r  c                 C   sR   |    t|| j}td| j}| |tj	 |
| | S )a}  Fills the tensor with numbers drawn from the Cauchy distribution.

    Args:
        x (Tenosr): the tensor will be filled, The data type is float32 or float64.
        loc (scalar, optional):  Location of the peak of the distribution. The data type is float32 or float64.
        scale (scalar, optional): The half-width at half-maximum (HWHM). The data type is float32 or float64. Must be positive values.
        name (str, optional): For details, please refer to :ref:`api_guide_Name`. Generally, no setting is required. Default: None.

    Returns:
        Tensor: input tensor with numbers drawn from the Cauchy distribution.

    Examples:
        .. code-block:: python

            >>> import paddle
            >>> x = paddle.randn([3, 4])
            >>> x.cauchy_(1, 2)
            >>> # doctest: +SKIP('random check')
            >>> print(x)
            Tensor(shape=[3, 4], dtype=float32, place=Place(cpu), stop_gradient=True,
            [[ 3.80087137,  2.25415039,  2.77960515,  7.64125967],
             [ 0.76541221,  2.74023032,  1.99383152, -0.12685823],
             [ 1.45228469,  1.76275957, -4.30458832, 34.74880219]])

    g      ?)Znormal_r@   r   rt   r    Z	subtract_Zscale_r<   piZtan_Zadd_)r   locscaler5   Zhalfr!   r!   r"   cauchy_-  s
   "r  c                 C   sV   t jt| jdj}t|| j}| jt	|t	dd | 
 t|  | S )a7  Fills the tensor with numbers drawn from the Geometric distribution.

    Args:
        x (Tenosr): the tensor will be filled, The data type is float32 or float64.
        probs (Real|Tensor): Probability parameter.
            The value of probs must be positive. When the parameter is a tensor, probs is probability of success for each trial.
        name (str, optional): For details, please refer to :ref:`api_guide_Name`. Generally, no setting is required. Default: None.

    Returns:
        Tensor: input tensor with numbers drawn from the Geometric distribution.

    Examples:
        .. code-block:: python

            >>> import paddle
            >>> x = paddle.randn([3, 4])
            >>> x.geometric_(0.3)
            >>> # doctest: +SKIP('random check')
            >>> print(x)
            Tensor(shape=[3, 4], dtype=float32, place=Place(cpu), stop_gradient=True,
            [[2.42739224, 4.78268528, 1.23302543, 3.76555204],
             [1.38877118, 0.16075331, 0.16401523, 2.47349310],
             [1.72872102, 2.76533413, 0.33410925, 1.63351011]])

    r   rP   )minmax)r<   Zfinfor   r    tinyr@   r   rt   Zuniform_rB   Zlog_Zdivide_log1p)r   Zprobsr5   r  r!   r!   r"   
geometric_O  s
   r  )FFN)NNFN)NF)NN)rp   NN)NNT)FNN)NNN)r   NrP   NN)r   N)r   r   r   )r   r   Nr   )r   r0   )Nr   r0   )r   rP   N)Gr   r   r   numpyr<   r@   r   Zpaddle.utils.inplace_utilsr   Zbase.data_feederr   r   r   r   r	   Zbase.frameworkr
   r   Zbase.param_attrr   Z	frameworkr   r   r   r   r   r   r   r   r   r   __all__r#   r%   r'   rF   rJ   rN   rq   r   r   r   r   rb   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r  r  r  r  r  r!   r!   r!   r"   <module>   sz   0	

R

R
*
z 

f
C
S
S
d
0
#
1
$
Q
> 
1@

B

A
w 

m
g
f 
d
$
Q
4
T
O&!