code: def test_partial_tucker():
      """Test for the Partial Tucker decomposition"""
      rng = tl.check_random_state(1234)
      tol_norm_2 = 10e-3
      tol_max_abs = 10e-1
      tensor = tl.tensor(rng.random_sample((3, 4, 3)))
      modes = [1, 2]
      (core, factors), rec_errors = partial_tucker(
          tensor, rank=None, modes=modes, n_iter_max=200, verbose=True
      )
      reconstructed_tensor = multi_mode_dot(core, factors, modes=modes)
      norm_rec = tl.norm(reconstructed_tensor, 2)
      norm_tensor = tl.norm(tensor, 2)
      assert_((norm_rec - norm_tensor) / norm_rec < tol_norm_2)
  
      # Test the max abs difference between the reconstruction and the tensor
      assert_(tl.max(tl.abs(norm_rec - norm_tensor)) < tol_max_abs)
  
      # Test the shape of the core and factors
      ranks = [3, 1]
      (core, factors), rec_errors = partial_tucker(
          tensor, rank=ranks, modes=modes, n_iter_max=100, verbose=1
      )
      for i, rank in enumerate(ranks):
          assert_equal(
              factors[i].shape,
              (tensor.shape[i + 1], ranks[i]),
              err_msg=f"factors[i].shape = {factors[i].shape}, expected {(tensor.shape[i + 1], ranks[i])}",
          )
      assert_equal(
          core.shape,
          [tensor.shape[0]] + ranks,
          err_msg=f"core.shape = {core.shape}, expected {[tensor.shape[0]] + ranks}",
      )
  
      # Test random_state fixes the core and the factor matrices
      (core1, factors1), rec_errors = partial_tucker(
          tensor,
          rank=ranks,
          modes=modes,
          random_state=0,
          init="random",
      )
      (core2, factors2), rec_errors = partial_tucker(
          tensor,
          rank=ranks,
          modes=modes,
          random_state=0,
          init="random",
      )
      assert_array_equal(core1, core2)
      for factor1, factor2 in zip(factors1, factors2):
          assert_array_equal(factor1, factor2)
  
file_path: tensorly/tensorly/decomposition/tests/test_tucker.py
imports: import pytest
  import numpy
  import tensorly
  from .._tucker import tucker, partial_tucker, non_negative_tucker, non_negative_tucker_hals, Tucker, Tucker_NN, Tucker_NN_HALS
  from ...tucker_tensor import tucker_to_tensor
  from ...tenalg import multi_mode_dot
  from ...random import random_tucker
  from ...testing import assert_equal, assert_, assert_array_equal, assert_class_wrapper_correctly_passes_arguments
label_desc: Use image node_id 1 for calling a global function with example usage: test_partial_tucker() without return types