code: def test_mpca(var_ratio, n_components, gait):
      # basic mpca test, return tensor
      x = gait["fea3D"].transpose((3, 0, 1, 2))
      mpca = MPCA(var_ratio=var_ratio, vectorize=False)
      x_proj = mpca.fit(x).transform(x)
  
      testing.assert_equal(x_proj.ndim, x.ndim)
      testing.assert_equal(x_proj.shape[0], x.shape[0])
      assert mpca.n_components <= np.prod(x.shape[1:])
      assert n_components < mpca.n_components
      for i in range(1, x.ndim):
          assert x_proj.shape[i] <= x.shape[i]
          testing.assert_equal(
              mpca.proj_mats[i - 1].shape[1], x.shape[i]
          )
  
      x_rec = mpca.inverse_transform(x_proj)
      testing.assert_equal(x_rec.shape, x.shape)
  
      # test return vector
      mpca.set_params(
          **{"vectorize": True, "n_components": n_components}
      )
  
      x_proj = mpca.transform(x)
      testing.assert_equal(x_proj.ndim, 2)
      testing.assert_equal(x_proj.shape[0], x.shape[0])
      testing.assert_equal(x_proj.shape[1], n_components)
      x_rec = mpca.inverse_transform(x_proj)
      testing.assert_equal(x_rec.shape, x.shape)
  
      # test n_samples = 1
      x0_proj = mpca.transform(x[0])
      testing.assert_equal(x0_proj.ndim, 2)
      testing.assert_equal(x0_proj.shape[0], 1)
      testing.assert_equal(x0_proj.shape[1], n_components)
      x0_rec = mpca.inverse_transform(x0_proj.reshape(-1))
      testing.assert_equal(x0_rec.shape[1:], x[0].shape)
  
      # test n_components exceeds upper limit
      mpca.set_params(
          **{
              "vectorize": True,
              "n_components": np.prod(x.shape[1:]) + 1,
          }
      )
      x_proj = mpca.transform(x)
      testing.assert_equal(x_proj.shape[1], np.prod(mpca.shape_out))
  
file_path: pykale/tests/embed/test_factorization.py
imports: import os
  import numpy
  import pytest
  from numpy import testing
  from scipy.io import loadmat
  from sklearn.datasets import make_blobs
  from sklearn.preprocessing import OneHotEncoder
  from tensorly.tenalg import multi_mode_dot
  from kale.embed.factorization import MIDA, MPCA
label_desc: Use image node_id 2 for calling a global function with example usage: test_mpca(var_ratio, n_components, gait) without return types