code: def cp_to_tensor(cp_tensor, mask=None):
      """Turns the Khatri-product of matrices into a full tensor
  
          ``factor_matrices = [|U_1, ... U_n|]`` becomes
          a tensor shape ``(U[1].shape[0], U[2].shape[0], ... U[-1].shape[0])``
  
      Parameters
      ----------
      cp_tensor : CPTensor = (weight, factors)
          factors is a list of factor matrices, all with the same number of columns
          i.e. for all matrix U in factor_matrices:
          U has shape ``(s_i, R)``, where R is fixed and s_i varies with i
  
      mask : ndarray a mask to be applied to the final tensor. It should be
          broadcastable to the shape of the final tensor, that is
          ``(U[1].shape[0], ... U[-1].shape[0])``.
  
      Returns
      -------
      ndarray
          full tensor of shape ``(U[1].shape[0], ... U[-1].shape[0])``
  
      Notes
      -----
      This version works by first computing the mode-0 unfolding of the tensor
      and then refolding it.
  
      There are other possible and equivalent alternate implementation, e.g.
      summing over r and updating an outer product of vectors.
  
      """
      shape, _ = _validate_cp_tensor(cp_tensor)
  
      if not shape:  # 0-order tensor
          return cp_tensor
  
      weights, factors = cp_tensor
      if len(shape) == 1:  # just a vector
          return T.sum(weights * factors[0], axis=1)
  
      if weights is None:
          weights = 1
  
      if mask is None:
          full_tensor = T.dot(
              factors[0] * weights,
              T.transpose(khatri_rao(factors, skip_matrix=0)),
          )
      else:
          full_tensor = T.sum(
              khatri_rao(
                  [factors[0] * weights] + factors[1:], mask=mask
              ),
              axis=1,
          )
  
      return fold(full_tensor, 0, shape)
  
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 7 for calling a global function with example usage: cp_to_tensor(cp_tensor, mask) and returns: fold, cp_tensor, T