code: def test_partial_fold():
      """Test for partial_fold
  
      Assumes partial unfolding works and check that
      refolding partially folded tensors results in
      the original tensor.
      """
      X = T.reshape(T.arange(24), (3, 4, 2))
      unfolded = T.tensor(
          [
              [
                  [0, 1, 2, 3, 4, 5, 6, 7],
                  [8, 9, 10, 11, 12, 13, 14, 15],
                  [16, 17, 18, 19, 20, 21, 22, 23],
              ],
              [
                  [0, 1, 2, 3, 4, 5, 6, 7],
                  [8, 9, 10, 11, 12, 13, 14, 15],
                  [16, 17, 18, 19, 20, 21, 22, 23],
              ],
              [
                  [0, 1, 2, 3, 4, 5, 6, 7],
                  [8, 9, 10, 11, 12, 13, 14, 15],
                  [16, 17, 18, 19, 20, 21, 22, 23],
              ],
          ]
      )
      folded = partial_fold(unfolded, 0, (3, 3, 4, 2), skip_begin=1)
      for i in range(3):
          assert_array_equal(folded[i], X)
  
      shape = [3, 4, 5, 6]
      X = T.tensor(np.random.random(shape))
      for i in [0, 1]:
          for mode in range(len(shape) - 1):
              unfolded = partial_unfold(
                  X, mode=mode, skip_begin=i, skip_end=(1 - i)
              )
              refolded = partial_fold(
                  unfolded,
                  mode=mode,
                  shape=shape,
                  skip_begin=i,
                  skip_end=(1 - i),
              )
              assert_array_equal(refolded, X)
  
      # Test for raveled_tensor=True
      for i in [0, 1]:
          for mode in range(len(shape) - 1):
              unfolded = partial_unfold(
                  X,
                  mode=mode,
                  skip_begin=i,
                  skip_end=(1 - i),
                  ravel_tensors=True,
              )
              refolded = partial_fold(
                  unfolded,
                  mode=mode,
                  shape=shape,
                  skip_begin=i,
                  skip_end=(1 - i),
              )
              assert_array_equal(refolded, X)
  
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 6 for calling a global function with example usage: test_partial_fold() without return types