code: def test_tensor_train_cross_4():
      """Test for tensor-train"""
  
      # TEST 4
      # Random tensor is not really compress-able. Test on a tensor as values of a function
  
      def getEquispaceGrid(n_dim, rng, subdivisions):
          """
          Returns a grid of equally-spaced points in the specified number of dimensions
  
          n_dim       : The number of dimensions to construct the tensor grid in
          rng         : The maximum dimension coordinate (grid starts at 0)
          subdivisions: Number of subdivisions of the grid to construct
          """
  
          return np.array(
              [
                  np.array(range(subdivisions + 1))
                  * rng
                  * 1.0
                  / subdivisions
                  for i in range(n_dim)
              ]
          )
  
      def evaluateGrid(grid, fcn):
          """
          Loops over a grid in specified order and computes the specified function at each
          point in the grid, returning a list of computed values.
          """
          d, n = grid.shape
          values = np.zeros(len(grid[0]) ** len(grid))
          idx = 0
          for permutation in itertools.product(
              range(len(grid[0])), repeat=len(grid)
          ):
              pt = np.array(
                  [
                      grid[i][permutation[i]]
                      for i in range(len(permutation))
                  ]
              )
              values[idx] = fcn(pt)
              idx += 1
  
          return values.reshape((n,) * d)
  
      def func(X):
          return sum(X) ** 3
  
      tol = 1e-3
      n = 10
      d = 4
      rng = 1
      grid = getEquispaceGrid(d, rng, n)
      value = evaluateGrid(grid, func)
      value = tl.tensor(value)
  
      # Find TT decomposition of the tensor
      rank = [1, 4, 4, 4, 1]
      factors = tensor_train_cross(
          value, rank, tol=tol, random_state=rng
      )
  
      approx = tt_to_tensor(factors)
      error = tl.norm(approx - value, 2)
      error /= tl.norm(value, 2)
  
      print(error)
      assert_(error < 1e-5, "norm 2 of reconstruction higher than tol")
  
file_path: tensorly/tensorly/contrib/decomposition/tests/test_mps_decomposition_cross.py
imports: import tensorly
  import pytest
  import numpy
  import itertools
  from .._tt_cross import tensor_train_cross
  from ....tt_tensor import tt_to_tensor
  from tensorly.testing import assert_
label_desc: Use image node_id 4 for calling a global function with example usage: test_tensor_train_cross_4() and returns: np, values, unknown