code: def from_vector_to_diagonal_matrix(vector, num_diag=0):
      """Create diagonal matrices from rows of a matrix.
  
      Parameters
      ----------
      vector : array-like, shape=[m, n]
      num_diag : int
          number of diagonal in result matrix. If 0, the result matrix is a
          diagonal matrix; if positive, the result matrix has an upper-right
          non-zero diagonal; if negative, the result matrix has a lower-left
          non-zero diagonal.
          Optional, Default: 0.
  
      Returns
      -------
      diagonals : array-like, shape=[m, n, n]
          3-dimensional array where the `i`-th n-by-n array `diagonals[i, :, :]`
          is a diagonal matrix containing the `i`-th row of `vector`.
      """
      num_columns = gs.shape(vector)[-1]
      identity = gs.eye(num_columns)
      identity = gs.cast(identity, vector.dtype)
      diagonals = gs.einsum("...i,ij->...ij", vector, identity)
      diagonals = gs.to_ndarray(diagonals, to_ndim=3)
      num_lines = diagonals.shape[0]
      if num_diag > 0:
          left_zeros = gs.zeros((num_lines, num_columns, num_diag))
          lower_zeros = gs.zeros(
              (num_lines, num_diag, num_columns + num_diag)
          )
          diagonals = gs.concatenate((left_zeros, diagonals), axis=2)
          diagonals = gs.concatenate((diagonals, lower_zeros), axis=1)
      elif num_diag < 0:
          num_diag = gs.abs(num_diag)
          right_zeros = gs.zeros((num_lines, num_columns, num_diag))
          upper_zeros = gs.zeros(
              (num_lines, num_diag, num_columns + num_diag)
          )
          diagonals = gs.concatenate((diagonals, right_zeros), axis=2)
          diagonals = gs.concatenate((upper_zeros, diagonals), axis=1)
      return (
          gs.squeeze(diagonals) if gs.ndim(vector) == 1 else diagonals
      )
  
imports: import math
  import geomstats.backend
label_desc: Use image node_id 1 for calling a global function with example usage: from_vector_to_diagonal_matrix(vector, num_diag) and returns: unknown