vt::diag#

template<typename T>
Tensor<T, 2> vt::diag(Tensor<T, 1> tensor, int k = 0)#

Generate a 2D tensor with its diagonal filled by a tensor.

Template Parameters:

T – Data type of the tensor.

Parameters:
  • tensor – 1D diagnaoal tensor.

  • k – Index of diagonals.

Returns:

Tensor<T, 2>: The result tensor.

template<typename T>
Tensor<T, 1> vt::diag(Tensor<T, 2> tensor, int k = 0)#

Get the diagonal of a 2D tensor.

Template Parameters:

T – Data type of the tensor.

Parameters:
  • tensor – The input tensor.

  • k – Index of diagonals.

Returns:

Tensor<T, 1>: The result tensor.