
    QVji	                         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d	S )
    )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                     |dk    s
J d            t                                                       || _        || _        || _        || _        d S )Nr   z+Batch size is required to be larger than 0!)super__init__r   r   r   r   )selfr   r   r   r   	__class__s        a/root/voice-cloning/.venv/lib/python3.11/site-packages/torch/utils/data/datapipes/map/grouping.pyr   zBatcherMapDataPipe.__init__)   sR     A~~~L~~~ $"*    c                 p    g }t          | j        z  |dz    j        z            }	 |                     fd|D                                             |          S # t          $ rM} j        s-t          |          dk    r                     |          cY d }~S t	          d| d          |d }~ww xY w)N   c              3   2   K   | ]}j         |         V  d S )N)r   ).0ir   s     r   	<genexpr>z1BatcherMapDataPipe.__getitem__.<locals>.<genexpr>;   s*      ;;aq);;;;;;r   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O	KLL;;;;7;;;;;;%%e,,, 	K 	K 	K> Kc%jj1nn))%00000000 !B%!B!B!BCCJ		Ks#   5A 
B5(.B0B5B00B5c                    t          | j        t                    rJ| 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   s|    dmU++ 	Y~ U4=))T_<<DM**T_<q@T_TTtDzz2WWWXXXr   )r*   
__module____qualname____doc__r   __annotations__intboolr   r	   r)   r   r%   r+   __classcell__)r   s   @r   r   r      s          ( OOOOOO  )2+ +b/+ + 	+
 I+ 
+ + + + + +
KI 
K 
K 
K 
KY Y Y Y Y Y Y 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      s    ! ! ! ! ! !       E E E E E E F F F F F F F F  
  WT]] W:Y :Y :Y :Y :YY/ :Y :Y :Y :Y :Yr   