code: def test_singular_values():
      # Check that the TruncatedSVD output has the correct singular values
  
      rng = np.random.RandomState(0)
      n_samples = 100
      n_features = 80
  
      X = rng.randn(n_samples, n_features)
      dX = da.from_array(X, chunks=(n_samples // 2, n_features))
  
      apca = dd.TruncatedSVD(
          n_components=2, algorithm="tsqr", random_state=rng
      ).fit(dX)
      rpca = sd.TruncatedSVD(
          n_components=2, algorithm="arpack", random_state=rng
      ).fit(X)
      assert_array_almost_equal(
          apca.singular_values_, rpca.singular_values_, 12
      )
  
      # Compare to the Frobenius norm
      X_apca = apca.transform(X)
      X_rpca = rpca.transform(X)
      assert_array_almost_equal(
          np.sum(apca.singular_values_**2.0),
          np.linalg.norm(X_apca, "fro") ** 2.0,
          12,
      )
      assert_array_almost_equal(
          np.sum(rpca.singular_values_**2.0),
          np.linalg.norm(X_rpca, "fro") ** 2.0,
          12,
      )
  
      # Compare to the 2-norms of the score vectors
      assert_array_almost_equal(
          apca.singular_values_,
          np.sqrt(np.sum(X_apca**2.0, axis=0)),
          12,
      )
      assert_array_almost_equal(
          rpca.singular_values_,
          np.sqrt(np.sum(X_rpca**2.0, axis=0)),
          12,
      )
  
      # Set the singular values and see what we get back
      rng = np.random.RandomState(0)
      n_samples = 100
      n_features = 110
  
      X = rng.randn(n_samples, n_features)
      dX = da.from_array(X, chunks=(50, n_features))
  
      apca = dd.TruncatedSVD(
          n_components=3, algorithm="randomized", random_state=0
      )
      rpca = sd.TruncatedSVD(
          n_components=3, algorithm="randomized", random_state=0
      )
      X_apca = apca.fit_transform(dX).compute()
      X_rpca = rpca.fit_transform(X)
  
      X_apca /= np.sqrt(np.sum(X_apca**2.0, axis=0))
      X_rpca /= np.sqrt(np.sum(X_rpca**2.0, axis=0))
      X_apca[:, 0] *= 3.142
      X_apca[:, 1] *= 2.718
      X_rpca[:, 0] *= 3.142
      X_rpca[:, 1] *= 2.718
  
      X_hat_apca = np.dot(X_apca, apca.components_)
      X_hat_rpca = np.dot(X_rpca, rpca.components_)
      apca.fit(da.from_array(X_hat_apca, chunks=(50, n_features)))
      rpca.fit(X_hat_rpca)
      assert_array_almost_equal(
          apca.singular_values_, [3.142, 2.718, 1.0], 14
      )
      assert_array_almost_equal(
          rpca.singular_values_, [3.142, 2.718, 1.0], 14
      )
  
file_path: dask-ml/tests/test_svd.py
imports: import dask.array
  import numpy
  import pytest
  import scipy.sparse
  from numpy.testing import assert_array_almost_equal
  from sklearn import decomposition
  from sklearn.utils import check_random_state
  from dask_ml import decomposition
  from dask_ml.utils import assert_estimator_equal, flip_vector_signs
label_desc: Use image node_id 8 for calling a global function with example usage: test_singular_values() without return types