o
    wZh                     @   s   d dl Z d dlmZ d dlmZ d dlmZ d dlm	Z	m
Z
 g dZedG dd	 d	e
Zed
ddG dd de	ZedddG dd de	ZedddG dd de	ZedddG dd de	ZedddG dd de	ZdS )    N)Any)functional_datapipe)dataframe_wrapper)DFIterDataPipeIterDataPipe)ConcatDataFramesPipeDataFramesAsTuplesPipeExampleAggregateAsDataFramesFilterDataFramesPipePerRowDataFramesPipeShuffleDataFramesPipeZ_dataframes_as_tuplesc                   @      e Zd Zdd Zdd ZdS )r   c                 C   
   || _ d S Nsource_datapipeselfr    r   ]/var/www/auris/lib/python3.10/site-packages/torch/utils/data/datapipes/dataframe/datapipes.py__init__      
zDataFramesAsTuplesPipe.__init__c                 c   s"    | j D ]
}t|E d H  qd S r   )r   
df_wrapperZiterate)r   dfr   r   r   __iter__   s   
zDataFramesAsTuplesPipe.__iter__N__name__
__module____qualname__r   r   r   r   r   r   r          r   Z_dataframes_per_rowT)Zenable_df_api_tracingc                   @   r   )r   c                 C   r   r   r   r   r   r   r   r   !   r   zPerRowDataFramesPipe.__init__c                 c   s6    | j D ]}tt|D ]}|||d  V  qqd S N   )r   rangelen)r   r   ir   r   r   r   $   s   
zPerRowDataFramesPipe.__iter__Nr   r   r   r   r   r      r   r   Z_dataframes_concatc                   @   s   e Zd ZdddZdd ZdS )r      c                 C      || _ || _d S r   )r   n_batch)r   r   batchr   r   r   r   -      
zConcatDataFramesPipe.__init__c                 c   sV    g }| j D ]}|| t|| jkrt|V  g }qt|r)t|V  d S d S r   )r   appendr#   r'   r   concat)r   bufferr   r   r   r   r   1   s   

zConcatDataFramesPipe.__iter__N)r%   r   r   r   r   r   r   +   s    
r   Z_dataframes_shufflec                   @   r   )r   c                 C   r   r   r   r   r   r   r   r   >   r   zShuffleDataFramesPipe.__init__c                 #   s    d }g }| j D ] |d u rt }| fddtt D  qt| g }|D ] |  t||krCt	|V  g }q.t|rPt	|V  d S d S )Nc                 3   s    | ]	}t  |V  qd S r   )r   Zget_item).0r$   r   r   r   	<genexpr>G   s    
z1ShuffleDataFramesPipe.__iter__.<locals>.<genexpr>)
r   r   Zget_lenextendr"   randomshuffler*   r#   r+   )r   size
all_bufferr,   r   r.   r   r   A   s(   




zShuffleDataFramesPipe.__iter__Nr   r   r   r   r   r   <   r   r   Z_dataframes_filterc                   @   r   )r
   c                 C   r&   r   )r   	filter_fn)r   r   r5   r   r   r   r   W   r)   zFilterDataFramesPipe.__init__c                 c   s    d }g }g }| j D ]+}|d u rt|j}tt|jD ]}||||d   || |j|  qq
g }t||D ]\}}|rV|| t||krVt	|V  g }q=t|rct	|V  d S d S r    )
r   r#   indexr"   r*   r5   Ziloczipr   r+   )r   r3   r4   Z
filter_resr   r$   r,   resr   r   r   r   [   s,   


zFilterDataFramesPipe.__iter__Nr   r   r   r   r   r
   U   s    r
   Z_to_dataframes_pipec                   @   s&   e Zd Zd	ddZdd Zdd ZdS )
r	   
   Nc                 C   s   || _ || _|| _d S r   )r   columnsdataframe_size)r   r   r;   r:   r   r   r   r   s   s   
z%ExampleAggregateAsDataFrames.__init__c                 C   s$   zt |W S  ty   |g Y S w r   )list	Exception)r   itemr   r   r   _as_listx   s   

z%ExampleAggregateAsDataFrames._as_listc                 c   sl    g }| j D ]}|| | t|| jkr"tj|| jdV  g }qt|dkr4tj|| jdV  d S d S )N)r:   r   )r   r*   r?   r#   r;   r   Zcreate_dataframer:   )r   Z	aggregater>   r   r   r   r      s   
z%ExampleAggregateAsDataFrames.__iter__)r9   N)r   r   r   r   r?   r   r   r   r   r   r	   q   s    
r	   )r1   typingr   Z%torch.utils.data.datapipes._decoratorr   Z$torch.utils.data.datapipes.dataframer   r   Z#torch.utils.data.datapipes.datapiper   r   __all__r   r   r   r   r
   r	   r   r   r   r   <module>   s$   






