code: def test_nearest_pos_semi_def():
      B = np.diag(np.array([1, 2, 3]))
      assert_array_almost_equal(B, nearest_pos_semi_def(B))
      B = np.diag(np.array([0, 2, 3]))
      assert_array_almost_equal(B, nearest_pos_semi_def(B))
      B = np.diag(np.array([0, 0, 3]))
      assert_array_almost_equal(B, nearest_pos_semi_def(B))
      B = np.diag(np.array([-1, 2, 3]))
      Bpsd = np.array(
          [[0.0, 0.0, 0.0], [0.0, 1.75, 0.0], [0.0, 0.0, 2.75]]
      )
      assert_array_almost_equal(Bpsd, nearest_pos_semi_def(B))
      B = np.diag(np.array([-1, -2, 3]))
      Bpsd = np.array(
          [[0.0, 0.0, 0.0], [0.0, 0.0, 0.0], [0.0, 0.0, 2.0]]
      )
      assert_array_almost_equal(Bpsd, nearest_pos_semi_def(B))
      B = np.diag(np.array([-1.0e-11, 0, 1000]))
      Bpsd = np.array(
          [[0.0, 0.0, 0.0], [0.0, 0.0, 0.0], [0.0, 0.0, 1000.0]]
      )
      assert_array_almost_equal(Bpsd, nearest_pos_semi_def(B))
      B = np.diag(np.array([-1, -2, -3]))
      Bpsd = np.array(
          [[0.0, 0.0, 0.0], [0.0, 0.0, 0.0], [0.0, 0.0, 0.0]]
      )
      assert_array_almost_equal(Bpsd, nearest_pos_semi_def(B))
  
imports: import numpy
  import random
  from dipy.core.geometry import sphere2cart, cart2sphere, nearest_pos_semi_def, sphere_distance, cart_distance, vector_cosine, lambert_equal_area_projection_polar, circumradius, vec2vec_rotmat, vector_norm, compose_transformations, compose_matrix, decompose_matrix, perpendicular_directions, dist_to_corner, is_hemispherical
  from numpy.testing import assert_array_equal, assert_array_almost_equal, assert_equal, assert_raises, assert_almost_equal
  from dipy.testing.spherepoints import sphere_points
  from dipy.testing.decorators import set_random_number_generator
  from dipy.core.sphere_stats import random_uniform_on_sphere
  from itertools import permutations
label_desc: Use image node_id 4 for calling a global function with example usage: test_nearest_pos_semi_def() without return types