code: def spectra_and_moments_helper(spec_func):
      for triplet in [(20, 1000, 1000)]:
          k, m, n = triplet
          min_dim = min(m, n)
          sigma = np.diag([spec_func(i + 1, k) for i in range(min_dim)])
          seed = 1025
          np.random.seed(seed)
          U = np.linalg.qr(np.random.normal(0, 1, (m, min_dim)))[0]
          V = np.linalg.qr(np.random.normal(0, 1, (n, min_dim)))[0]
          A = U @ sigma @ V.T
          mt_A = matrix_table_from_numpy(A)
  
          (
              eigenvalues,
              scores,
              loadings,
              moments,
              stdevs,
          ) = hl._pca_and_moments(
              _make_tsm(mt_A.ent, 128),
              k=k,
              num_moments=7,
              oversampling_param=k,
              compute_loadings=True,
              q_iterations=4,
          )
          singulars = np.sqrt(eigenvalues)
          hail_V = (np.array(scores.scores.collect()) / singulars).T
          hail_U = np.array(loadings.loadings.collect())
          approx_A = hail_U @ np.diag(singulars) @ hail_V
          norm_of_diff = np.linalg.norm(A - approx_A, 2)
          np.testing.assert_allclose(
              norm_of_diff,
              spec_func(k + 1, k),
              rtol=1e-02,
              err_msg=f"Norm test failed on triplet {triplet}",
          )
          np.testing.assert_allclose(
              singulars,
              np.diag(sigma)[:k],
              rtol=1e-01,
              err_msg=f"Failed on triplet {triplet}",
          )
  
          true_moments = np.array(
              [np.sum(np.power(sigma, 2 * i)) for i in range(1, 8)]
          )
          np.testing.assert_allclose(moments, true_moments, rtol=1e-04)
  
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 24 for calling a global function with example usage: spectra_and_moments_helper(spec_func) without return types