code: def test_optimized_covariance(n_latent):
      """Tests CP_PLSR components capture maximum covariance in synthetic data."""
      x, y, x_cp, _ = _get_pls_dataset(TENSOR_DIMENSIONS, n_latent, 1)
      pls = CP_PLSR(n_latent)
      pls.fit(x, y)
      y = tl.tensor_to_vec(y)
  
      max_cov = 0
      pls_cov = 0
      for component in np.arange(n_latent):
          max_cov += abs(
              np.cov(
                  tl.tensor_to_vec(x_cp.factors[0][:, component]),
                  y,
                  bias=True,
              )[0, 1]
          )
          pls_cov += abs(
              np.cov(
                  tl.tensor_to_vec(pls.X_factors[0][:, component]),
                  y,
                  bias=True,
              )[0, 1]
          )
  
      assert_allclose(max_cov, pls_cov)
  
imports: import numpy
  import pytest
  import tensorly
  from ...testing import assert_allclose
  from ...cp_tensor import CPTensor, cp_normalize, cp_to_tensor
  from ...metrics.factors import congruence_coefficient
  from ...random import random_cp
  from ..cp_plsr import CP_PLSR
label_desc: Use image node_id 12 for calling a global function with example usage: test_optimized_covariance(n_latent) without return types