Ë
    –\;j
-  ã                   óž   — 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 ddlmZmZ dd	lmZmZ g Zd
„ Zd„ Zd„ Zd„ Zd„ Zdd„Zdd„Zy)é    N)Ú_C_opsé   )Ú
check_typeÚcheck_variable_and_dtype)Úin_dynamic_or_pir_modeÚin_pir_mode)ÚVariable)ÚLayerHelperÚcoreé   )Ú_complex_to_real_dtypeÚassignc                 óÆ   — 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
    ÚinputÚint32)
r   r	   ÚpaddleÚpirÚValueÚlenÚshaper   ÚnpÚarray)r   ÚndimsÚouts      ú`G:\00. PROJECTS\API\Inventory\templateJSON\kerjaOCR\Lib\site-packages\paddle/tensor/attribute.pyÚrankr      sI   € ô* ˆu�g¤¬&¯*©*×*:Ñ*:Ð;¸WÔEÜ�—‘Ó€EÜ
”—‘˜% Ó)Ó
*€Cà€Jó    c                 ó   — t        «       rt        j                  | «      }d|_        |S t	        | dg d¢d«       t        d
i t        «       ¤Ž}|j                  d¬«      }|j                  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 (Variable): 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:
        Variable (Tensor): The shape of the input variable.

    Examples:
        .. code-block:: python

            >>> 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=int32)]
    Tr   )
ÚboolÚuint16Úfloat16Úfloat32Úfloat64r   Úint64Ú	complex64Ú
complex128r    r   r   ©ÚdtypeÚInputÚOut)ÚtypeÚinputsÚoutputsÚstop_gradient)r   )	r   r   r   r.   r   r
   ÚlocalsÚ"create_variable_for_type_inferenceÚ	append_op)r   r   Úhelpers      r   r   r   ;   s™   € ô^ ÔÜ�l‰l˜5Ó!ˆØ ˆÔØˆ
ä ØØòð ô	
ô" Ñ1¬«Ñ1ˆØ×7Ñ7¸gÐ7ÓFˆØ×ÑØØ˜UÐ#Ø˜C�LØð	 	ô 	
ð !ˆÔØˆ
r   c                 ó  — t        | t        j                  t        j                  j                  t        j
                  j                  f«      st        dt        | «      › �«      ‚| j                  }|t        j                  j                  j                  k(  xse |t        j                  j                  j                  k(  xs< |t        j                  j                  k(  xs |t        j                  j                  k(  }|S )aˆ  Return whether x is a tensor of complex data type(complex64 or complex128).

    Args:
        x (Tensor): The input tensor.

    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   ÚTensorÚstaticr	   r   r   Ú	TypeErrorr+   r(   r   ÚVarDescÚVarTypeÚ	COMPLEX64Ú
COMPLEX128ÚDataType)Úxr(   Úis_complex_dtypes      r   Ú
is_complexr@   Œ   sÄ   € ô4 Ø	ŒF�M‰Mœ6Ÿ=™=×1Ñ1´6·:±:×3CÑ3CÐDôô ÐCÄDÈÃGÀ9ÐMÓNÐNØ�G‰G€Eà”—‘×%Ñ%×/Ñ/Ñ/ò 	-Ø”D—L‘L×(Ñ(×3Ñ3Ñ3ò	-à”D—M‘M×+Ñ+Ñ+ò	-ð ”D—M‘M×,Ñ,Ñ,ð	 ð Ðr   c                 óø  — t        | t        j                  t        j                  j                  f«      st        dt        | «      › �«      ‚| j                  }|t        j                  j                  j                  k(  xsy |t        j                  j                  j                  k(  xsP |t        j                  j                  j                  k(  xs' |t        j                  j                  j                  k(  }|S )aK  
    Returns whether the dtype of `x` is one of paddle.float64, paddle.float32, paddle.float16, and paddle.bfloat16.

    Args:
        x (Tensor): The input tensor.

    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
    r4   )r5   r   r6   r7   r	   r8   r+   r(   r   r9   r:   ÚFP32ÚFP64ÚFP16ÚBF16)r>   r(   Úis_fp_dtypes      r   Úis_floating_pointrG   ´   s¿   € ô, �aœ&Ÿ-™-¬¯©×)?Ñ)?Ð@ÔAÜÐCÄDÈÃGÀ9ÐMÓNÐNØ�G‰G€Eà”—‘×%Ñ%×*Ñ*Ñ*ò 	.Ø”D—L‘L×(Ñ(×-Ñ-Ñ-ò	.à”D—L‘L×(Ñ(×-Ñ-Ñ-ò	.ð ”D—L‘L×(Ñ(×-Ñ-Ñ-ð	 ð Ð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(  xs¢ |t        j                  j                  j                  k(  xsy |t        j                  j                  j                   k(  xsP |t        j                  j                  j"                  k(  xs' |t        j                  j                  j$                  k(  }|S |t        j&                  j                  k(  xsz |t        j&                  j                  k(  xs[ |t        j&                  j                   k(  xs< |t        j&                  j"                  k(  xs |t        j&                  j$                  k(  }|S )aq  Return whether x is a tensor of integeral 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
    r4   F)r5   r   r6   r7   r	   r   ÚOpResultr8   r+   r(   r   r   r9   r:   ÚUINT8ÚINT8ÚINT16ÚINT32ÚINT64r=   )r>   r(   Úis_int_dtypes      r   Ú
is_integerrP   Ö   sz  € ô4 Ø	ŒF�M‰Mœ6Ÿ=™=×1Ñ1´6·:±:×3FÑ3FÐGôô ÐCÄDÈÃGÀ9ÐMÓNÐNØ�G‰G€Eà€LÜŒ=à”T—\‘\×)Ñ)×/Ñ/Ñ/ò 3ØœŸ™×,Ñ,×1Ñ1Ñ1ò3àœŸ™×,Ñ,×2Ñ2Ñ2ò3ð œŸ™×,Ñ,×2Ñ2Ñ2ò3ð œŸ™×,Ñ,×2Ñ2Ñ2ð 	ð  Ðð ”T—]‘]×'Ñ'Ñ'ò ,ØœŸ™×*Ñ*Ñ*ò,àœŸ™×+Ñ+Ñ+ò,ð œŸ™×+Ñ+Ñ+ò,ð œŸ™×+Ñ+Ñ+ð 	ð Ðr   c                 ó  — t        «       rt        j                  | «      S t        | dddgd«       t	        d	i t        «       ¤Ž}|j                  t        |j                  «       «      ¬«      }|j                  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, 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'   ÚXr*   ©r+   r,   r-   )rR   )
r   r   rR   r   r
   r/   r0   r   Úinput_dtyper1   ©r>   Únamer2   r   s       r   rR   rR     ó…   € ôH ÔÜ�{‰{˜1‹~Ðä   C¨+°|Ð)DÀfÔMÜÑ0¤v£xÑ0ˆØ×7Ñ7Ü(¨×);Ñ);Ó)=Ó>ð 8ó 
ˆð 	×Ñ˜f¨c°1¨XÀÀs¸|ÐÔLØˆ
r   c                 ó  — t        «       rt        j                  | «      S t        | dddgd«       t	        d	i t        «       ¤Ž}|j                  t        |j                  «       «      ¬«      }|j                  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, 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'   rS   r*   rT   )rZ   )
r   r   rZ   r   r
   r/   r0   r   rU   r1   rV   s       r   rZ   rZ   ;  rX   r   )N)Únumpyr   r   r   Úbase.data_feederr   r   Úbase.frameworkr   r   Úcommon_ops_importr	   Ú	frameworkr
   r   Úcreationr   r   Ú__all__r   r   r@   rG   rP   rR   rZ   © r   r   Ú<module>rc      sM   ðó" ã Ý ç Cß @Ý (ß )ß 4à
€òò8Nòb%òPòD2ój-ô`-r   