
    ёi/                    6   S SK Jr  S SKJr  S SKrS SKrS SKJr  S SKJ	r	J
r
  SSKJrJr  SSKJrJr  SS	KJr  SS
KJrJr  SSKJrJr  \(       a  S SKJr  / rSS jrSS jr\	" SS/05      SS j5       r\
" SS/5      SS j5       rSS jrSSS jjr SSS jjr!g)    )annotations)TYPE_CHECKINGN)_C_ops)ParamAliasDecoratorparam_one_alias   )
check_typecheck_variable_and_dtype)in_dynamic_or_pir_modeuse_pir_api)Variable)LayerHelpercore   )_complex_to_real_dtypeassign)Tensorinputc                    [        U S[        [        R                  R                  4S5        [        U R                  5      n[        [        R                  " US5      5      nU$ )a  

Returns the number of dimensions for a tensor, which is a 0-D int32 Tensor.

Args:
    input (Tensor): The input Tensor with shape of :math:`[N_1, N_2, ..., N_k]`, the data type is arbitrary.

Returns:
    Tensor, the output data type is int32.: The 0-D tensor with the dimensions of the input Tensor.

Examples:
    .. code-block:: python

        >>> import paddle

        >>> input = paddle.rand((3, 100, 100))
        >>> rank = paddle.rank(input)
        >>> print(rank.numpy())
        3
r   int32)
r	   r   paddlepirValuelenshaper   nparray)r   ndimsouts      W/var/www/html/banglarbhumi/venv/lib/python3.13/site-packages/paddle/tensor/attribute.pyrankr!   %   sI    * ug&***:*:;WEE
%)
*CJ    c                    [        5       (       a  [        R                  " U 5      nSUl        U$ [	        U S/ SQS5        [        S
0 [        5       D6nUR                  SS9nUR                  SSU 0SU0SS	9  SUl        U$ )a1  
Get the shape of the input.

.. code-block:: text

    Case1:
        Given N-D Tensor:
            input = [ [1, 2, 3, 4], [5, 6, 7, 8] ]

        Then:
            input.shape = [2, 4]

    Case2:
        Given SelectedRows:
            input.rows = [0, 4, 19]
            input.height = 20
            input.value = [ [1, 2], [3, 4], [5, 6] ]  # inner tensor
        Then:
            input.shape = [3, 2]

Args:
    input (Tensor): The input can be N-D Tensor or SelectedRows with data type bool, bfloat16, float16, float32, float64, int32, int64.
                      If input variable is type of SelectedRows, returns the shape of it's inner tensor.

Returns:
    Tensor: The shape of the input variable.

Examples:
    .. code-block:: pycon

        >>> import numpy as np
        >>> import paddle
        >>> paddle.enable_static()

        >>> inputs = paddle.static.data(name="x", shape=[3, 100, 100], dtype="float32")
        >>> output = paddle.shape(inputs)

        >>> exe = paddle.static.Executor(paddle.CPUPlace())
        >>> exe.run(paddle.static.default_startup_program())

        >>> img = np.ones((3, 100, 100)).astype(np.float32)

        >>> res = exe.run(paddle.static.default_main_program(), feed={'x': img}, fetch_list=[output])
        >>> print(res)
        [array([  3, 100, 100], dtype=int64)]
Tr   )booluint16float16float32float64r   int64	complex64
complex128r%   float8_e4m3fnfloat8_e5m2r   r   dtypeInputOut)typeinputsoutputsstop_gradient)r   )	r   r   shape64r5   r
   r   locals"create_variable_for_type_inference	append_op)r   r   helpers      r    r   r   A   s    ^ nnU# 
  #	
& 1177g7FU#CL	 	 	
 !
r"   xc                *   [        U [        R                  [        R                  R                  [        R
                  R                  45      (       d  [        S[        U 5       35      eU R                  nU[        R                  R                  R                  :H  =(       do    U[        R                  R                  R                  :H  =(       dA    U[        R                  R                  :H  =(       d    U[        R                  R                  :H  nU$ )a  Return whether x is a tensor of complex data type(complex64 or complex128).


.. note::
Alias Support: The parameter name ``input`` can be used as an alias for ``x``.
For example, ``input=tensor_x`` is equivalent to ``x=tensor_x``.

Args:
    x (Tensor): The input tensor.
    input: An alias for ``x`` , with identical behavior.

Returns:
    bool: True if the data type of the input is complex data type, otherwise false.

Examples:
    .. code-block:: python

        >>> import paddle

        >>> x = paddle.to_tensor([1 + 2j, 3 + 4j])
        >>> print(paddle.is_complex(x))
        True

        >>> x = paddle.to_tensor([1.1, 1.2])
        >>> print(paddle.is_complex(x))
        False

        >>> x = paddle.to_tensor([1, 2, 3])
        >>> print(paddle.is_complex(x))
        False
)Expected Tensor, but received type of x: )
isinstancer   r   staticr   r   r   	TypeErrorr2   r/   r   VarDescVarType	COMPLEX64
COMPLEX128DataType)r;   r/   is_complex_dtypes      r    
is_complexrG      s    B 	FMM6==116::3C3CD  CDG9MNNGGE%%/// 	-DLL((333	-DMM+++	- DMM,,,	  r"   c                t   [        U [        R                  [        R                  R                  [        R
                  R                  45      (       d  [        S[        U 5       35      eU R                  nU[        R                  R                  R                  :H  =(       Gd    U[        R                  R                  R                  :H  =(       d    U[        R                  R                  R                  :H  =(       d    U[        R                  R                  R                   :H  =(       d    U[        R"                  R$                  :H  =(       de    U[        R"                  R&                  :H  =(       dA    U[        R"                  R(                  :H  =(       d    U[        R"                  R*                  :H  nU$ )a  
Returns whether the dtype of `x` is one of paddle.float64, paddle.float32, paddle.float16, and paddle.bfloat16.

.. note::
    Alias Support: The parameter name ``input`` can be used as an alias for ``x``.
    For example, ``is_floating_point(input=tensor_x)`` is equivalent to ``is_floating_point(x=tensor_x)``.

Args:
    x (Tensor): The input tensor. alias: ``input``.

Returns:
    bool: True if the dtype of `x` is floating type, otherwise false.

Examples:
    .. code-block:: python

        >>> import paddle

        >>> x = paddle.arange(1., 5., dtype='float32')
        >>> y = paddle.arange(1, 5, dtype='int32')
        >>> print(paddle.is_floating_point(x))
        True
        >>> print(paddle.is_floating_point(y))
        False
r=   )r>   r   r   r?   r   r   r   r@   r2   r/   r   rA   rB   FP32FP64FP16BF16rE   FLOAT32FLOAT64FLOAT16BFLOAT16)r;   r/   is_fp_dtypes      r    is_floating_pointrR      s>   6 	FMM6==116::3C3CD  CDG9MNNGGE%%*** 	+ 	+DLL((---	+DLL((---	+ DLL((---	+ DMM)))		+
 DMM)))	+ DMM)))	+ DMM***  r"   c                .   [        U [        R                  [        R                  R                  [        R
                  R                  45      (       d  [        S[        U 5       35      eU R                  nSn[        5       (       d  U[        R                  R                  R                  :H  =(       d    U[        R                  R                  R                  :H  =(       d    U[        R                  R                  R                   :H  =(       dU    U[        R                  R                  R"                  :H  =(       d'    U[        R                  R                  R$                  :H  nU$ U[        R&                  R                  :H  =(       d    U[        R&                  R                  :H  =(       de    U[        R&                  R                   :H  =(       dA    U[        R&                  R"                  :H  =(       d    U[        R&                  R$                  :H  nU$ )a,  Return whether x is a tensor of integral data type.

Args:
    x (Tensor): The input tensor.

Returns:
    bool: True if the data type of the input is integer data type, otherwise false.

Examples:
    .. code-block:: python

        >>> import paddle

        >>> x = paddle.to_tensor([1 + 2j, 3 + 4j])
        >>> print(paddle.is_integer(x))
        False

        >>> x = paddle.to_tensor([1.1, 1.2])
        >>> print(paddle.is_integer(x))
        False

        >>> x = paddle.to_tensor([1, 2, 3])
        >>> print(paddle.is_integer(x))
        True
r=   F)r>   r   r   r?   r   r   r   r@   r2   r/   r   r   rA   rB   UINT8INT8INT16INT32INT64rE   )r;   r/   is_int_dtypes      r    
is_integerrZ      s   4 	FMM6==116::3C3CD  CDG9MNNGGEL==T\\))/// 3,,1113,,2223 ,,2223 ,,222 	   T]]((( ,***,+++, +++, +++ 	 r"   c                   [        5       (       a  [        R                  " U 5      $ [        U SSS/S5        [	        S	0 [        5       D6nUR                  [        UR                  5       5      S9nUR                  SSU 0SU0S9  U$ )
aw  
Returns a new Tensor containing real values of the input Tensor.

Args:
    x (Tensor): the input Tensor, its data type could be complex64 or complex128.
    name (str|None, 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 containing real values of the input Tensor.

Examples:
    .. code-block:: python

        >>> import paddle

        >>> x = paddle.to_tensor(
        ...     [[1 + 6j, 2 + 5j, 3 + 4j], [4 + 3j, 5 + 2j, 6 + 1j]])
        >>> print(x)
        Tensor(shape=[2, 3], dtype=complex64, place=Place(cpu), stop_gradient=True,
        [[(1+6j), (2+5j), (3+4j)],
         [(4+3j), (5+2j), (6+1j)]])

        >>> real_res = paddle.real(x)
        >>> print(real_res)
        Tensor(shape=[2, 3], dtype=float32, place=Place(cpu), stop_gradient=True,
        [[1., 2., 3.],
         [4., 5., 6.]])

        >>> real_t = x.real()
        >>> print(real_t)
        Tensor(shape=[2, 3], dtype=float32, place=Place(cpu), stop_gradient=True,
        [[1., 2., 3.],
         [4., 5., 6.]])
r;   r*   r+   realr.   Xr1   r2   r3   r4   )r\   )
r   r   r\   r
   r   r7   r8   r   input_dtyper9   r;   namer:   r   s       r    r\   r\   %      H {{1~ C+|)DfM0vx077(););)=> 8 
 	fc1Xs|L
r"   c                   [        5       (       a  [        R                  " U 5      $ [        U SSS/S5        [	        S	0 [        5       D6nUR                  [        UR                  5       5      S9nUR                  SSU 0SU0S9  U$ )
a}  
Returns a new tensor containing imaginary values of input tensor.

Args:
    x (Tensor): the input tensor, its data type could be complex64 or complex128.
    name (str|None, 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 containing imaginary values of the input tensor.

Examples:
    .. code-block:: python

        >>> import paddle

        >>> x = paddle.to_tensor(
        ...     [[1 + 6j, 2 + 5j, 3 + 4j], [4 + 3j, 5 + 2j, 6 + 1j]])
        >>> print(x)
        Tensor(shape=[2, 3], dtype=complex64, place=Place(cpu), stop_gradient=True,
        [[(1+6j), (2+5j), (3+4j)],
         [(4+3j), (5+2j), (6+1j)]])

        >>> imag_res = paddle.imag(x)
        >>> print(imag_res)
        Tensor(shape=[2, 3], dtype=float32, place=Place(cpu), stop_gradient=True,
        [[6., 5., 4.],
         [3., 2., 1.]])

        >>> imag_t = x.imag()
        >>> print(imag_t)
        Tensor(shape=[2, 3], dtype=float32, place=Place(cpu), stop_gradient=True,
        [[6., 5., 4.],
         [3., 2., 1.]])
r;   r*   r+   imagr.   r]   r1   r^   )rd   )
r   r   rd   r
   r   r7   r8   r   r_   r9   r`   s       r    rd   rd   U  rb   r"   )r   r   returnr   )r;   r   re   r$   )N)r;   r   ra   z
str | Nonere   r   )"
__future__r   typingr   numpyr   r   r   paddle.utils.decorator_utilsr   r   base.data_feederr	   r
   base.frameworkr   r   common_ops_importr   	frameworkr   r   creationr   r   r   __all__r!   r   rG   rR   rZ   r\   rd    r"   r    <module>rq      s    #      M C @ ( ) 4
8Pf cG9%&+ '+\ #w ) !)X2j-`-r"   