code: def test_randomised_parafac(monkeypatch):
      """Test for randomised_parafac"""
      rng = tl.check_random_state(1234)
      t_shape = (10, 10, 10)
      tensor = T.tensor(rng.random_sample(t_shape))
      rank = 4
  
      # test tensor reconstructed properly
      tolerance = 0.05
      tensor = random_cp(
          shape=(10, 10, 10), rank=rank, full=True, random_state=rng
      )
      cp_tensor = randomised_parafac(
          tensor,
          rank=rank,
          n_samples=100,
          max_stagnation=20,
          n_iter_max=60,
          tol=0,
          verbose=0,
          random_state=rng,
      )
  
      for i, f in enumerate(cp_tensor[1]):
          assert_(
              T.shape(f) == (t_shape[i], rank),
              "Factors are of incorrect size",
          )
  
      reconstruction = cp_to_tensor(cp_tensor)
      error = float(
          T.norm(reconstruction - tensor, 2) / T.norm(tensor, 2)
      )
      assert_(
          error < tolerance,
          msg=f"reconstruction of {error} (higher than tolerance of {tolerance})",
      )
  
      assert_class_wrapper_correctly_passes_arguments(
          monkeypatch,
          randomised_parafac,
          RandomizedCP,
          ignore_args={"return_errors"},
          rank=3,
          n_samples=100,
      )
  
imports: import numpy
  import pytest
  import tensorly
  from .._cp import parafac, initialize_cp, sample_khatri_rao, randomised_parafac, CP, RandomizedCP, CPTensor
  from .._nn_cp import non_negative_parafac, non_negative_parafac_hals, CP_NN, CP_NN_HALS
  from ...cp_tensor import cp_to_tensor
  from ...cp_tensor import cp_to_tensor
  from ...random import random_cp
  from ...tenalg import khatri_rao
  from ...None import backend
  from ...testing import assert_array_equal, assert_, assert_class_wrapper_correctly_passes_arguments, assert_array_almost_equal
  from ...metrics.factors import congruence_coefficient
label_desc: Use image node_id 8 for calling a global function with example usage: test_randomised_parafac(monkeypatch) without return types