
    *`i
                         d Z ddlmZmZmZ ddlZddlmZ 	 	 ddej        dej        dee	         d	eeee	         ej        f                  d
df
dZ
dS )z4CPU implementation for in-place applying token mask.    )ListOptionalUnionN   )_corelogitsbitmask
vocab_sizeindicesreturnc                 6   | j         j        dk    rt          d          |j         j        dk    rt          d          |j        t          j        k    rt          d          |                                 dk    rL|                                 dk    r4t          d                    |                                                     |                                dk    rL|                                dk    r4t          d                    |                                                    |                                 dk    rd| j        d	         fn| j        d	         | j        d         f}| 	                                }|                                 dk    r
|d	         dfn|d	         |d         f}|                                dk    rd|j        d	         fn|j        d	         |j        d         f}|	                                }|                                dk    r
|d	         dfn|d	         |d         f}|)t          | j        d         |j        d         dz            n|}| j        t          j        k    rMt          j                            |                                 |||                                ||||d	  	         d
S | j        t          j        k    rMt          j                            |                                 |||                                ||||d	  	         d
S | j        t          j        k    rMt          j                            |                                 |||                                ||||d	  	         d
S t          d          )z$Apply token bitmask in-place on CPU.cpuzlogits must be on CPUzbitmask must be on CPUzbitmask must be of type int32   r   z&logits should be 1D or 2D, but got {}Dz'bitmask should be 1D or 2D, but got {}Dr   N    float32bfloat16float16z2logits must be of type float32 or bfloat16/float16)devicetype
ValueErrordtypetorchint32dimformatshapestrideminr   r   kernelsapply_token_bitmask_inplace_cpudata_ptrr   r   )r   r	   r
   r   logits_shapelogits_stridebitmask_shapebitmask_strides           /home/jaya/work/projects/VOICE-AGENT/VIET/agent-env/lib/python3.11/site-packages/xgrammar/kernels/apply_token_bitmask_inplace_cpu.pyr!   r!   
   st    }U""0111~e##1222}##8999zz||qVZZ\\Q..AHHVVWWW{{}}gkkmmq00BII'++--XXYYY+1::<<1+<+<Av|A''6<PQ?TZT`abTcBdLMMOOM!'!2!2q	1q9I=YZK[8\ 
 ")!!3!3GM!'-:JGMZ[L\9]  ^^%%N")++--1"4"4	A>!;Ln]^N_:`  CMBTV\"%w}R'82'=>>>ZdJ|u}$$55OO
	
 
	
 
	
 
	
 
	
 
	'	'55OO
	
 
	
 
	
 
	
 
	
 
	&	&55OO
	
 
	
 
	
 
	
 
	
 MNNN    )NN)__doc__typingr   r   r   r   baser   Tensorintr!    r(   r'   <module>r/      s    : : ( ( ( ( ( ( ( ( ( (        !%8<	GO GOLGO\GO GO eDIu|345	GO
 
GO GO GO GO GO GOr(   