y=lab.diag(x) when x is of dimension 1 returns a diagonal matrix with diagonal elements constructed from x.

y=lab.diag(x) when x is of dimension 2 returns a tensor of dimension 1 with elements constructed from the diagonal of x.

y=lab.diag(x,k) returns the k-th diagonal of x, wher k=0 is the main diagonal, k>0 is above the main diagonal and k<0 is below the main diagonal.