Ë
    Z^(h™	  ã                   ó€   — d dl mZ d dl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	)
é    )ÚSized)Ú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        €úe/var/www/skyplay_api_hub/venv/lib/python3.12/site-packages/torch/utils/data/datapipes/map/grouping.pyr   zBatcherMapDataPipe.__init__)   s?   ø€ ð ˜AŠ~ÐLÐLÓLˆ~Ü‰ÑÔØ ˆŒØ$ˆŒØ"ˆŒØ*ˆÕó    c                 óT  ‡ — g }t        |‰ j                  z  |dz   ‰ j                  z  «      }	 |j                  ˆ fd„|D «       «       ‰ 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é   c              3   ó<   •K  — | ]  }‰j                   |   –— Œ y ­w)N)r   )Ú.0Úir   s     €r   ú	<genexpr>z1BatcherMapDataPipe.__getitem__.<locals>.<genexpr>;   s   øè ø€ Ò;¨a˜Ÿ™ qÕ)Ñ;ùs   ƒr   zIndex z is out of bound.)Úranger   Úextendr   Ú
IndexErrorr   Úlen)r   Úindexr
   ÚindicesÚes   `    r   Ú__getitem__zBatcherMapDataPipe.__getitem__7   sž   ø€ ØˆÜ˜ §¡Ñ/°%¸!±)¸t¿¹Ñ1NÓOˆð	KØ�L‰LÓ;°7Ô;Ô;Ø×%Ñ% eÓ,Ð,øÜò 	KØ—>’>¤c¨%£j°1¢nØ×)Ñ)¨%Ó0Õ0ä  6¨%¨Ð0AÐ!BÓCÈÐJûð		Kús#   ®*A Á	B'Á"*B"ÂB'ÂB"Â"B'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)Úcollections.abcr   Útypingr   Ú%torch.utils.data.datapipes._decoratorr   Ú#torch.utils.data.datapipes.datapiper   r   Ú__all__r	   r   © r   r   ú<module>r9      sN   ðå !Ý å Eß Fð  Ð
 €ñ ˆTƒ]€ñ �WÓô:Y˜ YÑ/ó :Yó ñ:Yr   