Esempio n. 1
0
 def test_prune_discrete(self):
     """
     Testing prune_discrete function with beta/lp specified.
     """
     self.setup()
     ngl_edges = ngl.prune(self.X, self.edges, steps=100)
     edge_set = create_edge_set(ngl_edges)
     self.assertEqual(len(self.gold_strict ^ edge_set), 0, '')
Esempio n. 2
0
 def test_prune(self):
     """
     Testing prune function
     """
     self.setup()
     ngl_edges = ngl.prune(self.X, self.edges)
     edge_set = create_edge_set(ngl_edges)
     self.assertEqual(len(self.gold_strict ^ edge_set), 0, '')
Esempio n. 3
0
    def populate_chunk(self, start_index):
        end_index = min(start_index + self.query_size, self.X.shape[0])
        count = end_index - start_index
        working_set = np.array(range(start_index, end_index))

        distances, edges = self.nn_index.search(working_set,
                                                self.max_neighbors)

        indices = working_set
        # We will need the locations of these additional points since
        # we need to know if they fall into the empty region of any
        # edges above
        additional_indices = np.setdiff1d(edges.ravel(), working_set)

        if additional_indices.shape[0] > 0:
            # It is possible that we cannot store the entirety of X
            # and edges on the GPU, so figure out the subset of Xs and
            # carefully replace the edges values
            indices = np.hstack((working_set, additional_indices))
            if not self.relaxed:
                neighbor_edges = self.nn_index.search(additional_indices,
                                                      self.max_neighbors,
                                                      False)

                # We don't care about whether any of the edges of these
                # extra rows are valid yet, but the algorithm will need
                # them to prune correctly
                edges = np.vstack((edges, neighbor_edges))

                # Since we will be using the edges above for queries, we
                # need to make sure we have the locations of everything
                # they touch
                neighbor_indices = np.setdiff1d(neighbor_edges.ravel(),
                                                indices)

                if neighbor_indices.shape[0] > 0:
                    indices = np.hstack((indices, neighbor_indices))

        indices = indices.astype(i32)
        X = self.X[indices, :]
        edges = ngl.prune(X,
                          edges,
                          indices=indices,
                          relaxed=self.relaxed,
                          steps=self.discrete_steps,
                          beta=self.beta,
                          lp=self.p,
                          count=count)

        # We will cache these for later use
        self.edges[start_index:end_index, :] = edges[:count]
        self.distances[start_index:end_index, :] = distances[:count]

        # Since, we are taking a lot of time to generate these, then we
        # should give the user something to process in the meantime, so
        # don't remove these lines and make sure to return in the main
        # populate before the same process is done again.
        self.push_edges(edges[:count], distances[:count], indices[:count])
Esempio n. 4
0
 def test_prune_discrete_template(self):
     """
     Testing prune_discrete fucntion with template specified
     """
     self.setup()
     template = np.array(ngl.create_template(1, 2, 100), dtype=f32)
     ngl_edges = ngl.prune(self.X, self.edges, template=template)
     edge_set = create_edge_set(ngl_edges)
     self.assertEqual(len(self.gold_strict ^ edge_set), 0, '')
Esempio n. 5
0
 def test_get_edge_list(self):
     """
     Testing get_edge_list function
     """
     self.setup()
     ngl_edges = ngl.prune(self.X, self.edges)
     edge_list = ngl.get_edge_list(ngl_edges, np.zeros(ngl_edges.shape))
     edge_set = set()
     for (p, q, d) in edge_list:
         lo = min(p, q)
         hi = max(p, q)
         edge_set.add((lo, hi))
     self.assertEqual(len(self.gold_strict ^ edge_set), 0, '')
Esempio n. 6
0
    def populate_whole(self):
        count = self.X.shape[0]
        working_set = np.array(range(count))
        distances, edges = self.nn_index.search(working_set,
                                                self.max_neighbors)

        edges = ngl.prune(self.X,
                          edges,
                          relaxed=self.relaxed,
                          steps=self.discrete_steps,
                          beta=self.beta,
                          lp=self.p)

        self.edges = edges
        self.distances = distances