
    |j/                    4   d dl mZ d dlmZ d dlZd dlZd dlmZ d dlm	Z	m
Z
 ddlmZmZ ddlmZmZ dd	lmZ dd
lmZmZ ddlmZmZ erd dlmZ g ZddZddZ e	ddgi          dd            Z e
ddg          dd            ZddZdddZ dddZ!dS )     )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inputr   returnc                    t          | dt          t          j        j        fd           t          | j                  }t          t          j	        |d                    }|S )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      g/lsinfo/ai/hellotax_ai/data_center/backend/venv/lib/python3.11/site-packages/paddle/tensor/attribute.pyrankr"   %   sO    * ug&**:;WEEEE
%))
*
*CJ    c                (   t                      rt          j        |           }d|_        |S t	          | dg dd           t          di t                      }|                    d          }|                    dd| id|id	           d|_        |S )a  
    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_gradientN)r   )	r   r   shape64r6   r
   r   locals"create_variable_for_type_inference	append_op)r   r    helpers      r!   r   r   A   s    ^  !nU## 
    #	
 	
 	
& 111177g7FFU#CL	 	 	
 	
 	
 !
r#   xr%   c                   t          | t          j        t          j        j        t          j        j        f          st          dt          |                      | j	        }|t          j        j        j        k    pC|t          j        j        j        k    p)|t          j        j        k    p|t          j        j        k    }|S )am  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   	TypeErrorr3   r0   r   VarDescVarType	COMPLEX64
COMPLEX128DataType)r<   r0   is_complex_dtypes      r!   
is_complexrH      s    B 	FM6=16:3CD  O MDGGMMNNNGE%// 	-DL(33	-DM++	- DM,,	  r#   c                @   t          | t          j        t          j        j        t          j        j        f          st          dt          |                      | j	        }|t          j        j        j        k    p|t          j        j        j        k    p|t          j        j        j        k    pm|t          j        j        j        k    pS|t          j        j        k    p>|t          j        j        k    p)|t          j        j        k    p|t          j        j        k    }|S )a2  
    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   rA   r3   r0   r   rB   rC   FP32FP64FP16BF16rF   FLOAT32FLOAT64FLOAT16BFLOAT16)r<   r0   is_fp_dtypes      r!   is_floating_pointrS      s   6 	FM6=16:3CD  O MDGGMMNNNGE%** 	+DL(--	+DL(--	+ DL(--	+ DM))		+
 DM))	+ DM))	+ DM**  r#   c                   t          | t          j        t          j        j        t          j        j        f          st          dt          |                      | j	        }d}t                      s|t          j        j        j        k    pg|t          j        j        j        k    pM|t          j        j        j        k    p3|t          j        j        j        k    p|t          j        j        j        k    }ni|t          j        j        k    pS|t          j        j        k    p>|t          j        j        k    p)|t          j        j        k    p|t          j        j        k    }|S )ap  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   rA   r3   r0   r   r   rB   rC   UINT8INT8INT16INT32INT64rF   )r<   r0   is_int_dtypes      r!   
is_integerr[      s=   4 	FM6=16:3CD  O MDGGMMNNNGEL== 
T\)// 3,113,223 ,223 ,22 	 T](( ,**,++, ++, ++ 	 r#   name
str | Nonec                D   t                      rt          j        |           S t          | dddgd           t	          d
i t                      }|                    t          |                                                    }|	                    dd| id|i           |S )a  
    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/   Xr2   r3   r4   r5   N)r_   )
r   r   r_   r
   r   r8   r9   r   input_dtyper:   r<   r\   r;   r    s       r!   r_   r_   %      H  	{1~~ C+|)DfMMM00vxx0077(););)=)=>> 8 
 
 	fc1Xs|LLL
r#   c                D   t                      rt          j        |           S t          | dddgd           t	          d
i t                      }|                    t          |                                                    }|	                    dd| id|i           |S )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`   r2   ra   N)rf   )
r   r   rf   r
   r   r8   r9   r   rb   r:   rc   s       r!   rf   rf   U  rd   r#   )r   r   r   r   )r<   r   r   r%   )N)r<   r   r\   r]   r   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   rH   rS   r[   r_   rf    r#   r!   <module>rr      s   # " " " " "                        M M M M M M M M C C C C C C C C @ @ @ @ @ @ @ @ ( ( ( ( ( ( ) ) ) ) ) ) ) ) 4 4 4 4 4 4 4 4 
   8P P P Pf cG9%&&+ + + '&+\ #w  ) ) ) ! )X2 2 2 2j- - - - -`- - - - - - -r#   