old_contents: from nose.tools import assert_greater_equal
  
  import numpy as np
  from pynndescent import NNDescent
  from sklearn.neighbors import KDTree
  from sklearn.preprocessing import normalize
  
  np.random.seed(42)
  spatial_data = np.random.randn(10, 20)
  spatial_data = np.vstack(
      [spatial_data, np.zeros((2, 20))]
  )  # Add some all zero data for corner case test
  nn_data = np.random.uniform(0, 1, size=(1000, 5))
  nn_data = np.vstack(
      [nn_data, np.zeros((2, 5))]
  )  # Add some all zero data for corner case test
  
  def test_nn_descent_neighbor_accuracy():
      knn_indices, knn_dists = NNDescent(
          nn_data, "euclidean", {}, 10, random_state=np.random
      )._neighbor_graph
  
      tree = KDTree(nn_data)
      true_indices = tree.query(nn_data, 10, return_distance=False)
  
      num_correct = 0.0
      for i in range(nn_data.shape[0]):
          num_correct += np.sum(np.in1d(true_indices[i], knn_indices[i]))
  
      percent_correct = num_correct / (spatial_data.shape[0] * 10)
      assert_greater_equal(
          percent_correct,
          0.99,
          "NN-descent did not get 99% " "accuracy on nearest neighbors",
      )
  
  
  def test_angular_nn_descent_neighbor_accuracy():
      knn_indices, knn_dists = NNDescent(
          nn_data, "cosine", {}, 10, random_state=np.random
      )._neighbor_graph
  
      angular_data = normalize(nn_data, norm="l2")
      tree = KDTree(angular_data)
      true_indices = tree.query(angular_data, 10, return_distance=False)
  
      num_correct = 0.0
      for i in range(nn_data.shape[0]):
          num_correct += np.sum(np.in1d(true_indices[i], knn_indices[i]))
  
      percent_correct = num_correct / (spatial_data.shape[0] * 10)
      assert_greater_equal(
          percent_correct,
          0.99,
          "NN-descent did not get 99% " "accuracy on nearest neighbors",
      )
new_contents: from nose.tools import assert_greater_equal
  
  import numpy as np
  from pynndescent import NNDescent
  from sklearn.neighbors import KDTree
  from sklearn.preprocessing import normalize
  
  np.random.seed(42)
  spatial_data = np.random.randn(10, 20)
  spatial_data = np.vstack(
      [spatial_data, np.zeros((2, 20))]
  )  # Add some all zero data for corner case test
  nn_data = np.random.uniform(0, 1, size=(1000, 5))
  nn_data = np.vstack(
      [nn_data, np.zeros((2, 5))]
  )  # Add some all zero data for corner case test
  
  def test_nn_descent_neighbor_accuracy():
      knn_indices, knn_dists = NNDescent(
          nn_data, "euclidean", {}, 10, random_state=np.random
      )._neighbor_graph
  
      tree = KDTree(nn_data)
      true_indices = tree.query(nn_data, 10, return_distance=False)
  
      num_correct = 0.0
      for i in range(nn_data.shape[0]):
          num_correct += np.sum(np.in1d(true_indices[i], knn_indices[i]))
  
      percent_correct = num_correct / (spatial_data.shape[0] * 10)
      assert_greater_equal(
          percent_correct,
          0.99,
          "NN-descent did not get 99% " "accuracy on nearest neighbors",
      )
  
  
  def test_angular_nn_descent_neighbor_accuracy():
      knn_indices, knn_dists = NNDescent(
          nn_data, "cosine", {}, 10, random_state=np.random
      )._neighbor_graph
  
      angular_data = normalize(nn_data, norm="l2")
      tree = KDTree(angular_data)
      true_indices = tree.query(angular_data, 10, return_distance=False)
  
      num_correct = 0.0
      for i in range(nn_data.shape[0]):
          num_correct += np.sum(np.in1d(true_indices[i], knn_indices[i]))
  
      percent_correct = num_correct / (spatial_data.shape[0] * 10)
      assert_greater_equal(
          percent_correct,
          0.99,
          "NN-descent did not get 99% " "accuracy on nearest neighbors",
      )
  
  
  def test_deterministic():
      seed = np.random.RandomState(42)
  
      x1 = seed.normal(0, 100, (1000, 50))
      x2 = seed.normal(0, 100, (1000, 50))
  
      index1 = NNDescent(x1, random_state=np.random.RandomState(42))
      neighbors1, distances1 = index1.query(x2)
  
      index2 = NNDescent(x1, random_state=np.random.RandomState(42))
      neighbors2, distances2 = index2.query(x2)
  
      np.testing.assert_equal(neighbors1, neighbors2)
      np.testing.assert_equal(distances1, distances2)
  
subject: Test that setting random_state for NNDescent produces deterministic outputs.