code: def test_mode_dot():
      """Test for mode_dot (n_mode_product)"""
      X = T.tensor(
          [
              [[1, 13], [4, 16], [7, 19], [10, 22]],
              [[2, 14], [5, 17], [8, 20], [11, 23]],
              [[3, 15], [6, 18], [9, 21], [12, 24]],
          ]
      )
      # tensor times matrix
      U = T.tensor([[1, 3, 5], [2, 4, 6]])
      true_res = T.tensor(
          [
              [[22, 130], [49, 157], [76, 184], [103, 211]],
              [[28, 172], [64, 208], [100, 244], [136, 280]],
          ]
      )
      res = mode_dot(X, U, 0)
      assert_array_equal(true_res, res)
  
      #######################
      # tensor times vector #
      #######################
      # Test with a matrix
      U = T.tensor([1, 2, 3, 4])
      true_res = T.tensor([[70, 190], [80, 200], [90, 210]])
      res = mode_dot(X, U, 1)
      assert_array_equal(true_res, res)
      # Test with a third order tensor
      X = T.tensor(np.arange(24, dtype=float).reshape((3, 4, 2)))
      v = T.tensor(np.arange(4, dtype=float))
      true_res = [[28, 34], [76, 82], [124, 130]]
      res = mode_dot(X, v, 1)
      assert_array_equal(true_res, res)
  
      # Using equivalence with unfolded expression
      X = T.tensor(np.random.random((2, 4, 5)))
      U = T.tensor(np.random.random((3, 4)))
      true_res = fold(T.dot(U, unfold(X, 1)), 1, (2, 3, 5))
      res = mode_dot(X, U, 1)
      assert res.shape == (2, 3, 5)
      assert_array_almost_equal(true_res, res)
  
      #########################################
      # Test for errors that should be raised #
      #########################################
      with assert_raises(ValueError):
          mode_dot(X, U, 0)
      # Same test for the vector case
      with assert_raises(ValueError):
          mode_dot(X, U[:, 0], 0)
      # Cannot take mode product of tensor with tensor
      with assert_raises(ValueError):
          mode_dot(X, X, 0)
  
      # Test using the equivalence with unfolded expression
      X = T.tensor(np.random.random((2, 4, 5)))
      U = T.tensor(np.random.random((3, 4)))
      res = unfold(mode_dot(X, U, 1), 1)
      assert_array_almost_equal(T.dot(U, unfold(X, 1)), res)
  
file_path: tensorly/tensorly/tenalg/tests/test_n_mode_product.py
imports: import itertools
  import numpy
  from ...None import backend
  from ...testing import assert_array_equal, assert_equal, assert_array_almost_equal, assert_raises
  from ...base import fold, unfold
  from ..None import kronecker
  from ..None import mode_dot, multi_mode_dot
label_desc: Use image node_id 1 for calling a global function with example usage: test_mode_dot() without return types