code: def test_randomized_eigsh_compared_to_others(k):
      """Check that `_randomized_eigsh` is similar to other `eigsh`
  
      Tests that for a random PSD matrix, `_randomized_eigsh` provides results
      comparable to LAPACK (scipy.linalg.eigh) and ARPACK
      (scipy.sparse.linalg.eigsh).
  
      Note: some versions of ARPACK do not support k=n_features.
      """
  
      # make a random PSD matrix
      n_features = 200
      X = make_sparse_spd_matrix(n_features, random_state=0)
  
      # compare two versions of randomized
      # rough and fast
      eigvals, eigvecs = _randomized_eigsh(
          X,
          n_components=k,
          selection="module",
          n_iter=25,
          random_state=0,
      )
      # more accurate but slow (TODO find realistic settings here)
      eigvals_qr, eigvecs_qr = _randomized_eigsh(
          X,
          n_components=k,
          n_iter=25,
          n_oversamples=20,
          random_state=0,
          power_iteration_normalizer="QR",
          selection="module",
      )
  
      # with LAPACK
      eigvals_lapack, eigvecs_lapack = eigh(
          X, subset_by_index=(n_features - k, n_features - 1)
      )
      indices = eigvals_lapack.argsort()[::-1]
      eigvals_lapack = eigvals_lapack[indices]
      eigvecs_lapack = eigvecs_lapack[:, indices]
  
      # -- eigenvalues comparison
      assert eigvals_lapack.shape == (k,)
      # comparison precision
      assert_array_almost_equal(eigvals, eigvals_lapack, decimal=6)
      assert_array_almost_equal(eigvals_qr, eigvals_lapack, decimal=6)
  
      # -- eigenvectors comparison
      assert eigvecs_lapack.shape == (n_features, k)
      # flip eigenvectors' sign to enforce deterministic output
      dummy_vecs = np.zeros_like(eigvecs).T
      eigvecs, _ = svd_flip(eigvecs, dummy_vecs)
      eigvecs_qr, _ = svd_flip(eigvecs_qr, dummy_vecs)
      eigvecs_lapack, _ = svd_flip(eigvecs_lapack, dummy_vecs)
      assert_array_almost_equal(eigvecs, eigvecs_lapack, decimal=4)
      assert_array_almost_equal(eigvecs_qr, eigvecs_lapack, decimal=6)
  
      # comparison ARPACK ~ LAPACK (some ARPACK implems do not support k=n)
      if k < n_features:
          v0 = _init_arpack_v0(n_features, random_state=0)
          # "LA" largest algebraic <=> selection="value" in randomized_eigsh
          eigvals_arpack, eigvecs_arpack = eigsh(
              X, k, which="LA", tol=0, maxiter=None, v0=v0
          )
          indices = eigvals_arpack.argsort()[::-1]
          # eigenvalues
          eigvals_arpack = eigvals_arpack[indices]
          assert_array_almost_equal(
              eigvals_lapack, eigvals_arpack, decimal=10
          )
          # eigenvectors
          eigvecs_arpack = eigvecs_arpack[:, indices]
          eigvecs_arpack, _ = svd_flip(eigvecs_arpack, dummy_vecs)
          assert_array_almost_equal(
              eigvecs_arpack, eigvecs_lapack, decimal=8
          )
  
imports: import numpy
  import pytest
  from scipy import linalg, sparse
  from scipy.linalg import eigh
  from scipy.sparse.linalg import eigsh
  from scipy.special import expit
  from sklearn.datasets import make_low_rank_matrix, make_sparse_spd_matrix
  from sklearn.utils import gen_batches
  from sklearn.utils._arpack import _init_arpack_v0
  from sklearn.utils._testing import assert_allclose, assert_allclose_dense_sparse, assert_almost_equal, assert_array_almost_equal, assert_array_equal, skip_if_32bit
  from sklearn.utils.extmath import _deterministic_vector_sign_flip, _incremental_mean_and_var, _randomized_eigsh, _safe_accumulator_op, cartesian, density, log_logistic, randomized_svd, row_norms, safe_sparse_dot, softmax, stable_cumsum, svd_flip, weighted_mode
  from sklearn.utils.fixes import COO_CONTAINERS, CSC_CONTAINERS, CSR_CONTAINERS, DOK_CONTAINERS, LIL_CONTAINERS, _mode
label_desc: Use image node_id 6 for calling a global function with example usage: test_randomized_eigsh_compared_to_others(k) without return types