MCPcopy Create free account
hub / github.com/GGA23/GrokFormer / eig_dgl_adj_sparse

Function eig_dgl_adj_sparse

preprocess_node_data.py:134–161  ·  view source on GitHub ↗
(g, sm=0, lm=0)

Source from the content-addressed store, hash-verified

132
133
134def eig_dgl_adj_sparse(g, sm=0, lm=0):
135 #A = g.adj(scipy_fmt='csr')
136 #adj_matrix = dgl.to_scipy(g)
137 #A = csr_matrix(adj_matrix)
138 adj_matrix = g.adjacency_matrix().to_dense().numpy()
139 A = csr_matrix(adj_matrix)
140 deg = np.array(A.sum(axis=0)).flatten()
141 D_ = sp.sparse.diags(deg ** -0.5)
142
143 A_ = D_.dot(A.dot(D_))
144 L_ = sp.sparse.eye(g.num_nodes()) - A_
145
146 if sm > 0:
147 e1, u1 = sp.sparse.linalg.eigsh(L_, k=sm, which='SM', tol=1e-5)
148 e1, u1 = map(torch.FloatTensor, (e1, u1))
149
150 if lm > 0:
151 e2, u2 = sp.sparse.linalg.eigsh(L_, k=lm, which='LM', tol=1e-5)
152 e2, u2 = map(torch.FloatTensor, (e2, u2))
153
154 if sm > 0 and lm > 0:
155 return torch.cat((e1, e2), dim=0), torch.cat((u1, u2), dim=1)
156 elif sm > 0:
157 return e1, u1
158 elif lm > 0:
159 return e2, u2
160 else:
161 pass
162
163
164def load_fb100_dataset():

Callers 1

generate_node_dataFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected