o
    i                  	   @   s   d dl mZmZmZmZ ddlmZ ddlmZ edZ	eZ
eddee	ef dee	ef d	ee	ef fd
dZdd Z	ddee	e
f dee	 dee
 d	dfddZdS )    )AnyOptionalTupleTypeVar   )registry)ModelInTz
tuplify.v1layer1layer2returnc                 G   s>   | |f| }dd |D }t dd| d tt|ddidS )	zSend a separate copy of the input to each child layer, and join the
    outputs of the children into a tuple on the way out.

    Typically used to provide both modified data and the original input to a
    downstream layer.
    c                 S   s   g | ]}|j qS  )name).0layerr   r   H/home/ubuntu/.local/lib/python3.10/site-packages/thinc/layers/tuplify.py
<listcomp>   s    ztuplify.<locals>.<listcomp>ztuple(z, )nIN)initlayersdims)r   jointuplify_forwardr   )r
   r   r   namesr   r   r   tuplify
   s   r   c                    sN   g }g  | j D ]}|||\}}||  | q fdd}t||fS )Nc                    s:   dd t  | D }|d }|dd  D ]}||7 }q|S )Nc                 S   s   g | ]\}}||qS r   r   )r   bpdYr   r   r   r   )   s    z=tuplify_forward.<locals>.backprop_tuplify.<locals>.<listcomp>r      )zip)dYsdXsdXdx	backpropsr   r   backprop_tuplify(   s
   
z)tuplify_forward.<locals>.backprop_tuplify)r   appendtuple)modelXis_trainYsr   Ybackpropr&   r   r$   r   r       s   

r   Nr)   r*   r-   c                 C   s   |d u r&|d u r&| j D ]}|  q| j d dr&| d| j d d t| j D ]\}}|d urD|dd u rD|j||| d q+|j|d q+| j d dra| d| j d d d S d S )Nr   r   nO)r*   r-   )r*   )r   
initializehas_dimset_dimget_dim	enumerate)r)   r*   r-   r   iir   r   r   r   2   s   

r   )NN)typingr   r   r   r   configr   r)   r   r	   OutTr   r   r   r   r   r   r   r   <module>   s0    



