code: def test_svd():
      def assert_evals_to_same_svd(
          nd_expr, np_array, full_matrices=True, compute_uv=True
      ):
          evaled = hl.eval(
              hl.nd.svd(nd_expr, full_matrices, compute_uv)
          )
          np_svd = np.linalg.svd(np_array, full_matrices, compute_uv)
  
          # check shapes
          for h, n in zip(evaled, np_svd):
              assert h.shape == n.shape
  
          k = min(np_array.shape)
          rank = np.linalg.matrix_rank(np_array)
  
          if compute_uv:
              hu, hs, hv = evaled
              nu, ns, nv = np_svd
  
              # Singular values match
              np.testing.assert_array_almost_equal(hs, ns)
  
              # U is orthonormal
              uut = hu.T @ hu
              np.testing.assert_array_almost_equal(
                  uut, np.identity(uut.shape[0])
              )
  
              # V is orthonormal
              vvt = hv @ hv.T
              np.testing.assert_array_almost_equal(
                  vvt, np.identity(vvt.shape[0])
              )
  
              # Multiplying together gets back to original
              smat = (
                  np.zeros(np_array.shape)
                  if full_matrices
                  else np.zeros((k, k))
              )
              smat[:k, :k] = np.diag(hs)
              np.testing.assert_array_almost_equal(
                  hu @ smat @ hv, np_array
              )
  
          else:
              np.testing.assert_array_almost_equal(evaled, np_svd)
  
      np_small_square = np.arange(4).reshape((2, 2))
      small_square = hl.nd.array(np_small_square)
      np_rank_2_wide_rectangle = np.arange(12).reshape((4, 3))
      rank_2_wide_rectangle = hl.nd.array(np_rank_2_wide_rectangle)
      np_rank_2_tall_rectangle = np_rank_2_wide_rectangle.T
      rank_2_tall_rectangle = hl.nd.array(np_rank_2_tall_rectangle)
  
      assert_evals_to_same_svd(small_square, np_small_square)
      assert_evals_to_same_svd(
          small_square, np_small_square, compute_uv=False
      )
  
      assert_evals_to_same_svd(
          rank_2_wide_rectangle, np_rank_2_wide_rectangle
      )
      assert_evals_to_same_svd(
          rank_2_wide_rectangle,
          np_rank_2_wide_rectangle,
          full_matrices=False,
      )
  
      assert_evals_to_same_svd(
          rank_2_tall_rectangle, np_rank_2_tall_rectangle
      )
      assert_evals_to_same_svd(
          rank_2_tall_rectangle,
          np_rank_2_tall_rectangle,
          full_matrices=False,
      )
  
imports: import math
  import numpy
  import re
  from ..helpers import *
  import pytest
  from hail.utils.java import FatalError, HailUserError
label_desc: Use image node_id 26 for calling a global function with example usage: test_svd() without return types