code: def test_pca_randomized_solver(setup):
      # PCA on dense arrays
      X = iris
  
      # Loop excluding the 0, invalid for randomized
      for n_comp in np.arange(1, X.shape[1]):
          pca = PCA(
              n_components=n_comp,
              svd_solver="randomized",
              random_state=0,
          )
  
          X_r = pca.fit(X).transform(X)
          np.testing.assert_equal(X_r.shape[1], n_comp)
  
          X_r2 = pca.fit_transform(X)
          assert_array_almost_equal(X_r.fetch(), X_r2.fetch())
  
          X_r = pca.transform(X)
          assert_array_almost_equal(X_r.fetch(), X_r2.fetch())
  
          # Test get_covariance and get_precision
          cov = pca.get_covariance()
          precision = pca.get_precision()
          assert_array_almost_equal(
              mt.dot(cov, precision).to_numpy(),
              mt.eye(X.shape[1]).to_numpy(),
              12,
          )
  
      pca = PCA(n_components=0, svd_solver="randomized", random_state=0)
      with pytest.raises(ValueError):
          pca.fit(X)
  
      pca = PCA(n_components=0, svd_solver="randomized", random_state=0)
      with pytest.raises(ValueError):
          pca.fit(X)
      # Check internal state
      assert (
          pca.n_components
          == PCA(
              n_components=0, svd_solver="randomized", random_state=0
          ).n_components
      )
      assert (
          pca.svd_solver
          == PCA(
              n_components=0, svd_solver="randomized", random_state=0
          ).svd_solver
      )
  
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 2 for calling a global function with example usage: test_pca_randomized_solver(setup) without return types