
    i              
           d dl mZmZmZ d dlZddlmZ ddlmZ ddl	m
Z
mZ eZe
Z ej                  d      d dd	ed
edeeef   fd       Zdeeef   dededeeef   fdZ	 ddeeef   dee   dee   ddfdZy)    )CallableOptionalTupleN   )registry)Model)Floats2dInts2dz
uniqued.v1)columnlayerr   returnc          	      \    t        d| j                   dt        t        | gdddd|i      S )a  Group inputs to a layer, so that the layer only has to compute for the
    unique values. The data is transformed back before output, and the same
    transformation is applied for the gradient. Effectively, this is a cache
    local to each minibatch.
    zuniqued()N)nOnIr   )initlayersdimsattrs)r   nameforwardr   )r   r   s     e/var/www/vps2.regionflexible.com/Desarrollo/venv/lib/python3.12/site-packages/thinc/layers/uniqued.pyuniquedr      s<     
5::,a w%      modelXis_trainc                 X   | j                   d   }| j                  d   |j                  dk  r	 ||      S |d d |f   }t        |t        j
                        s|j                         }j                  j                  j                  |ddd      \  }}| j                  j                  dd      ||   } ||      \  }|   j                  |j                  d   f|j                  dd  z         }	t        |j                        dt        d	t        ffd
}
|	|
fS )Nr   r   r   T)return_indexreturn_inversereturn_counts   dYr   c                      j                   j                   }j                   j                  |j                   j                        |         |      }|z     S )N)opsalloc2fscatter_add	asarray_i)r$   dY_uniq	d_uniques	bp_Y_uniqcountsinvr   
uniq_shapes      r   backpropzforward.<locals>.backprop/   sX    #%))##Z0		guyy':':3'?Dg&	F"C((r   )r   r   size
isinstancenumpyndarraygetr&   xpunique	reshape2ireshapeshapetupleOutTInT)r   r   r   r   keys	uniq_keysindX_uniqY_uniqYr0   r,   r-   r.   r   r/   s              @@@@@r   r   r      s   ++h'FLLOEvvzQ!!QY<DdEMM*xxz"')),,"5"54D #6 #IsC YY  Q/FsVFfh/FIsQWWQZMFLL,<<=Av||$J)T )c ) ) h;r   rC   c                    | j                   d   }|j                  ||       |j                  d      r!| j                  d|j	                  d             |j                  d      r"| j                  d|j	                  d             y y )Nr   )r   rC   r   r   )r   
initializehas_dimset_dimget_dim)r   r   rC   r   s       r   r   r   9   so     LLOE	qA}}TdEMM$/0}}TdEMM$/0 r   )NN)typingr   r   r   r3   configr   r   r   typesr	   r
   r=   r<   r   intr   boolr   r    r   r   <module>rO      s    , ,    $ +, 5 S sDy1A   5d#  t dHn@U 8 KO1d1 (19A$1	1r   