Skip to content
fn

masked_select_op

→TensorImplPtr
int masked_select_op(const int & a, const int & mask)

Python wrappers

Public Python APIs implemented by this engine symbol.

Extract elements where a boolean mask is true.

Returns a 1-D tensor containing the elements of a at the positions where mask is true, in row-major (C) order. The output length is data-dependent.

Parameters

aTensorImplPtr
Source tensor.
maskTensorImplPtr
Boolean tensor broadcastable to a.

Returns

TensorImplPtr

1-D tensor of length equal to the number of true entries in mask; dtype matches a.

Notes

Because the output size depends on the values of mask, this op performs a CPU round-trip on the GPU stream to materialise the count before allocation. Non-differentiable in mask; the gradient w.r.t. a is a scatter into a zero tensor at the selected positions.