Implementing kernel
C++ engine symbols that back this Python API.Return the indices of all non-zero (or True) elements.
The output is a 2-D int64 tensor of shape (N, input.ndim)
where N is the number of non-zero entries — each row is one
multi-index. With as_tuple=True it is one 1-D int64 tensor
per dim instead (a 0-d input counts as 1-D).
Parameters
inputTensorSource tensor.
as_tuplebool= FalseReturn the columns of the index matrix as a tuple.
Returns
Notes
Because the output size is data-dependent this op forces a CPU
round-trip on accelerator backends. For mask-style use cases
prefer where or masked_select.
Examples
>>> import lucid
>>> x = lucid.tensor([[0, 1], [2, 0]])
>>> lucid.nonzero(x)
Tensor([[0, 1],
[1, 0]])