Skip to main content

ClikaRT::ops::diag

function

diag()

Tensor diag(Tensor x, int64_t diagonal = 0)

Rank-1 <-> rank-2 diagonal converter.

A vector of length L becomes an (L + |diagonal|) x (L + |diagonal|) matrix carrying it on the chosen diagonal (zeros elsewhere); a matrix input reads the chosen diagonal back out as a vector. diagonal: 0 = main, +k above, -k below. Copies.

Throws

  • ClikaRT::Error: (INVALID_ARGUMENT) when the input is not rank-1 or rank-2 (code_name() carries the reason).

Returns: a new matrix (rank-1 input) or vector (rank-2 input).

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