#NEWLINE# def test_haversine_metric( ) : #NEWLINE# #INDENT# def haversine_slow( x1 , x2 ) : #NEWLINE# #INDENT# return ( 2 * np . arcsin ( np . sqrt ( ( ( np . sin ( ( 0.5 * ( x1 [ 0 ] - x2 [ 0 ] ) ) ) ** 2 ) + ( ( np . cos ( x1 [ 0 ] ) * np . cos ( x2 [ 0 ] ) ) * ( np . sin ( ( 0.5 * ( x1 [ 1 ] - x2 [ 1 ] ) ) ) ** 2 ) ) ) ) ) ) #NEWLINE# #UNINDENT# X = np . random . random ( ( 10 , 2 ) ) #NEWLINE# haversine = DistanceMetric . get_metric ( 'haversine' ) #NEWLINE# D1 = haversine . pairwise ( X ) #NEWLINE# D2 = np . zeros_like ( D1 ) #NEWLINE# for ( i , x1 ) in enumerate ( X ) : #NEWLINE# #INDENT# for ( j , x2 ) in enumerate ( X ) : #NEWLINE# #INDENT# D2 [ ( i , j ) ] = haversine_slow ( x1 , x2 ) #NEWLINE# #UNINDENT# #UNINDENT# assert_array_almost_equal ( D1 , D2 ) #NEWLINE# assert_array_almost_equal ( haversine . dist_to_rdist ( D1 ) , ( np . sin ( ( 0.5 * D2 ) ) ** 2 ) )