code: def tensor_train_example_numpy():
      # kept here just for a collection, only tested for numpy
      # https://arxiv.org/pdf/1509.06569.pdf, (5)
      x = numpy.ones([3, 4, 5, 6])
      rank = 4
      if numpy.__version__ < "1.15.0":
          # numpy.einsum fails here, skip test
          return
      # creating appropriate Gs
      Gs = [numpy.ones([d, d, rank, rank]) for d in x.shape]
      Gs[0] = Gs[0][:, :, :1, :]
      Gs[-1] = Gs[-1][:, :, :, :1]
  
      # einsum way
      y = x.reshape((1,) + x.shape)
      for G in Gs:
          # taking partial results left-to-right
          # y = numpy.einsum('i j alpha beta, alpha i ...  -> beta ... j', G, y)
          y = numpy.einsum("i j a b, a i ...  -> b ... j", G, y)
      y1 = y.reshape(-1)
  
      # alternative way
      y = x.reshape(-1)
      for G in Gs:
          i, j, alpha, beta = G.shape
          y = rearrange(
              y, "(i rest alpha) -> rest (alpha i)", alpha=alpha, i=i
          )
          y = y @ rearrange(G, "i j alpha beta -> (alpha i) (j beta)")
          y = rearrange(
              y, "rest (beta j) -> (beta rest j)", beta=beta, j=j
          )
      y2 = y
      assert numpy.allclose(y1, y2)
  
      # yet another way
      y = x
      for G in Gs:
          i, j, alpha, beta = G.shape
          y = rearrange(
              y, "i ... (j alpha) -> ... j (alpha i)", alpha=alpha, i=i
          )
          y = y @ rearrange(G, "i j alpha beta -> (alpha i) (j beta)")
      y3 = y.reshape(-1)
      assert numpy.allclose(y1, y3)
  
file_path: einops/tests/test_examples.py
imports: import numpy
  import pytest
  from einops import rearrange, parse_shape, reduce
  from tests import is_backend_tested
  from tests.test_ops import imp_op_backends
label_desc: Use image node_id 2 for calling a global function with example usage: tensor_train_example_numpy() without return types