#NEWLINE# def test_ckdtree_query_pairs( ) : #NEWLINE# #INDENT# np . random . seed ( 0 ) #NEWLINE# n = 50 #NEWLINE# k = 2 #NEWLINE# r = 0.1 #NEWLINE# r2 = ( r ** 2 ) #NEWLINE# points = np . random . randn ( n , k ) #NEWLINE# T = cKDTree ( points ) #NEWLINE# brute = set ( ) #NEWLINE# for i in range ( n ) : #NEWLINE# #INDENT# for j in range ( ( i + 1 ) , n ) : #NEWLINE# #INDENT# v = ( points [ i , : ] - points [ j , : ] ) #NEWLINE# if ( np . dot ( v , v ) <= r2 ) : #NEWLINE# #INDENT# brute . add ( ( i , j ) ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# l0 = sorted ( brute ) #NEWLINE# s = T . query_pairs ( r ) #NEWLINE# l1 = sorted ( s ) #NEWLINE# assert_array_equal ( l0 , brute ) #NEWLINE# s = T . query_pairs ( r , output_type = 'set' ) #NEWLINE# l1 = sorted ( s ) #NEWLINE# assert_array_equal ( l0 , l1 ) #NEWLINE# s = set ( ) #NEWLINE# arr = T . query_pairs ( r , output_type = 'ndarray' ) #NEWLINE# for i in range ( arr . shape [ 0 ] ) : #NEWLINE# #INDENT# s . add ( ( int ( arr [ ( i , 0 ) ] ) , int ( arr [ ( i , 1 ) ] ) ) ) #NEWLINE# #UNINDENT# l2 = sorted ( s ) #NEWLINE# assert_array_equal ( l0 , l2 )