code: def test_cp_to_tensor_with_weights(shape, expected):
      A = ivy.reshape(ivy.arange(1, 5, dtype=float), shape)
      B = ivy.reshape(ivy.arange(5, 9, dtype=float), shape)
      weights = ivy.array([2, -1], dtype=A.dtype)
  
      out = ivy.CPTensor.cp_to_tensor((weights, [A, B]))
      expected = ivy.array(expected)  # computed by hand
      assert np.allclose(out, expected)
  
      (weights, factors) = ivy.random_cp(
          (5, 5, 5), 5, normalise_factors=True, full=False
      )
      true_res = ivy.matmul(
          ivy.matmul(factors[0], ivy.diag(weights)),
          ivy.permute_dims(ivy.khatri_rao(factors[1:]), (1, 0)),
      )
      true_res = ivy.fold(true_res, 0, (5, 5, 5))
      res = ivy.CPTensor.cp_to_tensor((weights, factors))
      assert np.allclose(true_res, res)
  
file_path: ivy/ivy_tests/test_ivy/test_misc/test_factorized_tensor/test_cp_tensor.py
imports: import ivy
  import numpy
  import pytest
label_desc: Use image node_id 7 for calling a global function with example usage: test_cp_to_tensor_with_weights(shape, expected) without return types