Ë
    –\;j  ã                   óD   — d dl Z ddlmZ ddlmZ ddlmZ ddgZd„ Zd	„ Z	y)
é    Né   )Ú	LoDTensor)Ú
check_type)Úin_dygraph_modeÚ	to_dlpackÚfrom_dlpackc                 ór  — t        «       rŒt        | t        j                  t        j                  j
                  j                  j                  f«      st        dt        | «      › d�«      ‚| j                  «       j                  «       j                  «       S t        | dt        d«       | j                  «       S )a  
    Encodes a tensor to DLPack.

    Args:
        x (Tensor): The input tensor, and the data type can be `bool`, `float16`, `float32`,
                    `float64`, `int8`, `int16`, `int32`, `int64`, `uint8`, `complex64`,
                    `complex128`.

    Returns:
        dltensor, and the data type is PyCapsule.

    Examples:
        .. code-block:: python

            >>> import paddle
            >>> # x is a tensor with shape [2, 4]
            >>> x = paddle.to_tensor([[0.2, 0.3, 0.5, 0.9],
            ...                       [0.1, 0.2, 0.6, 0.7]])
            >>> dlpack = paddle.utils.dlpack.to_dlpack(x)
            >>> print(dlpack)
            >>> # doctest: +SKIP('the address will change in every run')
            <capsule object "dltensor" at 0x7f6103c681b0>
    zAThe type of 'x' in to_dlpack must be paddle.Tensor, but received Ú.Úxr   )r   Ú
isinstanceÚpaddleÚTensorÚbaseÚcoreÚeagerÚ	TypeErrorÚtypeÚvalueÚ
get_tensorÚ
_to_dlpackr   r   )r   s    ú\G:\00. PROJECTS\API\Inventory\templateJSON\kerjaOCR\Lib\site-packages\paddle/utils/dlpack.pyr   r      s�   € ô2 ÔÜ˜!œfŸm™m¬V¯[©[×-=Ñ-=×-CÑ-C×-JÑ-JÐKÔLÜð!Ü!% a£ 	¨ð,óð ð
 �w‰w‹y×#Ñ#Ó%×0Ñ0Ó2Ð2äˆq�#œ	 KÔ0Ø�<‰<‹>Ðó    c                 óv  — t        | «      }|j                  dk(  xr |j                  dk(  }|st        dt        | «      › d�«      ‚t	        «       r@t
        j                  j                  j                  | «      }t        j                  |«      }|S t
        j                  j                  j                  | «      }|S )aÂ  
    Decodes a DLPack to a tensor.

    Args:
        dlpack (PyCapsule): a PyCapsule object with the dltensor.

    Returns:
        out (Tensor), a tensor decoded from DLPack. One thing to be noted, if we get
                      an input dltensor with data type as `bool`, we return the decoded
                      tensor as `uint8`.

    Examples:
        .. code-block:: python

            >>> import paddle
            >>> # x is a tensor with shape [2, 4]
            >>> x = paddle.to_tensor([[0.2, 0.3, 0.5, 0.9],
            ...                       [0.1, 0.2, 0.6, 0.7]])
            >>> dlpack = paddle.utils.dlpack.to_dlpack(x)
            >>> x = paddle.utils.dlpack.from_dlpack(dlpack)
            >>> print(x)
            Tensor(shape=[2, 4], dtype=float32, place=Place(cpu), stop_gradient=True,
                   [[0.20000000, 0.30000001, 0.50000000, 0.89999998],
                    [0.10000000, 0.20000000, 0.60000002, 0.69999999]])
    ÚbuiltinsÚ	PyCapsulezKThe type of 'dlpack' in from_dlpack must be PyCapsule object, but received r
   )
r   Ú
__module__Ú__name__r   r   r   r   r   r   Ú	to_tensor)ÚdlpackÚtÚdlpack_flagÚouts       r   r   r   A   s¤   € ô6 	ˆV‹€AØ—,‘, *Ñ,ÒJ°·±¸{Ñ1J€KÙÜðÜ! &›\˜N¨!ð-ó
ð 	
ô
 ÔÜ�k‰k×Ñ×*Ñ*¨6Ó2ˆÜ×Ñ˜sÓ#ˆØˆ
ä
�+‰+×
Ñ
×
&Ñ
& vÓ
.€CØ€Jr   )
r   Ú	base.corer   Úbase.data_feederr   Úbase.frameworkr   Ú__all__r   r   © r   r   Ú<module>r(      s-   ðó å !Ý )Ý ,ð Øð€ò#óL)r   