code: def test_partial_unfold():
      """Test for partial_unfold
  
      Notes
      -----
      Assumes that the standard unfold is correct!
      """
      X = T.reshape(T.arange(24), (3, 4, 2))
      n_samples = 3
      ###################################
      # Samples are the first dimension #
      ###################################
      tensor = T.tensor(
          np.concatenate(
              [
                  np.arange(24).reshape((1, 3, 4, 2)) + i
                  for i in range(n_samples)
              ]
          )
      )
      t = T.tensor(X)
      # We created here a tensor with 3 samples, each sample being similar to X
      for i in range(T.ndim(X)):  # test for each mode
          unfolded = partial_unfold(tensor, i, skip_begin=1)
          unfolded_X = unfold(t, i)
          for j in range(n_samples):  # test for each sample
              assert_array_equal(unfolded[j], unfolded_X + j)
      # Test for raveled tensor
      for i in range(T.ndim(X)):  # test for each mode
          unfolded = partial_unfold(
              tensor, mode=i, skip_begin=1, ravel_tensors=True
          )
          unfolded_X = T.reshape(unfold(t, i), (-1,))
          for j in range(n_samples):  # test for each sample
              assert_array_equal(unfolded[j], unfolded_X + j)
  
      ##################################
      # Samples are the last dimension #
      ##################################
      tensor = T.tensor(
          np.concatenate(
              [
                  np.arange(24).reshape((3, 4, 2, 1)) + i
                  for i in range(n_samples)
              ],
              axis=-1,
          )
      )
      for i in range(T.ndim(X)):  # test for each mode
          unfolded = partial_unfold(
              tensor, mode=i, skip_end=1, skip_begin=0
          )
          unfolded_X = unfold(t, i)
          for j in range(n_samples):  # test for each sample
              assert_array_equal(
                  T.transpose(T.transpose(unfolded)[j]), unfolded_X + j
              )
  
      # Test for raveled tensor
      for i in range(T.ndim(X)):  # test for each mode
          unfolded = partial_unfold(
              tensor,
              mode=i,
              skip_end=1,
              skip_begin=0,
              ravel_tensors=True,
          )
          unfolded_X = T.reshape(unfold(t, i), (-1,))
          for j in range(n_samples):  # test for each sample
              assert_array_equal(
                  T.transpose(unfolded)[j], unfolded_X + j
              )
  
file_path: tensorly/tensorly/tests/test_core.py
imports: import numpy
  from ..None import backend
  from ..base import fold, unfold
  from ..base import partial_fold, partial_unfold
  from ..base import tensor_to_vec, vec_to_tensor
  from ..base import partial_tensor_to_vec, partial_vec_to_tensor
  from ..base import matricize
  from ..testing import assert_array_equal, assert_raises
label_desc: Use image node_id 5 for calling a global function with example usage: test_partial_unfold() without return types