def test_distance():
    u = np.array([[np.cos(0.), np.sin(0.)], [np.cos(0.5),
                                             np.sin(0.5)],
                  [np.cos(10.), np.sin(10.)]])
    v = np.array([[np.cos(0.5), np.sin(0.5)], [np.cos(0.5),
                                               np.sin(0.5)],
                  [np.cos(0.5), np.sin(0.5)]])
    expected = np.array([[0.5], [0.], [3.066370614359173]])

    circle = Sphere(1)
    assert_array_almost_equal(circle.distance(u, v), expected)
Exemple #2
0
 def compute_distances_zoo_topology(self):
     latencies = {}
     max_weight = 0
     min_weight = sys.maxint
     for n, nbrs in self.graph.adjacency_iter():
         for nbr, eattr in nbrs.items():
             log.info("edge {0}-{1}: {2}".format(n, nbr, str(eattr)))
             n, n_items = self.graph.nodes(data=True)[n]
             nbr, nbr_items = self.graph.nodes(data=True)[nbr]
             latencies[(n, nbr)] = float(Sphere.distance(n_items['Latitude'], n_items['Longitude'],
                                                         nbr_items['Latitude'], nbr_items['Longitude']) * 1000)/200000
             log.info("latency: {0}".format(latencies[(n, nbr)]))
     return latencies