code: def tucker(
      tensor,
      rank,
      fixed_factors=None,
      n_iter_max=100,
      init="svd",
      return_errors=False,
      svd="truncated_svd",
      tol=10e-5,
      random_state=None,
      mask=None,
      verbose=False,
  ):
      """Tucker decomposition via Higher Order Orthogonal Iteration (HOI)
  
          Decomposes `tensor` into a Tucker decomposition:
          ``tensor = [| core; factors[0], ...factors[-1] |]`` [1]_
  
      Parameters
      ----------
      tensor : ndarray
      rank : None, int or int list
          size of the core tensor, ``(len(ranks) == tensor.ndim)``
          if int, the same rank is used for all modes
      fixed_factors : int list or None, default is None
          if not None, list of modes for which to keep the factors fixed.
          Only valid if a Tucker tensor is provided as init.
      n_iter_max : int
                   maximum number of iteration
      init : {'svd', 'random'}, optional
      return_errors : boolean
          Indicates whether the algorithm should return all reconstruction errors
          and computation time of each iteration or not
          Default: False
      svd : str, default is 'truncated_svd'
          function to use to compute the SVD,
          acceptable values in tensorly.SVD_FUNS
      tol : float, optional
            tolerance: the algorithm stops when the variation in
            the reconstruction error is less than the tolerance
      random_state : {None, int, np.random.RandomState}
      mask : ndarray
          array of booleans with the same shape as ``tensor`` should be 0 where
          the values are missing and 1 everywhere else. Note:  if tensor is
          sparse, then mask should also be sparse with a fill value of 1 (or
          True).
      verbose : int, optional
          level of verbosity
  
      Returns
      -------
      core : ndarray of size `ranks`
              core tensor of the Tucker decomposition
      factors : ndarray list
              list of factors of the Tucker decomposition.
              Its ``i``-th element is of shape ``(tensor.shape[i], ranks[i])``
  
      References
      ----------
      .. [1] tl.G.Kolda and B.W.Bader, "Tensor Decompositions and Applications",
         SIAM REVIEW, vol. 51, n. 3, pp. 455-500, 2009.
      """
      if fixed_factors:
          try:
              (core, factors) = init
          except:
              raise ValueError(
                  f'Got fixed_factor={fixed_factors} but no appropriate Tucker tensor was passed for "init".'
              )
  
          fixed_factors = sorted(fixed_factors)
          modes_fixed, factors_fixed = zip(
              *[
                  (i, f)
                  for (i, f) in enumerate(factors)
                  if i in fixed_factors
              ]
          )
          core = multi_mode_dot(core, factors_fixed, modes=modes_fixed)
          modes, factors = zip(
              *[
                  (i, f)
                  for (i, f) in enumerate(factors)
                  if i not in fixed_factors
              ]
          )
          init = (core, list(factors))
  
          (core, new_factors), rec_errors = partial_tucker(
              tensor,
              rank=rank,
              modes=modes,
              n_iter_max=n_iter_max,
              init=init,
              svd=svd,
              tol=tol,
              random_state=random_state,
              mask=mask,
              verbose=verbose,
          )
  
          factors = list(new_factors)
          for i, e in enumerate(fixed_factors):
              factors.insert(e, factors_fixed[i])
          core = multi_mode_dot(
              core, factors_fixed, modes=modes_fixed, transpose=True
          )
  
          return TuckerTensor((core, factors))
  
      else:
          modes = list(range(tl.ndim(tensor)))
          # TO-DO validate rank for partial tucker as well
          rank = validate_tucker_rank(tl.shape(tensor), rank=rank)
  
          (core, factors), rec_errors = partial_tucker(
              tensor,
              rank=rank,
              modes=modes,
              n_iter_max=n_iter_max,
              init=init,
              svd=svd,
              tol=tol,
              random_state=random_state,
              mask=mask,
              verbose=verbose,
          )
          tensor = TuckerTensor((core, factors))
          if return_errors:
              return tensor, rec_errors
          else:
              return tensor
  
imports: import tensorly
  from ._base_decomposition import DecompositionMixin
  from ..base import unfold
  from ..tenalg import multi_mode_dot, mode_dot
  from ..tucker_tensor import tucker_to_tensor, TuckerTensor, validate_tucker_rank, tucker_normalize
  from ..tenalg.proximal import hals_nnls, active_set_nnls, fista
  from math import sqrt
  import warnings
  from collections.abc import Iterable
  from ..tenalg.svd import svd_interface
label_desc: Use image node_id 3 for calling a global function with example usage: tucker(tensor, rank, fixed_factors, n_iter_max, init, return_errors, svd, tol, random_state, mask, verbose) and returns: TuckerTensor, tensor,  rec_errors, tensor