§
    .`ƒiê	  ã                   ób   — d dl Z ddlmZ ddlmZ dd„Zdde j        de j        d	e j        fd
„ZdS )é    Né   )Ú_masked_compaction)Ú	Bitmatrixéÿÿÿÿc                 ó:  — |j         \  }}t          j        | ¦  «        }t          j        |¦  «        }t          |t          ¦  «        r|j        j        }t          |f         | |||                     d¦  «        |                     d¦  «        ||||¬¦	  «	         ||fS )un  
    Return compacted copies of *yv* and *yi* based on a per-row bitmask.

    Only the elements whose index appears among the active bits of *bitmask*
    are kept; the rest are replaced by *sentinel*.  Kept elements preserve
    their original left-to-right order.

    Parameters
    ----------
    yv : torch.Tensor, shape (B, K)
        Values tensor.
    yi : torch.Tensor, shape (B, K), dtype torch.long
        Integer indices (0 â‰¤ index < 32) associated with *yv*.
    bitmask : torch.Tensor, shape (B,) **or** (B, 32)
        Per-row mask of active indices.  See the in-place version for details.
    sentinel : int, default -1
        Value written into dropped positions of the returned tensors.

    Returns
    -------
    (yv_out, yi_out) : Tuple[torch.Tensor, torch.Tensor], each shape (B, K)
        New tensors with the same dtype/device as the inputs.

    r   r   )ÚK)	ÚshapeÚtorchÚ
empty_likeÚ
isinstancer   ÚstorageÚdatar   Ústride)ÚyvÚyiÚbitmaskÚsentinelÚn_rowsÚn_colsÚret_yvÚret_yis           ú~/home/jaya/work/projects/VOICE-AGENT/VIET/agent-env/lib/python3.11/site-packages/vllm/third_party/triton_kernels/compaction.pyÚ
compactionr      s£   € ð4 ”XN€FˆFÝÔ˜bÑ!Ô!€FÝÔ˜bÑ!Ô!€FÝ'9Ñ%Ô%ð 'Ø”/Ô&ˆå˜zÔ"Ø
ˆB˜Ÿš¨Ñ*Ô*¨G¯NªN¸1Ñ,=Ô,=ØØØ
ð	ñ ô ð ð 6ˆ>Ðó    r   r   r   c                 ó$  — |j         \  }}|j        }dt          j        d||j        ¬¦  «        z  }|                     d¦  «        |z  dk    }|                     d¬¦  «        }	|	                     d|                     ¦   «         ¦  «        }
|
  	                    t          j
        ¦  «                             dd¬	¦  «        }|                     d|¦  «        }|                      d|¦  «        }|
                     d|¦  «        }||| <   ||| <   ||fS )
z6
    reference implementation of `masked_compact`
    r   é    )ÚdeviceÚdtyper   r   éþÿÿÿ)Ú	start_dimT)ÚdimÚstable)r	   r   r
   Úaranger   Ú	unsqueezeÚflattenÚgatherÚlongÚtoÚintÚargsort)r   r   r   r   ÚBr   r   ÚwÚbitsÚmaskÚkeepÚorderÚ	yi_sortedÚ	yv_sortedÚkeep_sorteds                  r   Úcompaction_torchr4   /   s  € ð Œ8D€A€qØŒY€Fà	
eŒl˜2 f°G´MÐBÑBÔBÑ	B€AØ×Ò˜bÑ!Ô! AÑ%¨!Ò+€DØ<Š< "ˆ<Ñ%Ô%€Dà;Š;q˜"Ÿ'š'™)œ)Ñ$Ô$€Dð ˆUJŠJ•u”yÑ!Ô!×)Ò)¨a¸Ð)Ñ=Ô=€Eà—	’	˜!˜UÑ#Ô#€IØ—	’	˜!˜UÑ#Ô#€Ià—+’+˜a Ñ'Ô'€KØ&€Iˆ{ˆlÑØ&€Iˆ{ˆlÑØiÐÐr   )r   )r
   Ú%compaction_details._masked_compactionr   Útensorr   r   ÚTensorr4   © r   r   ú<module>r9      s…   ðØ €€€Ø EÐ EÐ EÐ EÐ EÐ EØ Ð Ð Ð Ð Ð ð&ð &ð &ð &ðR ð  ˜œð  ¨5¬<ð  À%Ä,ð  ð  ð  ð  ð  ð  r   