docstr: Turn 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
      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
      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
  -------
  ivy.Array
      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.
docstr_tok: ["Turn","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","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","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","--","--","--","-","ivy.Array","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","."]
code: def cp_to_tensor(cp_tensor, mask=None):
      """Turn 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
          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
          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
      -------
      ivy.Array
          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, _ = ivy.CPTensor.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 ivy.sum(weights * factors[0], axis=1)
  
      if weights is None:
          weights = 1
  
      if mask is None:
          full_tensor = ivy.matmul(
              factors[0] * weights,
              ivy.permute_dims(
                  ivy.khatri_rao(factors, skip_matrix=0), (1, 0)
              ),
          )
      else:
          full_tensor = ivy.sum(
              ivy.khatri_rao(
                  [factors[0] * weights] + factors[1:], mask=mask
              ),
              axis=1,
          )
  
      return ivy.fold(full_tensor, 0, shape)
  
imports: from .base import FactorizedTensor
  import ivy
label_desc: Use image node_id 21 for calling the CPTensor obj's underlying member method code with example usage: obj.cp_to_tensor(cp_tensor, mask) and returns: ivy, cp_tensor, ivy