code: def test_parafac2_linesearch():
      """Test that we end up with a better fit at the same number of iterations with linesearch."""
      rng = tl.check_random_state(1234)
      rank = 4
  
      random_parafac2_tensor = random_parafac2(
          shapes=[(25 + rng.randint(5), 300) for _ in range(15)],
          rank=rank,
          random_state=rng,
      )
  
      slices = parafac2_to_slices(random_parafac2_tensor)
  
      _, err = parafac2(
          slices,
          rank,
          init="svd",
          return_errors=True,
          n_iter_max=10,
          linesearch=False,
      )
      standard_error = err[-1]
  
      _, err = parafac2(
          slices,
          rank,
          init="svd",
          return_errors=True,
          n_iter_max=10,
          linesearch=True,
      )
      ls_error = err[-1]
      assert ls_error < standard_error
  
file_path: tensorly/tensorly/decomposition/tests/test_parafac2.py
imports: import itertools
  import numpy
  import pytest
  import tensorly
  from ...random import random_parafac2
  from ...None import backend
  from ...testing import assert_, assert_class_wrapper_correctly_passes_arguments, assert_array_almost_equal, assert_allclose
  from .._parafac2 import Parafac2, parafac2, initialize_decomposition, _BroThesisLineSearch
  from ...parafac2_tensor import Parafac2Tensor, parafac2_to_tensor, parafac2_to_slices
  from ...metrics.factors import congruence_coefficient
label_desc: Use image node_id 2 for calling a global function with example usage: test_parafac2_linesearch() without return types