code: def test_validate_tucker_rank():
      """Test validate_tucker_rank with random sizes"""
      tol = 0.01
  
      tensor_shape = tuple(np.random.randint(1, 100, size=5))
      n_param_tensor = np.prod(tensor_shape)
  
      # Rounding = floor
      rank = validate_tucker_rank(
          tensor_shape, rank="same", rounding="floor"
      )
      n_param = _tucker_n_param(tensor_shape, rank)
      assert_(n_param * (1 - tol) <= n_param_tensor)
  
      # Rounding = ceil
      rank = validate_tucker_rank(
          tensor_shape, rank="same", rounding="ceil"
      )
      n_param = _tucker_n_param(tensor_shape, rank)
      assert_(n_param >= n_param_tensor * (1 - tol))
  
      # With fixed modes
      fixed_modes = [1, 4]
      tensor_shape = [
          s**2 if i in fixed_modes else s
          for (i, s) in enumerate(np.random.randint(2, 10, size=5))
      ]
      n_param_tensor = np.prod(tensor_shape)
      # Floor
      rank = validate_tucker_rank(
          tensor_shape,
          rank=0.5,
          fixed_modes=fixed_modes,
          rounding="floor",
      )
      n_param = _tucker_n_param(tensor_shape, rank)
      for mode in fixed_modes:
          assert_(rank[mode] == tensor_shape[mode])
      assert_(n_param * (1 - tol) <= n_param_tensor * 0.5)
      # Ceil
      fixed_modes = [0, 2]
      tensor_shape = [
          s**2 if i in fixed_modes else s
          for (i, s) in enumerate(np.random.randint(2, 10, size=5))
      ]
      n_param_tensor = np.prod(tensor_shape)
      rank = validate_tucker_rank(
          tensor_shape,
          rank=0.5,
          fixed_modes=fixed_modes,
          rounding="ceil",
      )
      n_param = _tucker_n_param(tensor_shape, rank)
      for mode in fixed_modes:
          assert_(rank[mode] == tensor_shape[mode])
      assert_(n_param >= n_param_tensor * 0.5 * (1 - tol))
  
file_path: tensorly/tensorly/tests/test_tucker_tensor.py
imports: import numpy
  from ..None import backend
  from ..base import unfold, tensor_to_vec
  from ..tucker_tensor import tucker_to_tensor, tucker_to_unfolded, tucker_to_vec, _validate_tucker_tensor, tucker_mode_dot, tucker_normalize, _tucker_n_param, validate_tucker_rank
  from ..tenalg import kronecker, mode_dot
  from ..testing import assert_array_equal, assert_array_almost_equal, assert_equal, assert_raises, assert_
  from ..random import random_tucker
label_desc: Use image node_id 7 for calling a global function with example usage: test_validate_tucker_rank() without return types