§
    “©ºj§  ã                   óþ  — U d Z ddlmZ ddlmZ ddlmZmZmZm	Z	 ddl
Z
ddlmZ ddl
mZ ddlmZ dd	lmZ erddlZd
Zdddedefd„Ze ee
j        e
j        ¬¦  «        fe ee
j        e
j        ¬¦  «        fe ee
j        e
j        ¬¦  «        fgZeeeeeegef         f                  ed<   er ddlZe                     ej         ef¦  «          G d„ de¦  «        Z!dededefd„Z"dededefd„Z#dedefd„Z$dS )zUtilities used for collections.é    )ÚABC)Úpartial)ÚTYPE_CHECKINGÚAnyÚCallableÚUnionN)Úapply_to_collection)ÚTensor)Ú_NUMPY_AVAILABLE)Ú_DEVICE)ÚcpuÚmpsÚvaluez
np.ndarrayÚdeviceÚreturnc                 óP   — t          j        | ¦  «                             |¦  «        S )N)ÚtorchÚ
from_numpyÚto)r   r   s     úu/root/private/project/pallet_detection_v2/.venv/lib/python3.11/site-packages/lightning_fabric/utilities/apply_func.pyÚ_from_numpyr   !   s!   € ÝÔ˜EÑ"Ô"×%Ò% fÑ-Ô-Ð-ó    )ÚdtypeÚCONVERSION_DTYPESc                   óB   — e Zd ZdZededeeef         fd„¦   «         ZdS )Ú_TransferableDataTypea"  A custom type for data that can be moved to a torch device via ``.to(...)``.

    Example:

        >>> isinstance(dict, _TransferableDataType)
        False
        >>> isinstance(torch.rand(2, 3), _TransferableDataType)
        True
        >>> class CustomObject:
        ...     def __init__(self):
        ...         self.x = torch.rand(2, 2)
        ...     def to(self, device):
        ...         self.x = self.x.to(device)
        ...         return self
        >>> isinstance(CustomObject(), _TransferableDataType)
        True

    Úsubclassr   c                 ób   — | t           u r t          |dd ¦  «        }t          |¦  «        S t          S )Nr   )r   ÚgetattrÚcallableÚNotImplemented)Úclsr   r   s      r   Ú__subclasshook__z&_TransferableDataType.__subclasshook__F   s1   € àÕ'Ð'Ð'Ý˜ 4¨Ñ.Ô.ˆBÝ˜B‘<”<ÐÝÐr   N)	Ú__name__Ú
__module__Ú__qualname__Ú__doc__Úclassmethodr   r   Úboolr#   © r   r   r   r   2   sU   € € € € € ðð ð& ð¨ð °°d¸C°iÔ0@ð ð ð ñ „[ðð ð r   r   Úbatchc                 ó¬   ‡— t          ‰t          ¦  «        rt          j        ‰¦  «        Šdt          dt          fˆfd„}t          | t          |¬¦  «        S )ak  Transfers a collection of data to the given device. Any object that defines a method ``to(device)`` will be
    moved and all other objects in the collection will be left untouched.

    Args:
        batch: A tensor or collection of tensors or anything that has a method ``.to(...)``.
            See :func:`apply_to_collection` for a list of supported collection types.
        device: The device to which the data should be moved

    Return:
        the same collection but with all contained tensors residing on the new device.

    See Also:
        - :meth:`torch.Tensor.to`
        - :class:`torch.device`

    Údatar   c                 ó´   •— i }t          | t          ¦  «        r-t          ‰t          j        ¦  «        r‰j        t
          vrd|d<    | j        ‰fi |¤Ž}|�|S | S )NTÚnon_blocking)Ú
isinstancer
   r   r   ÚtypeÚ_BLOCKING_DEVICE_TYPESr   )r-   ÚkwargsÚdata_outputr   s      €r   Úbatch_toz%move_data_to_device.<locals>.batch_tob   sp   ø€ Øˆõ �d�FÑ#Ô#ð 	*­
°6½5¼<Ñ(HÔ(Hð 	*ÈVÌ[Õ`vÐMvÐMvØ%)ˆF�>Ñ"Ø�d”g˜fÐ/Ð/¨Ð/Ð/ˆØÐ"ØÐàˆr   )r   Úfunction)r0   Ústrr   r   r   r	   r   )r+   r   r5   s    ` r   Úmove_data_to_devicer8   N   sj   ø€ õ" �&�#ÑÔð &Ý”˜fÑ%Ô%ˆð
•sð 
�sð 
ð 
ð 
ð 
ð 
ð 
õ ˜uÕ,AÈHÐUÑUÔUÐUr   r-   c                 ób   — t           D ]\  }}t          | |||¬¦  «        } Œt          | |¦  «        S )N)r   )r   r	   r8   )r-   r   Ú	src_dtypeÚconversion_funcs       r   Úconvert_to_tensorsr<   q   s@   € å&7ð Tð TÑ"ˆ	�?Ý" 4¨°OÈFÐSÑSÔSˆˆÝ˜t VÑ,Ô,Ð,r   c                 ó‚   — dt           dt          t          t          t          f         fd„}t          | t           |¦  «        S )zíRecursively walk through a collection and convert single-item tensors to scalar values.

    Raises:
        ValueError:
            If tensors inside ``metrics`` contains multiple elements, hence preventing conversion to a scalar.

    r   r   c                 ó€   — |                       ¦   «         dk    rt          d| › d�¦  «        ‚|                      ¦   «         S )Né   zThe metric `zM` does not contain a single element, thus it cannot be converted to a scalar.)ÚnumelÚ
ValueErrorÚitem)r   s    r   Úto_itemz+convert_tensors_to_scalars.<locals>.to_item�   sE   € Ø�;Š;‰=Œ=˜AÒÐÝØs˜uÐsÐsÐsñô ð ð �zŠz‰|Œ|Ðr   )r
   r   ÚintÚfloatr)   r	   )r-   rC   s     r   Úconvert_tensors_to_scalarsrF   x   sD   € ð•vð ¥%­­UµDÐ(8Ô"9ð ð ð ð õ ˜t¥V¨WÑ5Ô5Ð5r   )%r'   Úabcr   Ú	functoolsr   Útypingr   r   r   r   r   Ú#lightning_utilities.core.apply_funcr	   r
   Ú"lightning_fabric.utilities.importsr   Ú lightning_fabric.utilities.typesr   ÚnumpyÚnpr2   r   r)   ÚtensorÚuint8rD   rE   r   ÚlistÚtupleÚ__annotations__ÚappendÚndarrayr   r8   r<   rF   r*   r   r   ú<module>rV      sW  ðð &Ð %Ð %à Ð Ð Ð Ð Ð Ø Ð Ð Ð Ð Ð Ø 6Ð 6Ð 6Ð 6Ð 6Ð 6Ð 6Ð 6Ð 6Ð 6Ð 6Ð 6à €€€Ø CÐ CÐ CÐ CÐ CÐ CØ Ð Ð Ð Ð Ð à ?Ð ?Ð ?Ð ?Ð ?Ð ?Ø 4Ð 4Ð 4Ð 4Ð 4Ð 4àð ØÐÐÐà'Ð ð.�|ð .¨Wð .¸ð .ð .ð .ð .ð 
ˆ7ˆ7�5”< u¤{Ð3Ñ3Ô3Ð4Øˆ'ˆ'�%”, e¤iÐ
0Ñ
0Ô
0Ð1Ø
ˆGˆG�E”L¨¬Ð4Ñ4Ô4Ð5ð	EÐ �4˜˜c 8¨S°#¨J¸Ð,>Ô#?Ð?Ô@ÔAð ð ñ ð ð 8ØÐÐÐà×Ò˜bœj¨+Ð6Ñ7Ô7Ð7ðð ð ð ð ˜Cñ ô ð ð8 V˜sð  V¨Gð  V¸ð  Vð  Vð  Vð  VðF-˜Sð -¨'ð -°cð -ð -ð -ð -ð6 Sð 6¨Sð 6ð 6ð 6ð 6ð 6ð 6r   