code: def test_pca_against_numpy():
      mt = hl.import_vcf(resource("tiny_m.vcf"))
      mt = mt.annotate_rows(
          AC=hl.agg.sum(mt.GT.n_alt_alleles()),
          n_called=hl.agg.count_where(hl.is_defined(mt.GT)),
      )
      n_rows = 3
      n_cols = 4
      k = 3
  
      mean = mt.AC / mt.n_called
      eigen, scores, loadings = hl.pca(
          hl.coalesce(
              (mt.GT.n_alt_alleles() - mean)
              / hl.sqrt(mean * (2 - mean) * n_rows / 2),
              0,
          ),
          k=k,
          compute_loadings=True,
      )
  
      hail_scores = scores.explode("scores").scores.collect()
      hail_loadings = loadings.explode("loadings").loadings.collect()
  
      assert len(hail_scores) == n_cols * k
      assert len(hail_loadings) == n_rows * k
  
      # compute PCA with numpy
      def normalize(a):
          ms = np.mean(a, axis=0, keepdims=True)
          return np.divide(
              np.subtract(a, ms),
              np.sqrt(
                  2.0 * np.multiply(ms / 2.0, 1 - ms / 2.0) * a.shape[1]
              ),
          )
  
      g = np.pad(
          np.diag([1.0, 1, 2]), ((0, 1), (0, 0)), mode="constant"
      )
      g[1, 0] = 1.0 / 3
      n = normalize(g)
      U, s, V = np.linalg.svd(n, full_matrices=0)
      np_scores = U.dot(np.diag(s)).flatten()
      np_loadings = V.transpose().flatten()
      np_eigenvalues = np.multiply(s, s).flatten()
  
      np.testing.assert_allclose(eigen, np_eigenvalues, rtol=1e-5)
      np.testing.assert_allclose(
          np.abs(hail_scores), np.abs(np_scores), rtol=1e-5
      )
      np.testing.assert_allclose(
          np.abs(hail_loadings), np.abs(np_loadings), rtol=1e-5
      )
  
imports: import math
  import pytest
  import numpy
  import hail
  from hail.methods.pca import _make_tsm
  from ..helpers import resource, fails_local_backend, skip_when_service_backend, test_timeout
label_desc: Use image node_id 2 for calling a global function with example usage: test_pca_against_numpy() and returns: np