o
    ?e                     @   s|   d Z ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddl	m
Z ddlmZ 				dd
dZG dd dejZd	S )z0The implementation of `tf.data.Dataset.shuffle`.    )dataset_ops)structured_function)nest)	structure)ops)gen_experimental_dataset_ops)collections_abcNc                 C   s   t | ||||dS )N)name)_ScanDataset)input_datasetinitial_state	scan_funcuse_default_devicer	    r   c/home/www/facesmatcher.com/pyenv/lib/python3.10/site-packages/tensorflow/python/data/ops/scan_op.py_scan   s   
r   c                       sB   e Zd ZdZ		d fdd	Zdd Zedd Zd	d
 Z  Z	S )r
   z1A dataset that scans a function across its input.Nc                    s  || _ t|| _t| j| _d}|rtj||  | j|j	fdd}t
|jtjr1t|jdks:td|j d|j\}| _|j\}}	tdd | j}
tt|t|
D ]\}}t||smtd	|
 d
| dqY|j\}}tdd | j}tt|t|D ]\}}||krtd| d
| dq|j\}}tdd | j}t|||	| _t|}t|}dd t||D }d}t||D ]\}}|jdur|jdu s| | krd} qq|rt|t|||
| _|s|| _| jj t!"  || _#|dur)t$j%| j j&t'| j| j| jjj(f| jjd|d| j)}nt$j%| j j&t'| j| j| jjj(f| jjdd| j)}t* +|| dS )zSee `scan()` for details.TF)Zinput_structureadd_to_graph   zzInvalid `scan_func`. `scan_func` should return a pair consisting of new state and the output value but its return type is .c                 S      |   S N)Z_to_legacy_output_classesZcomponent_specr   r   r   <lambda>J       z'_ScanDataset.__init__.<locals>.<lambda>zbInvalid `scan_func`. The element classes for the new state must match the initial state. Expected z, got c                 S   r   r   )Z_to_legacy_output_typesr   r   r   r   r   V   r   z`Invalid `scan_func`. The element types for the new state must match the initial state. Expected c                 S   r   r   )Z_to_legacy_output_shapesr   r   r   r   r   b   r   c                 S   s   g | ]	\}}| |qS r   )Zmost_specific_compatible_shape).0originalnewr   r   r   
<listcomp>i   s    z)_ScanDataset.__init__.<locals>.<listcomp>N)fpreserve_cardinalityr   )r   r   ),Z_input_datasetr   Znormalize_elementZ_initial_stateZtype_spec_from_valueZ_state_structurer   ZStructuredFunctionWrapper_transformation_nameelement_spec
isinstanceoutput_typesr   Sequencelen	TypeErrorZoutput_structureoutput_classesZ_output_classesr   Zmap_structurezipflatten
issubclassoutput_shapesZconvert_legacy_structure_element_specZndimsas_listZpack_sequence_as
_scan_funcfunctionr   r   Zget_default_graph_nameged_opsZscan_datasetZ_variant_tensorZto_tensor_listZcaptured_inputsZ_common_argssuper__init__)selfr   r   r   r   r	   Zneed_to_rerunZwrapped_funcZnew_state_classesr'   Zold_state_classesZnew_state_classZold_state_classZnew_state_typesr#   Zold_state_typesZnew_state_typeZold_state_typeZnew_state_shapesr+   Zold_state_shapesZflat_state_shapesZflat_new_state_shapesZweakened_state_shapesZoriginal_shapeZweakened_shapeZvariant_tensor	__class__r   r   r3   %   s   











I
	z_ScanDataset.__init__c                 C   s   | j gS r   )r.   r4   r   r   r   
_functions   s   z_ScanDataset._functionsc                 C   s   | j S r   )r,   r7   r   r   r   r!      s   z_ScanDataset.element_specc                 C   s   dS )NzDataset.scan()r   r7   r   r   r   r       s   z!_ScanDataset._transformation_nameNN)
__name__
__module____qualname____doc__r3   r8   propertyr!   r    __classcell__r   r   r5   r   r
   "   s    s
r
   r9   )r=   Ztensorflow.python.data.opsr   r   Ztensorflow.python.data.utilr   r   Ztensorflow.python.frameworkr   Ztensorflow.python.opsr   r1   Ztensorflow.python.util.compatr   r   ZUnaryDatasetr
   r   r   r   r   <module>   s   
	