code: def test_cp_to_tensor():
      """Test for cp_to_tensor."""
      U1 = np.reshape(np.arange(1, 10, dtype=float), (3, 3))
      U2 = np.reshape(np.arange(10, 22, dtype=float), (4, 3))
      U3 = np.reshape(np.arange(22, 28, dtype=float), (2, 3))
      U4 = np.reshape(np.arange(28, 34, dtype=float), (2, 3))
      U = [tl.tensor(t) for t in [U1, U2, U3, U4]]
      true_res = tl.tensor(
          [
              [
                  [[46754.0, 51524.0], [52748.0, 58130.0]],
                  [[59084.0, 65114.0], [66662.0, 73466.0]],
                  [[71414.0, 78704.0], [80576.0, 88802.0]],
                  [[83744.0, 92294.0], [94490.0, 104138.0]],
              ],
              [
                  [[113165.0, 124784.0], [127790.0, 140912.0]],
                  [[143522.0, 158264.0], [162080.0, 178730.0]],
                  [[173879.0, 191744.0], [196370.0, 216548.0]],
                  [[204236.0, 225224.0], [230660.0, 254366.0]],
              ],
              [
                  [[179576.0, 198044.0], [202832.0, 223694.0]],
                  [[227960.0, 251414.0], [257498.0, 283994.0]],
                  [[276344.0, 304784.0], [312164.0, 344294.0]],
                  [[324728.0, 358154.0], [366830.0, 404594.0]],
              ],
          ]
      )
      res = cp_to_tensor((tl.ones(3), U))
      assert_array_equal(
          res,
          true_res,
          err_msg="Khatri-rao incorrectly transformed into full tensor.",
      )
  
      columns = 4
      rows = [3, 4, 2]
      matrices = [
          tl.tensor(
              np.arange(k * columns, dtype=float).reshape((k, columns))
          )
          for k in rows
      ]
      tensor = cp_to_tensor((tl.ones(columns), matrices))
      for i in range(len(rows)):
          unfolded = unfold(tensor, mode=i)
          U_i = matrices.pop(i)
          reconstructed = tl.dot(
              U_i, tl.transpose(khatri_rao(matrices))
          )
          assert_array_almost_equal(reconstructed, unfolded)
          matrices.insert(i, U_i)
  
imports: import numpy
  import tensorly
  from ..tenalg import khatri_rao, mode_dot
  from ..cp_tensor import cp_to_tensor, cp_to_unfolded, cp_to_vec, _validate_cp_tensor, cp_normalize, CPTensor, cp_mode_dot, cp_norm, cp_flip_sign, _cp_n_param, validate_cp_rank, cp_lstsq_grad, cp_permute_factors
  from ..base import unfold, tensor_to_vec
  from tensorly.random import random_cp
  from tensorly.testing import assert_equal, assert_raises, assert_, assert_array_equal, assert_array_almost_equal
  import pytest
label_desc: Use image node_id 4 for calling a global function with example usage: test_cp_to_tensor() without return types