code: def _nearpsd(A):
      r"""Obtain the "closest" positive semidefinite matrix to A."""
      n = A.shape[0]
      eigval, eigvec = np.linalg.eig(A)
      val = np.matrix(np.maximum(eigval, 0))
      vec = np.matrix(eigvec)
      T = 1 / (np.multiply(vec, vec) * val.T)
      T = np.matrix(np.sqrt(np.diag(np.array(T).reshape((n)))))
      B = T * vec * np.diag(np.array(np.sqrt(val)).reshape((n)))
      out = np.real(B * B.T)
      return out
  
imports: import hail
  from hail.typecheck import typecheck, oneof, nullable
  from hail.expr.expressions import expr_float64, expr_int32, expr_array, expr_call
  from hail.matrixtable import MatrixTable
  from hail.table import Table
  from hail.utils.java import Env
  import numpy
  import pandas
  import scipy.stats
label_desc: Use image node_id 6 for calling a global function with example usage: _nearpsd(A) and returns: out