code: def test_random_cp():
      """test for random.random_cp"""
      shape = (10, 11, 12)
      rank = 4
  
      tensor = random_cp(shape, rank, full=True)
      assert T.shape(tensor) == shape
  
      for i in range(T.ndim(tensor)):
          assert_equal(
              matrix_rank(T.to_numpy(unfold(tensor, i)), tol=1e-6), rank
          )
  
      weights, factors = random_cp(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)}",
          )
  
      # tests that the columns of each factor matrix are indeed orthogonal
      weights, factors = random_cp(
          shape, rank, full=False, orthogonal=True
      )
      for i, factor in enumerate(factors):
          for j in range(rank):
              for k in range(j):
                  # (See issue #40)
                  dot_product = T.dot(factor[:, j], factor[:, k])
                  try:
                      T.shape(dot_product)
                  except:
                      dot_product = T.tensor(
                          [dot_product], **T.context(weights)
                      )
                  assert_array_almost_equal(dot_product, T.tensor([0]))
  
      with np.testing.assert_raises(ValueError):
          shape = (10, 11, 12)
          rank = 11
          _ = random_cp(shape, rank, orthogonal=True)
  
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 2 for calling a global function with example usage: test_random_cp() without return types