code: def cp_permute_factors(ref_cp_tensor, tensors_to_permute):
      """
      Compares factors of a reference cp tensor with factors of other another tensor (or list of tensor) in order to match component order.
      Permutation occurs on the columns of factors, minimizing the cosine distance to reference cp tensor with scipy
      Linear Sum Assignment method. The permuted tensor (or list of tensors) and list of permutation for each permuted tensors are returned.
  
      Parameters
      ----------
      ref_cp_tensor : cp tensor
          The tensor that serves as a reference for permutation.
      tensors_to_permute : cp tensor or list of cp tensors
          The tensors to permute so that the order of components match the reference tensor. Number of components must match.
  
      Returns
      -------
      permuted_tensors : permuted cp tensor or list of cp tensors
      permutation : list
          list of permuted indices. Lenght is equal to rank of cp_tensors.
      """
      if not isinstance(tensors_to_permute, list):
          permuted_tensors = [tensors_to_permute.cp_copy()]
          tensors_to_permute = [tensors_to_permute]
      else:
          permuted_tensors = []
          for i in range(len(tensors_to_permute)):
              permuted_tensors.append(tensors_to_permute[i].cp_copy())
              tensors_to_permute[i] = cp_normalize(
                  tensors_to_permute[i]
              )
      ref_cp_tensor = cp_normalize(ref_cp_tensor)
      n_tensors = len(tensors_to_permute)
      n_factors = len(ref_cp_tensor.factors)
      permutation = []
      for i in range(n_tensors):
          _, col = congruence_coefficient(
              ref_cp_tensor.factors, tensors_to_permute[i].factors
          )
          col = T.tensor(col, dtype=T.int64)
          for f in range(n_factors):
              permuted_tensors[i].factors[f] = permuted_tensors[
                  i
              ].factors[f][:, col]
          permuted_tensors[i].weights = permuted_tensors[i].weights[col]
          permutation.append(col)
      if len(permuted_tensors) == 1:
          permuted_tensors = permuted_tensors[0]
      return permuted_tensors, permutation
  
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 12 for calling a global function with example usage: cp_permute_factors(ref_cp_tensor, tensors_to_permute) and returns: permuted_tensors,  permutation