Skip to content
fn

trace

→Tensor
trace(input: Tensor)

Implementing kernel

C++ engine symbols that back this Python API.

Sum of the main diagonal of a 2-D tensor.

Parameters

inputTensor
A 2-D tensor; it need not be square.

Returns

Tensor

0-d tensor holding ∑iinput[i,i]\sum_i \text{input}[i, i].

Examples

>>> import lucid
>>> lucid.trace(lucid.tensor([[1.0, 2.0], [3.0, 4.0]]))
tensor(5.)