
    x-j:                     >    d dl Z d dlmZmZ d dlZd dlZdZd Zd Z	dS )    N)MappingSequence_paddle_field_c                     fdt          | t                    sg } | g|g d          \  }}||d         fS g } | |g d          \  }}||fS )a%  
    For lod_blocking_queue only receive tensor array, flatten batch
    data, extract numpy.array data out as a list of numpy.array to
    send to lod_blocking_queue, and save the batch data structure
    such as fields in other types (str, int, etc) or key-value map
    of dictionaries
    c                 X   t          | t                    rM| D ]G}t          |t          j        t          j        t          j        j        j        j        f          r9|	                    t           |            |	                    |           |dz  }|t          |t          t          t          j        f          r|	                    |           t          |t                    r' ||g |          \  }}|	                    |           t          |t                    r( ||i |          \  }}|	                    |           2|	                    |           InCt          | t                    r|                                 D ]\  }}t          |t          j        t          j        t          j        j        j        j        f          r)t           | ||<   |	                    |           |dz  }nt          |t          t          t          j        f          r|||<   t          |t                    r ||g |          \  }}|||<   t          |t                    r ||i |          \  }}|||<   |||<   nt#          dt%          |                      ||fS )N   wrong flat data type: )
isinstancer   npndarraypaddleTensorbasecoreeagerappendFIELD_PREFIXstrbytesnumbersNumberr   items	TypeErrortype)batch
flat_batch	structure	field_idxfieldfield_structk_flattens          Y/var/www/html/banglarbhumi/venv/lib/python3.11/site-packages/paddle/io/dataloader/flat.pyr"   z _flatten_batch.<locals>._flatten"   s   eX&& /	D , ,Z0@0F0MN  , $$%Ai%A%ABBB%%e,,,NIIUGN'CDD ,$$U++++x00 ,.6hz2y/ /+L) $$\2222w// ,.6hz2y/ /+L) $$\2222$$U+++++,, w'' 	D!KKMM ) )5Z0@0F0MN  ) '3#?I#?#?IaL%%e,,,NIIUGN'CDD )#(IaLLx00 ).6hz2y/ /+L) $0IaLLw// ).6hz2y/ /+L) $0IaLL#(IaLL+). BT%[[BBCCC)##    r   )r
   r   )r   r   r   _r"   s       @r#   _flatten_batchr&      s    2$ 2$ 2$ 2$ 2$j eX&& (
xR;;	19Q<''J8E:r155LIqy  r$   c                 V     fdt           t                    s
J d            t                     dk    r|S t          |t          t          f          r$|t
           d k    sJ d|              d         S  |d          }|dz   t                     k    s
J d            |S )z
    After reading list of Tensor data from lod_blocking_queue outputs,
    use this function to restore the batch data structure, replace
    :attr:`_paddle_field_x` with data from flat_batch
    c                 ~   t          | t                    rt          |           D ]\  }}t          |t                    ru|                    t
                    r[t          |                    t
          d                    }t          ||          }|         
J d            |         | |<   d |<   t          |t          t          t          j        f          rt          |t          t          f          r | |         |          }n/t          | t                    r|                                 D ]\  }}t          |t                    ru|                    t
                    r[t          |                    t
          d                    }t          ||          }|         
J d            |         | |<   d |<   t          |t          t          t          j        f          rt          |t          t          f          r | |         |          }nt          dt          |                      |S )N z flat_batch[{}] parsed repeatedlyr	   )r
   r   	enumerater   
startswithr   intreplacemaxr   r   r   r   r   r   r   )r   r   ir   cur_field_idxr!   _restorer   s         r#   r1   z _restore_batch.<locals>._restoreg   sL   i** 	H%i00 B B5eS)) Be.>.>|.L.L B$'lB(G(G$H$HM #I} = =I%m4@@: A@@ $.m#<IaL04J}--UGN'CDD B'':;; B (1y A AIB 	7++ 	H%OO-- B B5eS)) Be.>.>|.L.L B$'lB(G(G$H$HM #I} = =I%m4@@: A@@ $.m#<IaL04J}--UGN'CDD B'':;; B (1y A AIB FT)__FFGGGr$   z!flat_batch is not a list or tupler   zinvalid structure: r   zTensor parse incomplete)r
   r   lenr   r   r   )r   r   r   r1   s   `  @r#   _restore_batchr3   `   s               D j(++PP-PPP+ :! )c5\** |0Q00000-)-- 100 !}A&&Iq=C
OO+++-F+++r$   )
r   collections.abcr   r   numpyr   r   r   r&   r3    r$   r#   <module>r7      sn     - - - - - - - -     D! D! D!N8 8 8 8 8r$   