code: def test_random_tucker():
      """test for random.random_tucker"""
      shape = (10, 11, 12)
      rank = 4
  
      tensor = random_tucker(shape, rank, full=True)
      for i in range(T.ndim(tensor)):
          assert_equal(matrix_rank(T.to_numpy(unfold(tensor, i))), rank)
  
      core, factors = random_tucker(shape, rank, full=False)
      for i, factor in enumerate(factors):
          assert_equal(
              factor.shape,
              (shape[i], rank),
              err_msg=f"{i}-th factor has shape {factor.shape}, expected {(shape[i], rank)}",
          )
  
      shape = (10, 11, 12)
      rank = (6, 4, 5)
      tensor = random_tucker(shape, rank, full=True)
      for i in range(T.ndim(tensor)):
          assert_equal(
              matrix_rank(T.to_numpy(unfold(tensor, i))),
              min(shape[i], rank[i]),
          )
  
      core, factors = random_tucker(
          shape, rank, orthogonal=True, full=False
      )
      for i, factor in enumerate(factors):
          assert_equal(
              factor.shape,
              (shape[i], rank[i]),
              err_msg=f"{i}-th factor has shape {factor.shape}, expected {(shape[i], rank[i])}.",
          )
      assert_equal(
          core.shape,
          rank,
          err_msg=f"core has shape {core.shape}, expected {rank}.",
      )
      for factor in factors:
          assert_array_almost_equal(
              T.dot(T.transpose(factor), factor),
              T.tensor(np.eye(factor.shape[1])),
          )
      tensor = tucker_to_tensor((core, factors))
      reconstructed = multi_mode_dot(tensor, factors, transpose=True)
      assert_array_almost_equal(core, reconstructed)
  
file_path: tensorly/tensorly/random/tests/test_base.py
imports: import numpy
  from numpy.linalg import matrix_rank
  from ...None import backend
  from ..base import random_cp, random_tucker, random_tt, random_tr
  from ...tucker_tensor import tucker_to_tensor
  from ...tenalg import multi_mode_dot
  from ...base import unfold
  from ...testing import assert_equal, assert_array_almost_equal, assert_raises
label_desc: Use image node_id 3 for calling a global function with example usage: test_random_tucker() without return types