Extract a diagonal from a 2-D matrix or construct a 2-D matrix from a 1-D diagonal vector.
Follows numpy.diag semantics:
- If
vis 1-D of length , output is 2-D of shape withvon diagonal and zeros elsewhere. - If
vis 2-D, output is 1-D containing entriesv[i, i + k]for valid .
Parameters
vTensorImplPtr1-D or 2-D input tensor.
kint64_tDiagonal index (
0 main, >0 above, <0 below).Returns
TensorImplPtr1-D or 2-D output (the opposite rank from v).
Raises
LucidErrorIf
v is neither 1-D nor 2-D.