mirror of
https://github.com/dmlc/dgl.git
synced 2026-06-04 19:44:23 +08:00
Update example with spmatrix. (#5219)
* update * graph Co-authored-by: Steve <ubuntu@ip-172-31-34-29.ap-northeast-1.compute.internal>
This commit is contained in:
committed by
GitHub
parent
abfc4c31f5
commit
30fb03a6bc
@@ -94,9 +94,9 @@ if __name__ == "__main__":
|
||||
g = dataset[0].to(dev)
|
||||
|
||||
# Create the sparse adjacency matrix A.
|
||||
src, dst = g.edges()
|
||||
indices = torch.stack(g.edges())
|
||||
N = g.num_nodes()
|
||||
A = dglsp.from_coo(dst, src, shape=(N, N))
|
||||
A = dglsp.spmatrix(indices, shape=(N, N))
|
||||
|
||||
# Calculate the symmetrically normalized adjacency matrix.
|
||||
I = dglsp.identity(A.shape, device=dev)
|
||||
|
||||
@@ -99,9 +99,9 @@ if __name__ == "__main__":
|
||||
g = dataset[0].to(dev)
|
||||
|
||||
# Create the sparse adjacency matrix A.
|
||||
src, dst = g.edges()
|
||||
indices = torch.stack(g.edges())
|
||||
N = g.num_nodes()
|
||||
A = dglsp.from_coo(dst, src, shape=(N, N))
|
||||
A = dglsp.spmatrix(indices, shape=(N, N))
|
||||
|
||||
# Calculate the symmetrically normalized adjacency matrix.
|
||||
I = dglsp.identity(A.shape, device=dev)
|
||||
|
||||
@@ -123,9 +123,9 @@ if __name__ == "__main__":
|
||||
g = dataset[0].to(dev)
|
||||
|
||||
# Create the sparse adjacency matrix A.
|
||||
src, dst = g.edges()
|
||||
indices = torch.stack(g.edges())
|
||||
N = g.num_nodes()
|
||||
A = dglsp.from_coo(dst, src, shape=(N, N))
|
||||
A = dglsp.spmatrix(indices, shape=(N, N))
|
||||
|
||||
# Add self-loops.
|
||||
I = dglsp.identity(A.shape, device=dev)
|
||||
|
||||
@@ -85,9 +85,9 @@ if __name__ == "__main__":
|
||||
X = g.ndata["feat"]
|
||||
|
||||
# Create the adjacency matrix of graph.
|
||||
src, dst = g.edges()
|
||||
indices = torch.stack(g.edges())
|
||||
N = g.num_nodes()
|
||||
A = dglsp.from_coo(dst, src, shape=(N, N))
|
||||
A = dglsp.spmatrix(indices, shape=(N, N))
|
||||
|
||||
############################################################################
|
||||
# (HIGHLIGHT) Compute the symmetrically normalized adjacency matrix with
|
||||
|
||||
@@ -137,9 +137,9 @@ if __name__ == "__main__":
|
||||
H = g.ndata["feat"]
|
||||
|
||||
# Create the adjacency matrix of graph.
|
||||
src, dst = g.edges()
|
||||
indices = torch.stack(g.edges())
|
||||
N = g.num_nodes()
|
||||
A = dglsp.from_coo(dst, src, shape=(N, N))
|
||||
A = dglsp.spmatrix(indices, shape=(N, N))
|
||||
|
||||
############################################################################
|
||||
# (HIGHLIGHT) Compute the symmetrically normalized adjacency matrix with
|
||||
|
||||
@@ -98,9 +98,9 @@ class GTModel(nn.Module):
|
||||
)
|
||||
|
||||
def forward(self, g, X, pos_enc):
|
||||
src, dst = g.edges()
|
||||
indices = torch.stack(g.edges())
|
||||
N = g.num_nodes()
|
||||
A = dglsp.from_coo(dst, src, shape=(N, N))
|
||||
A = dglsp.spmatrix(indices, shape=(N, N))
|
||||
h = self.atom_encoder(X) + self.pos_linear(pos_enc)
|
||||
for layer in self.layers:
|
||||
h = layer(A, h)
|
||||
|
||||
@@ -71,8 +71,8 @@ def load_data():
|
||||
# self-loops).
|
||||
# We follow the paper and assume that the rows of the incidence matrix
|
||||
# are for nodes and the columns are for edges.
|
||||
src, dst = graph.edges()
|
||||
H = dglsp.from_coo(dst, src)
|
||||
indices = torch.stack(graph.edges())
|
||||
H = dglsp.spmatrix(indices)
|
||||
H = H + dglsp.identity(H.shape)
|
||||
|
||||
X = graph.ndata["feat"]
|
||||
|
||||
@@ -100,8 +100,8 @@ def load_data():
|
||||
# self-loops).
|
||||
# We follow the paper and assume that the rows of the incidence matrix
|
||||
# are for nodes and the columns are for edges.
|
||||
src, dst = graph.edges()
|
||||
H = dglsp.from_coo(dst, src)
|
||||
indices = torch.stack(graph.edges())
|
||||
H = dglsp.spmatrix(indices)
|
||||
H = H + dglsp.identity(H.shape)
|
||||
|
||||
X = graph.ndata["feat"]
|
||||
|
||||
@@ -69,9 +69,9 @@ if __name__ == "__main__":
|
||||
g = dataset[0].to(dev)
|
||||
|
||||
# Create the sparse adjacency matrix A
|
||||
src, dst = g.edges()
|
||||
indices = torch.stack(g.edges())
|
||||
N = g.num_nodes()
|
||||
A = dglsp.from_coo(dst, src, shape=(N, N))
|
||||
A = dglsp.spmatrix(indices, shape=(N, N))
|
||||
|
||||
# Calculate the symmetrically normalized adjacency matrix.
|
||||
I = dglsp.identity(A.shape, device=dev)
|
||||
|
||||
@@ -102,9 +102,9 @@ if __name__ == "__main__":
|
||||
|
||||
# Create the sparse adjacency matrix A (note that W was used as the notation
|
||||
# for adjacency matrix in the original paper).
|
||||
src, dst = g.edges()
|
||||
indices = torch.stack(g.edges())
|
||||
N = g.num_nodes()
|
||||
A = dglsp.from_coo(dst, src, shape=(N, N))
|
||||
A = dglsp.spmatrix(indices, shape=(N, N))
|
||||
|
||||
# Calculate the symmetrically normalized adjacency matrix.
|
||||
I = dglsp.identity(A.shape, device=dev)
|
||||
|
||||
@@ -184,9 +184,9 @@ if __name__ == "__main__":
|
||||
X = g.ndata["feat"]
|
||||
|
||||
# Create the sparse adjacency matrix A.
|
||||
src, dst = g.edges()
|
||||
indices = torch.stack(g.edges())
|
||||
N = g.num_nodes()
|
||||
A = dglsp.from_coo(dst, src, shape=(N, N))
|
||||
A = dglsp.spmatrix(indices, shape=(N, N))
|
||||
|
||||
# Create the TWIRLS model.
|
||||
in_size = X.shape[1]
|
||||
|
||||
Reference in New Issue
Block a user