code: def parafac_power_iteration(
      tensor, rank, n_repeat=10, n_iteration=10, verbose=0
  ):
      """CP Decomposition via Robust Tensor Power Iteration
  
      Parameters
      ----------
      tensor : tl.tensor
          input tensor to decompose
      rank : int
          rank of the decomposition (number of rank-1 components)
      n_repeat : int, default is 10
          number of initializations to be tried
      n_iteration : int, default is 10
          number of power iterations
      verbose : bool
          level of verbosity
  
      Returns
      -------
      (weights, factors)
  
      weights : 1-D tl.tensor of length `rank`
          contains the eigenvalue of each eigenvector
      factors : list of 2-D tl.tensor of shape (size, rank)
          Each column of each factor corresponds to one eigenvector
      """
      rank = validate_cp_rank(tl.shape(tensor), rank=rank)
  
      order = tl.ndim(tensor)
      factors = []
      weights = []
  
      for _ in range(rank):
          eigenval, eigenvec, deflated = power_iteration(
              tensor,
              n_repeat=n_repeat,
              n_iteration=n_iteration,
              verbose=verbose,
          )
          factors.append(eigenvec)
          weights.append(eigenval)
          tensor = deflated
  
      factors = [
          tl.stack([f[i] for f in factors], axis=1)
          for i in range(order)
      ]
      weights = tl.stack(weights)
  
      return weights, factors
  
file_path: tensorly/tensorly/decomposition/_cp_power.py
imports: import tensorly
  from ._base_decomposition import DecompositionMixin
  from ..cp_tensor import validate_cp_rank
  from tensorly.tenalg import outer
  import numpy
label_desc: Use image node_id 2 for calling a global function with example usage: parafac_power_iteration(tensor, rank, n_repeat, n_iteration, verbose) and returns: weights,  factors