code: def cp_to_unfolded(cp_tensor, mode):
      """Turns the khatri-product of matrices into an unfolded tensor
  
          turns ``factors = [|U_1, ... U_n|]`` into a mode-`mode`
          unfolding of the tensor
  
      Parameters
      ----------
      cp_tensor : CPTensor = (weight, factors)
          factors is a list of matrices, all with the same number of columns
          ie for all u in factor_matrices:
          u[i] has shape (s_u_i, R), where R is fixed
      mode: int
          mode of the desired unfolding
  
      Returns
      -------
      ndarray
          unfolded tensor of shape (tensor_shape[mode], -1)
  
      Notes
      -----
      Writing factors = [U_1, ..., U_n], we exploit the fact that
      ``U_k = U[k].dot(khatri_rao(U_1, ..., U_k-1, U_k+1, ..., U_n))``
      """
      _validate_cp_tensor(cp_tensor)
      weights, factors = cp_tensor
  
      if weights is not None:
          return T.dot(
              factors[mode] * weights,
              T.transpose(khatri_rao(factors, skip_matrix=mode)),
          )
      else:
          return T.dot(
              factors[mode],
              T.transpose(khatri_rao(factors, skip_matrix=mode)),
          )
  
imports: from .None import backend
  from .base import fold, tensor_to_vec
  from ._factorized_tensor import FactorizedTensor
  from .tenalg import khatri_rao, unfolding_dot_khatri_rao
  from .metrics.factors import congruence_coefficient
  import numpy
label_desc: Use image node_id 8 for calling a global function with example usage: cp_to_unfolded(cp_tensor, mode) and returns: T, T