ó
    "Eñi!  ã            	       óÒ   • S SK Jr  S SKrS SKrS SKJr  S SKJr	  SS/r
 " S S\R                  5      r\R                  R                  \S5        SSS	.S
\S\	S-  S\S-  SS4S jjrg)é    )ÚAnyN)Ú
_to_dlpack)ÚDeviceÚDLDeviceTypeÚfrom_dlpackc                   óP   • \ rS rSrSrSrSrSrSrSr	Sr
S	rS
rSrSrSrSrSrSrSrg)r   é   )é   )é   )é   )é   )é   )é   )é	   )é
   )é   )é   )é   )r	   )é   )é   )é   © N)Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__ÚkDLCPUÚkDLCUDAÚkDLCUDAHostÚ	kDLOpenCLÚ	kDLVulkanÚkDLMetalÚkDLVPIÚkDLROCMÚkDLROCMHostÚ	kDLExtDevÚkDLCUDAManagedÚ	kDLOneAPIÚ	kDLWebGPUÚ
kDLHexagonÚkDLMAIAÚ__static_attributes__r   ó    ÚO/home/mande/repo/quber/.venv/lib/python3.13/site-packages/torch/utils/dlpack.pyr   r      sM   † à€FØ€GØ€KØ€IØ€IØ€HØ€FØ€GØ€KØ€IØ€NØ€IØ€IØ€JØƒGr-   aÙ  to_dlpack(tensor) -> PyCapsule

Returns an opaque object (a "DLPack capsule") representing the tensor.

.. note::
  ``to_dlpack`` is a legacy DLPack interface. The capsule it returns
  cannot be used for anything in Python other than use it as input to
  ``from_dlpack``. The more idiomatic use of DLPack is to call
  ``from_dlpack`` directly on the tensor object - this works when that
  object has a ``__dlpack__`` method, which PyTorch and most other
  libraries indeed have now.

.. warning::
  Only call ``from_dlpack`` once per capsule produced with ``to_dlpack``.
  Behavior when a capsule is consumed multiple times is undefined.

Args:
    tensor: a tensor to be exported

The DLPack capsule shares the tensor's memory.
)ÚdeviceÚcopyÚ
ext_tensorr/   r0   Úreturnztorch.Tensorc                ó~  • [        U S5      (       GaI  0 nSUS'   UnSnSnUb  X#S'   U R                  5       nUb­  [        U[        5      (       a  [        R
                  " U5      n[        U[        R
                  5      (       d  [        S[        U5       35      e[        R                  R                  U5      nXx:g  nU(       d  XƒS	'   U(       a  USL a  [        S
U SU S35      eUS   [        R                  [        R                  4;   ad  [        R                  R                  SUS    35      n	US   [        R                  :H  n
U
(       a  U	R                   S:X  a  SOU	R                   nX³S'   Sn U R"                  " S0 UD6nUc%  UR'                  SS5         U R"                  " S0 UD6nUc'  UR'                  SS5        Sn U R"                  " S0 UD6nUc$  UR'                  S	S5        U R"                  " S0 UD6n[        R                  R)                  U5      nUSL a  U(       d  U(       d  UR+                  5       nU(       a  UR-                  U5      nU$ Uc  Ub  [        S5      eU n[        R                  R)                  U5      $ ! [$         a     GNf = f! [$         a     Nüf = f! [$         a     Nâf = f)a	  from_dlpack(ext_tensor) -> Tensor

Converts a tensor from an external library into a ``torch.Tensor``.

The returned PyTorch tensor will share the memory with the input tensor
(which may have come from another library). Note that in-place operations
will therefore also affect the data of the input tensor. This may lead to
unexpected issues (e.g., other libraries may have read-only flags or
immutable data structures), so the user should only do this if they know
for sure that this is fine.

Args:
    ext_tensor (object with ``__dlpack__`` attribute, or a DLPack capsule):
        The tensor or DLPack capsule to convert.

        If ``ext_tensor`` is a tensor (or ndarray) object, it must support
        the ``__dlpack__`` protocol (i.e., have a ``ext_tensor.__dlpack__``
        method). Otherwise ``ext_tensor`` may be a DLPack capsule, which is
        an opaque ``PyCapsule`` instance, typically produced by a
        ``to_dlpack`` function or method.

    device (torch.device or str or None): An optional PyTorch device
        specifying where to place the new tensor. If None (default), the
        new tensor will be on the same device as ``ext_tensor``.

    copy (bool or None): An optional boolean indicating whether or not to copy
        ``self``. If None, PyTorch will copy only if necessary.

Examples::

    >>> import torch.utils.dlpack
    >>> t = torch.arange(4)

    # Convert a tensor directly (supported in PyTorch >= 1.10)
    >>> t2 = torch.from_dlpack(t)
    >>> t2[:2] = -1  # show that memory is shared
    >>> t2
    tensor([-1, -1,  2,  3])
    >>> t
    tensor([-1, -1,  2,  3])

    # The old-style DLPack usage, with an intermediate capsule object
    >>> capsule = torch.utils.dlpack.to_dlpack(t)
    >>> capsule
    <capsule object "dltensor" at ...>
    >>> t3 = torch.from_dlpack(capsule)
    >>> t3
    tensor([-1, -1,  2,  3])
    >>> t3[0] = -9  # now we're sharing memory between 3 tensors
    >>> t3
    tensor([-9, -1,  2,  3])
    >>> t2
    tensor([-9, -1,  2,  3])
    >>> t
    tensor([-9, -1,  2,  3])

Ú
__dlpack__)r
   r   Úmax_versionTFNr0   z&from_dlpack: unsupported device type: Ú	dl_devicez&cannot move DLPack tensor from device z to z- without copying. Set copy=None or copy=True.r   zcuda:r
   ÚstreamzQdevice and copy kwargs not supported when ext_tensor is already a DLPack capsule.r   )ÚhasattrÚ__dlpack_device__Ú
isinstanceÚstrÚtorchr/   ÚAssertionErrorÚtypeÚ_CÚ_torchDeviceToDLDeviceÚ
ValueErrorr   r   r$   ÚcudaÚcurrent_streamÚcuda_streamr4   Ú	TypeErrorÚpopÚ_from_dlpackÚcloneÚto)r1   r/   r0   ÚkwargsÚrequested_copyÚproducer_handled_copyÚcross_device_transferÚ
ext_deviceÚtarget_dl_devicer7   Úis_cudaÚ
stream_ptrÚdlpackÚtensors                 r.   r   r   :   sÜ  € ô@ ˆz˜<×(Ò(ð "$ˆØ &ˆˆ}Ñð ˆØ $ÐØ %ÐàÑØ!�6‰Nð  ×1Ñ1Ó3ˆ
àÑÜ˜&¤#×&Ñ&ÜŸš fÓ-�Ü˜f¤e§l¡l×3Ñ3Ü$Ð'MÌdÐSYËlÈ^Ð%\Ó]Ð]ô  %Ÿx™x×>Ñ>¸vÓFÐð &0Ñ%CÐ!ö )Ø&6�{Ñ#ö %¨°ªÜ Ø<¸Z¸LÈÐM]ÐL^ð _Cð Cóð ð �a‰=œ\×1Ñ1´<×3GÑ3GÐHÓHÜ—Z‘Z×.Ñ.°°zÀ!±}°oÐ/FÓGˆFð ! ‘m¤|×';Ñ';Ñ;ˆGö &¨&×*<Ñ*<ÀÓ*A™Àv×GYÑGYˆJØ)�8Ñð ˆð	Ø×*Ò*Ñ4¨VÑ4ˆFð
 ‰>Ø�J‰J�} dÔ+ðØ#×.Ò.Ñ8°Ñ8�ð
 ‰>Ø�J‰J�v˜tÔ$Ø$)Ð!ðØ#×.Ò.Ñ8°Ñ8�ð
 ‰>Ø�J‰J�{ DÔ)Ø×*Ò*Ñ4¨VÑ4ˆFä—‘×&Ñ& vÓ.ˆð ˜TÒ!Ö*?ÖH]Ø—\‘\“^ˆFö !Ø—Y‘Y˜vÓ&ˆFàˆð Ñ Ñ!1Ü Øcóð ð ˆÜ�x‰x×$Ñ$ VÓ,Ð,øôY ó 	Úð	ûô ó Ùðûô ó Ùðús6   Å5J ÆJ ÇJ/ Ê
JÊJÊ
J,Ê+J,Ê/
J<Ê;J<)Útypingr   r<   ÚenumÚtorch._Cr   Ú	to_dlpackÚtorch.typesr   Ú_DeviceÚ__all__ÚIntEnumr   r?   Ú_add_docstrÚboolr   r   r-   r.   Ú<module>r^      sŽ   ðÝ ã Û å ,Ý )ð Øð€ô
�4—<‘<ô ð& ‡�× Ñ �Yð !ô ð8 "Øò	m-Øðm-ð �d‰Nðm-ð �‰+ð	m-ð
 öm-r-   