code: def test_parafac_linesearch():
      """Test that we more rapidly converge to a solution with line search."""
      rng = tl.check_random_state(1234)
      eps = 10e-2
      tensor = T.tensor(rng.random_sample((5, 5, 5)))
      kt = parafac(
          tensor,
          rank=5,
          init="random",
          random_state=1234,
          n_iter_max=10,
          tol=10e-9,
      )
      rec = tl.cp_to_tensor(kt)
      kt_ls = parafac(
          tensor,
          rank=5,
          init="random",
          random_state=1234,
          n_iter_max=10,
          tol=10e-9,
          linesearch=True,
      )
      rec_ls = tl.cp_to_tensor(kt_ls)
  
      rec_error = T.norm(tensor - rec) / T.norm(tensor)
      rec_error_ls = T.norm(tensor - rec_ls) / T.norm(tensor)
      assert_(
          rec_error_ls - rec_error < eps,
          f"Relative reconstruction error with line-search={rec_error_ls} VS {rec_error} without."
          "CP with line-search seems to have converged more slowly.",
      )
  
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 3 for calling a global function with example usage: test_parafac_linesearch() without return types