def test_compute_nearest():
 x = rng.randn(500, 3)
 x /= np.sqrt(np.sum((x ** 2), axis=1))[:, None]
 nn_true = rng.permutation(np.arange(500, dtype=np.int))[:20]
 y = x[nn_true]
 nn1 = _compute_nearest(x, y, use_balltree=False)
 nn2 = _compute_nearest(x, y, use_balltree=True)
 assert_array_equal(nn_true, nn1)
 assert_array_equal(nn_true, nn2)
 nnn1 = _compute_nearest(x, y, use_balltree=False, return_dists=True)
 nnn2 = _compute_nearest(x, y, use_balltree=True, return_dists=True)
 assert_array_equal(nnn1[0], nn_true)
 assert_array_equal(nnn1[1], np.zeros_like(nn1))
 assert_equal(len(nnn1), len(nnn2))
 for (nn1, nn2) in zip(nnn1, nnn2):
  assert_array_equal(nn1, nn2)

def test_compute_nearest ( ) : x = rng . randn ( 500 , 3 ) x /= np . sqrt ( np . sum ( ( x ** 2 ) , axis = 1 ) ) [ : , None ] nn_true = rng . permutation ( np . arange ( 500 , dtype = np . int ) ) [ : 20 ] y = x [ nn_true ] nn1 = _compute_nearest ( x , y , use_balltree = False ) nn2 = _compute_nearest ( x , y , use_balltree = True ) assert_array_equal ( nn_true , nn1 ) assert_array_equal ( nn_true , nn2 ) nnn1 = _compute_nearest ( x , y , use_balltree = False , return_dists = True ) nnn2 = _compute_nearest ( x , y , use_balltree = True , return_dists = True ) assert_array_equal ( nnn1 [ 0 ] , nn_true ) assert_array_equal ( nnn1 [ 1 ] , np . zeros_like ( nn1 ) ) assert_equal ( len ( nnn1 ) , len ( nnn2 ) ) for ( nn1 , nn2 ) in zip ( nnn1 , nnn2 ) : assert_array_equal ( nn1 , nn2 )
test nearest neighbor searches .