
    h              
           S SK JrJrJr  S SKJrJr  S SKJrJ	r	  SSK
Jr  S\\\	\	4   \	4   4S jrSS	 jrS
\S\\	\	4   S\S\\	\4   4S jrS\	S\S\4S jrS\	S\S\\	\4   4S jrg)    )CallableListTuple)Modelto_numpy)Ints1dRagged   )registryreturnc            
      0    [        S[        / 0 0 0 [        S9$ )zExtract spans from a sequence of source arrays, as specified by an array
of (start, end) indices. The output is a ragged array of the
extracted spans.
extract_spans)layersrefsattrsdimsinit)r   forwardr        P/home/james-whalen/.local/lib/python3.13/site-packages/spacy/ml/extract_spans.pyr   r   	   s     
 "BRd r   Nc                     g Nr   )modelXYs      r   r   r      s    r   r   source_spansis_trainc                   ^^^^	^
 U R                   mUu  nmTR                  R                  S:X  d   e[        TTUR                  5      m[        T5      S:  a?  [        UR                  T   TR                  SS2S4   TR                  SS2S4   -
  5      nOx[        TR                  R                  UR                  R                  UR                  R                  S9TR                  R                  [        UR                  5      4SS95      nUR                  R                  m
UR                  m	S[        S[        [        [        4   4UUUU	U
4S	 jjnXE4$ )
z%Get subsequences from source vectors.r
   r   N   )dtypeidYr   c                    > [        TR                  " T6 T5      nTR                  UR                  TU R                  5        UT4$ r   )r	   alloc2fscatter_adddataXd)r#   dXindicesopsspans	x_lengthsx_shapes     r   backprop_windows!forward.<locals>.backprop_windows)   s:    CKK)95		7BII6E{r   )r*   r'   ndim_get_span_indiceslengthslenr	   xpzerosshaper!   r   )r   r   r   r   r   r.   r)   r*   r+   r,   r-   s         @@@@@r   r   r      s    ))CHAu<<!!!UAII6G
7|a188G$ell1a4&85<<1;M&MNFFLLqxx~~L>FFLL#aii.*#L6
 hhnnG		IV ffn(=  
 r   r+   r2   c           
         [        X5      u  p/ nSn[        U5       H\  u  pVX   R                  U-   n[        UR                  S   5       H&  nUR                  [        XxS4   XxS4   5      5        M(     XF-  nM^     U R                  U5      $ )zConstruct a flat array that has the indices we want to extract from the
source data. For instance, if we want the spans (5, 9), (8, 10) the
indices will be [5, 6, 7, 8, 8, 9].
r   r    )_ensure_cpu	enumerater'   ranger6   extend	asarray1i)	r*   r+   r2   r)   offsetr"   lengthspans_ijs	            r   r1   r1   1   s    
 !0NEGFw'	(//F*w}}Q'(ANN5A1>? )	 (
 ==!!r   c                 |    [        [        U R                  5      [        U R                  5      5      [        U5      4$ r   )r	   r   r'   r2   )r+   r2   s     r   r8   r8   A   s+    (5<<((5==*ABHWDUUUr   )NN)typingr   r   r   	thinc.apir   r   thinc.typesr   r	   utilr   r   r   boolr   r1   r8   r   r   r   <module>rG      s    ( ( % & uU66>2F:; 	 %ffn 5AE
684"& "6 "f " Vv V V53H Vr   