code: def test_pca(setup):
      X = iris
  
      for n_comp in np.arange(X.shape[1]):
          pca = PCA(n_components=n_comp, svd_solver="full")
  
          X_r = pca.fit(X).transform(X).fetch()
          np.testing.assert_equal(X_r.shape[1], n_comp)
  
          X_r2 = pca.fit_transform(X).fetch()
          assert_array_almost_equal(X_r, X_r2)
  
          X_r = pca.transform(X).fetch()
          X_r2 = pca.fit_transform(X).fetch()
          assert_array_almost_equal(X_r, X_r2)
  
          # Test get_covariance and get_precision
          cov = pca.get_covariance()
          precision = pca.get_precision()
          assert_array_almost_equal(
              mt.dot(cov, precision).to_numpy(), np.eye(X.shape[1]), 12
          )
  
      # test explained_variance_ratio_ == 1 with all components
      pca = PCA(svd_solver="full")
      pca.fit(X)
      np.testing.assert_allclose(
          pca.explained_variance_ratio_.sum().to_numpy(), 1.0, 3
      )
  
imports: from itertools import product
  import numpy
  import pytest
  import scipy
  from sklearn import datasets
  from sklearn.utils._testing import assert_array_almost_equal, assert_almost_equal, assert_raises_regex, assert_raise_message, assert_raises
  from ....None import tensor
  from .._pca import PCA, _assess_dimension, _infer_dimension
label_desc: Use image node_id 1 for calling a global function with example usage: test_pca(setup) without return types