docstr: Turn 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
      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
      mode of the desired unfolding
  
  Returns
  -------
  ivy.Array
      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))``
docstr_tok: ["Turn","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","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","mode","of","the","desired","unfolding","Returns","--","--","--","-","ivy.Array","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",")",")","``"]
code: def cp_to_unfolded(cp_tensor, mode):
      """Turn 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
          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
          mode of the desired unfolding
  
      Returns
      -------
      ivy.Array
          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))``
      """
      ivy.CPTensor.validate_cp_tensor(cp_tensor)
      weights, factors = cp_tensor
  
      if weights is not None:
          return ivy.dot(
              factors[mode] * weights,
              ivy.permute_dims(
                  ivy.khatri_rao(factors, skip_matrix=mode), (1, 0)
              ),
          )
      else:
          return ivy.dot(
              factors[mode],
              ivy.permute_dims(
                  ivy.khatri_rao(factors, skip_matrix=mode), (1, 0)
              ),
          )
  
imports: from .base import FactorizedTensor
  import ivy
label_desc: Use image node_id 22 for calling the CPTensor obj's underlying member method code with example usage: obj.cp_to_unfolded(cp_tensor, mode) and returns: ivy, ivy