
    h              
          S SK JrJrJr  S SKrSSKJr  SSKJr  SSK	J
r
Jr  \r\
r\R                  " S5      S S.S	\S
\S\\\4   4S jj5       rS\\\4   S\S\S\\\4   4S jr SS\\\4   S\\   S\\   SS4S jjrg)    )CallableOptionalTupleN   )registry)Model)Floats2dInts2dz
uniqued.v1)columnlayerr   returnc          	      V    [        SU R                   S3[        [        U /SSS.SU0S9$ )zGroup 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     N/home/james-whalen/.local/lib/python3.13/site-packages/thinc/layers/uniqued.pyuniquedr      s<     
5::,a w%      modelXis_trainc                 X  ^^^^^ U R                   S   nU R                  S   mUR                  S:  a  T" X5      $ US S 2U4   n[        U[        R
                  5      (       d  UR                  5       nTR                  R                  R                  USSSS9u  pVmmU R                  R                  TSS5      mX   nT" Xr5      u  nmUT   R                  UR                  S   4UR                  SS  -   5      n	[        UR                  5      mS[        S	[        4UUUUU4S
 jjn
X4$ )Nr   r   r   T)return_indexreturn_inversereturn_counts   dYr   c                    > TR                   R                  " T6 nTR                   R                  UTR                   R                  T5      U 5        T" U5      nUT-  T   $ )N)opsalloc2fscatter_add	asarray_i)r$   dY_uniq	d_uniques	bp_Y_uniqcountsinvr   
uniq_shapes      r   backpropforward.<locals>.backprop/   sV    ))##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 #IC YY  Q/FVFf/FIsQWWQZMFLL,<<=Av||$J)T )c ) ) ;r   rD   c                    U R                   S   nUR                  XS9  UR                  S5      (       a!  U R                  SUR	                  S5      5        UR                  S5      (       a"  U R                  SUR	                  S5      5        g g )Nr   )r   rD   r   r   )r   
initializehas_dimset_dimget_dim)r   r   rD   r   s       r   r   r   9   ss     LLOE	q}}TdEMM$/0}}TdEMM$/0 r   )NN)typingr   r   r   r4   configr   r   r   typesr	   r
   r>   r=   r   intr   boolr   r    r   r   <module>rP      s    , ,    $ 
+, 5 S sDy1A   5d#  t dHn@U 8 KO1d1 (19A$1	1r   