コード例 #1
0
ファイル: bench_knn_graph.py プロジェクト: yyzhuang1991/dgl
def track_time(size, dim, k):
    device = utils.get_bench_device()
    features = np.random.randn(size, dim)
    feat = torch.tensor(features, dtype=torch.float, device=device)
    # dry run
    dgl.knn_graph(feat, k)
    # timing
    with utils.Timer() as t:
        for i in range(10):
            dgl.knn_graph(feat, k)

    return t.elapsed_secs / 10
コード例 #2
0
def track_time(size, dim, k, algorithm):
    device = utils.get_bench_device()
    features = np.random.RandomState(42).randn(size, dim)
    feat = torch.tensor(features, dtype=torch.float, device=device)
    # dry run
    for i in range(1):
        dgl.knn_graph(feat, k, algorithm=algorithm)
    # timing
    with utils.Timer() as t:
        for i in range(5):
            dgl.knn_graph(feat, k, algorithm=algorithm)

    return t.elapsed_secs / 5
コード例 #3
0
def track_time(size, dim, k):
    device = utils.get_bench_device()
    features = np.random.randn(size, dim)
    feat = torch.tensor(features, dtype=torch.float, device=device)
    # dry run
    dgl.knn_graph(feat, k)
    # timing
    t0 = time.time()
    for i in range(10):
        dgl.knn_graph(feat, k)
    t1 = time.time()

    return (t1 - t0) / 10
コード例 #4
0
    def get_single_event(self, event_idx):

        # ------- building the cluster graph ---------- #

        cluster_cell_ID = self.ev_tree['cluster_cell_ID'].array(
            entry_start=event_idx, entry_stop=event_idx + 1, library='np')[0]
        cluster_cell_E = self.ev_tree['cluster_cell_E'].array(
            entry_start=event_idx, entry_stop=event_idx + 1, library='np')[0]

        n_clusters = len(cluster_cell_ID)

        if (n_clusters == 0):
            #print('Empty cluster event')
            return {
                'gr': [dgl.rand_graph(2, 1)],
                'truth_E': torch.tensor([-1.])
            }

        graph_list = []
        # ---- loop over clusters ---- #
        for ic in range(n_clusters):

            cell_E = np.array(cluster_cell_E[ic])
            cell_idx = np.array(cluster_cell_ID[ic])

            cluster_cell_pos = np.array(
                [self.id_to_position[x] for x in cell_idx])

            n_part = len(cluster_cell_pos)

            if (n_part < self.k):
                knn_g = dgl.knn_graph(torch.tensor(cluster_cell_pos), n_part)
            else:
                knn_g = dgl.knn_graph(torch.tensor(cluster_cell_pos), self.k)

            knn_g.ndata['x'] = torch.tensor(cluster_cell_pos)
            knn_g.ndata['en'] = torch.tensor(cell_E)

            graph_list.append(knn_g)
        # -------- #

        cluster_energy_truth = self.ev_tree['cluster_ENG_CALIB_TOT'].array(
            entry_start=event_idx, entry_stop=event_idx + 1, library='np')[0]
        # ---------------------------------------------------------------- #
        return {
            'gr': graph_list,
            'truth_E': torch.tensor(cluster_energy_truth)
        }
コード例 #5
0
ファイル: threaded_sampling.py プロジェクト: Carachias/3DMTK
 def savetotensfile(self):
     listtenstosave = []
     for each in self.sampcloud:
         vertex = []
         vertex.append(float(each[0]))
         vertex.append(float(each[1]))
         vertex.append(float(each[2]))
         listtenstosave.append(vertex)
     nodepostens = torch.tensor(listtenstosave)
     #print(nodepostens)
     print(len(nodepostens))
     knn_g_edges = dgl.knn_graph(nodepostens, k=20)
     print(knn_g_edges)
     torch.save(nodepostens.clone(), 'nodepostens.pt')
     torch.save(knn_g_edges.clone(), 'knn_g_edges.pt')
     self.signalStatus.emit('Tensor files saved')