
    BVh                         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
Z G d dej                        Zy	)z0The implementation of `tf.data.Dataset.shuffle`.    )dataset_ops)structured_function)nest)	structure)ops)gen_experimental_dataset_ops)collections_abcNc                 "    t        | ||||      S )N)name)_ScanDataset)input_datasetinitial_state	scan_funcuse_default_devicer   s        R/home/dcms/DCMS/lib/python3.12/site-packages/tensorflow/python/data/ops/scan_op.py_scanr      s    
 
]I/A
N N    c                   D     e Zd ZdZ	 	 d fd	Zd Zed        Zd Z xZ	S )r   z1A dataset that scans a function across its input.c                 \	   || _         t        j                  |      | _        t        j                  | j                        | _        d}|rt        j                  || j                         | j
                  |j                  fd      }t        |j                  t        j                        rt        |j                        dk(  st        d|j                    d      |j"                  \  }| _        |j"                  \  }}	t'        j(                  d | j
                        }
t+        t'        j,                  |      t'        j,                  |
            D ]#  \  }}t/        ||      rt        d|
 d	| d       |j                  \  }}t'        j(                  d
 | j
                        }t+        t'        j,                  |      t'        j,                  |            D ]  \  }}||k7  st        d| d	| d       |j0                  \  }}t'        j(                  d | j
                        }t        j2                  |||	      | _        t'        j,                  |      }t'        j,                  |      }t+        ||      D cg c]  \  }}|j7                  |       }}}d}t+        ||      D ]C  \  }}|j8                  |j8                  "|j;                         |j;                         k7  sAd} n |r0t        j2                  |t'        j<                  ||      |
      | _        |r| _        | j>                  j@                  jC                  tE        jF                                || _$        |tK        jL                  | j                   jN                  t        jP                  | j
                  | j                        | j>                  j@                  jR                  f| j>                  j@                  d|d| jT                  }ntK        jL                  | j                   jN                  t        jP                  | j
                  | j                        | j>                  j@                  jR                  f| j>                  j@                  dd| jT                  }tV        |   ||       yc c}}w )zSee `scan()` for details.TF)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                 "    | j                         S N)_to_legacy_output_classescomponent_specs    r   <lambda>z'_ScanDataset.__init__.<locals>.<lambda>J   s    !I!I!K r   zbInvalid `scan_func`. The element classes for the new state must match the initial state. Expected z, got c                 "    | j                         S r   )_to_legacy_output_typesr   s    r   r   z'_ScanDataset.__init__.<locals>.<lambda>V   s    !G!G!I r   z`Invalid `scan_func`. The element types for the new state must match the initial state. Expected c                 "    | j                         S r   )_to_legacy_output_shapesr   s    r   r   z'_ScanDataset.__init__.<locals>.<lambda>b   s    !H!H!J r   N)fpreserve_cardinalityr   )r$   r%   )-_input_datasetr   normalize_element_initial_statetype_spec_from_value_state_structurer   StructuredFunctionWrapper_transformation_nameelement_spec
isinstanceoutput_typesr	   Sequencelen	TypeErroroutput_structureoutput_classes_output_classesr   map_structurezipflatten
issubclassoutput_shapesconvert_legacy_structure_element_specmost_specific_compatible_shapendimsas_listpack_sequence_as
_scan_funcfunctionr   r   get_default_graph_nameged_opsscan_dataset_variant_tensorto_tensor_listcaptured_inputs_common_argssuper__init__)selfr   r   r   r   r   need_to_rerunwrapped_funcnew_state_classesr4   old_state_classesnew_state_classold_state_classnew_state_typesr/   old_state_typesnew_state_typeold_state_typenew_state_shapesr:   old_state_shapesflat_state_shapesflat_new_state_shapesoriginalnewweakened_state_shapesoriginal_shapeweakened_shapevariant_tensor	__class__s                                r   rL   z_ScanDataset.__init__%   s    (D#55mDD
 &::4;N;NOD M
(BB


#
#
%00-2L2LM	l
 22O4L4LMl//0A5 2 (889< = 	=
 1=0K0K-- +7*E*E',,
K


! /2
,,(
)4<<8I+J/L L
*/?/?; N./v6G5HK L LL '3&?&?#o|**
I


!o -0
,,
'o)F-H H
(..^+ N,-VO3DAG H HH )5(B(B%++
J


! %==
~7d ,,'78"ll+;<  ##46KLh 
1
1#
6 
 m,/0A0E-G 
(..+  (""$(>(>(@@-
 
 !* B B!!"24IJ!I R #DOOO))#*?*?*ABDJ%++



-
-

"
"4#8#8$:M:M
N
//
"
"
2
2 OO$$#/ n ++



-
-

"
"4#8#8$:M:M
N
//
"
"
2
2 OO$$# n 
G]N3[s    R(c                     | j                   gS r   )rA   rM   s    r   
_functionsz_ScanDataset._functions   s    OOr   c                     | j                   S r   )r<   rd   s    r   r-   z_ScanDataset.element_spec   s    r   c                      y)NzDataset.scan() rd   s    r   r,   z!_ScanDataset._transformation_name   s    r   NN)
__name__
__module____qualname____doc__rL   re   propertyr-   r,   __classcell__)rb   s   @r   r   r   "   s3    9 #'q4f  r   r   ri   )rm   tensorflow.python.data.opsr   r   tensorflow.python.data.utilr   r   tensorflow.python.frameworkr   tensorflow.python.opsr   rE   tensorflow.python.util.compatr	   r   UnaryDatasetr   rh   r   r   <module>rv      sA    7 2 : , 1 + I 9 "	N~;++ ~r   