torch.masked_select
Returns a 1D tensor containing elements from input where mask is True.
Note: Due to WebGPU limitations, this returns a tensor with shape [inputSize] (the maximum possible size). The actual selected elements are packed at the beginning. Use masked_select_async() to get a tensor with exact shape.
Parameters
Returns
Tensor– A 1D tensor with selected elements (may have trailing garbage on WebGPU)Examples
const x = torch.tensor([1, 2, 3, 4]);
const mask = torch.tensor([true, false, true, false]);
torch.masked_select(x, mask); // [1, 3] (plus trailing elements on WebGPU)