Ë
    Q/æj›	  ã                   ó€   — d dl mZmZmZmZ d dlmZ d dlmZm	Z	 dgZ
 ed«      Z ed«       G d„ de	e   «      «       Zy)	é    )ÚListÚSizedÚTypeÚTypeVar)Úfunctional_datapipe)Ú	DataChunkÚMapDataPipeÚBatcherMapDataPipeÚ_TÚbatchc                   ó‚   ‡ — e Zd ZU dZeed<   eed<   eed<   defdee	   dedede
e   ddf
ˆ fd	„Zdefd
„Zdefd„Zˆ xZS )r
   a´  
    Create mini-batches of data (functional name: ``batch``).

    An outer dimension will be added as ``batch_size`` if ``drop_last`` is set to ``True``,
    or ``length % batch_size`` for the last batch if ``drop_last`` is set to ``False``.

    Args:
        datapipe: Iterable DataPipe being batched
        batch_size: The size of each batch
        drop_last: Option to drop the last batch if it's not full

    Example:
        >>> # xdoctest: +SKIP
        >>> from torchdata.datapipes.map import SequenceWrapper
        >>> dp = SequenceWrapper(range(10))
        >>> batch_dp = dp.batch(batch_size=2)
        >>> list(batch_dp)
        [[0, 1], [2, 3], [4, 5], [6, 7], [8, 9]]
    ÚdatapipeÚ
batch_sizeÚ	drop_lastFÚwrapper_classÚreturnNc                 ór   •— |dkD  sJ d«       ‚t         ‰| �  «        || _        || _        || _        || _        y )Nr   z+Batch size is required to be larger than 0!)ÚsuperÚ__init__r   r   r   r   )Úselfr   r   r   r   Ú	__class__s        €új/root/repos/pocs/video-evals/.venv/lib/python3.12/site-packages/torch/utils/data/datapipes/map/grouping.pyr   zBatcherMapDataPipe.__init__(   s?   ø€ ð ˜AŠ~ÐLÐLÓLˆ~Ü‰ÑÔØ ˆŒØ$ˆŒØ"ˆŒØ*ˆÕó    c                 óh  — g }t        || j                  z  |dz   | j                  z  «      }	 |D ]   }|j                  | j                  |   «       Œ" | j	                  |«      S # t
        $ rE}| j                  s$t        |«      dkD  r| j	                  |«      cY d }~S t        d|› d�«      |‚d }~ww xY w)Né   r   zIndex z is out of bound.)Úranger   Úappendr   r   Ú
IndexErrorr   Úlen)r   Úindexr   ÚindicesÚiÚes         r   Ú__getitem__zBatcherMapDataPipe.__getitem__6   s¯   € ØˆÜ˜ §¡Ñ/°%¸!±)¸t¿¹Ñ1NÓOˆð	KØò /�Ø—‘˜TŸ]™]¨1Ñ-Õ.ð/à×%Ñ% eÓ,Ð,øÜò 	KØ—>’>¤c¨%£j°1¢nØ×)Ñ)¨%Ó0Õ0ä  6¨%¨Ð0AÐ!BÓCÈÐJûð		Kús#   ­5A# Á#	B1Á,*B,ÂB1ÂB,Â,B1c                 ó8  — t        | j                  t        «      r`| j                  r"t	        | j                  «      | j
                  z  S t	        | j                  «      | j
                  z   dz
  | j
                  z  S t        t        | «      j                  › d�«      ‚)Nr   z# instance doesn't have valid length)	Ú
isinstancer   r   r   r   r   Ú	TypeErrorÚtypeÚ__name__)r   s    r   Ú__len__zBatcherMapDataPipe.__len__C   ss   € Ü�d—m‘m¤UÔ+Ø�~Š~Ü˜4Ÿ=™=Ó)¨T¯_©_Ñ<Ð<ä˜DŸM™MÓ*¨T¯_©_Ñ<¸qÑ@ÀTÇ_Á_ÑTÐTäœt D›z×2Ñ2Ð3Ð3VÐWÓXÐXr   )r)   Ú
__module__Ú__qualname__Ú__doc__r	   Ú__annotations__ÚintÚboolr   r   r   r   r$   r*   Ú__classcell__)r   s   @r   r
   r
      s{   ø… ñð( ÓØƒOØƒOð  Ø)2ñ+à˜b‘/ð+ð ð+ð ð	+ð
 ˜I‘ð+ð 
õ+ðK Ió KðY˜÷ Yr   N)Útypingr   r   r   r   Ú%torch.utils.data.datapipes._decoratorr   Ú#torch.utils.data.datapipes.datapiper   r	   Ú__all__r   r
   © r   r   ú<module>r7      sN   ðç -Ó -å Eß Fð  Ð
 €ñ ˆTƒ]€ñ �WÓô;Y˜ YÑ/ó ;Yó ñ;Yr   