Skip to main content

ClikaRT::ops::diagonal

function

diagonal()

Tensor diagonal(
    Tensor x,
    int64_t offset = 0,
    int64_t dim1 = 0,
    int64_t dim2 = 1
)

Extract the offset-th diagonal between dim1 and dim2: the two source dims are removed and a trailing dim of the diagonal's length is appended (rank - 1 total). Copies into fresh storage (deliberately not a view).

Throws

  • ClikaRT::Error: (INVALID_ARGUMENT) when dim1/dim2 collide or are out of range (code_name() carries the reason).

Returns: a new tensor of rank - 1 with the diagonal as its trailing dim.

Declared in ClikaRT/compute/ops.h, line 3139