Unverified Commit 30fb03a6 authored by Hongzhi (Steve), Chen's avatar Hongzhi (Steve), Chen Committed by GitHub
Browse files

Update example with spmatrix. (#5219)



* update

* graph
Co-authored-by: default avatarSteve <ubuntu@ip-172-31-34-29.ap-northeast-1.compute.internal>
parent abfc4c31
...@@ -94,9 +94,9 @@ if __name__ == "__main__": ...@@ -94,9 +94,9 @@ if __name__ == "__main__":
g = dataset[0].to(dev) g = dataset[0].to(dev)
# Create the sparse adjacency matrix A. # Create the sparse adjacency matrix A.
src, dst = g.edges() indices = torch.stack(g.edges())
N = g.num_nodes() 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. # Calculate the symmetrically normalized adjacency matrix.
I = dglsp.identity(A.shape, device=dev) I = dglsp.identity(A.shape, device=dev)
......
...@@ -99,9 +99,9 @@ if __name__ == "__main__": ...@@ -99,9 +99,9 @@ if __name__ == "__main__":
g = dataset[0].to(dev) g = dataset[0].to(dev)
# Create the sparse adjacency matrix A. # Create the sparse adjacency matrix A.
src, dst = g.edges() indices = torch.stack(g.edges())
N = g.num_nodes() 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. # Calculate the symmetrically normalized adjacency matrix.
I = dglsp.identity(A.shape, device=dev) I = dglsp.identity(A.shape, device=dev)
......
...@@ -123,9 +123,9 @@ if __name__ == "__main__": ...@@ -123,9 +123,9 @@ if __name__ == "__main__":
g = dataset[0].to(dev) g = dataset[0].to(dev)
# Create the sparse adjacency matrix A. # Create the sparse adjacency matrix A.
src, dst = g.edges() indices = torch.stack(g.edges())
N = g.num_nodes() N = g.num_nodes()
A = dglsp.from_coo(dst, src, shape=(N, N)) A = dglsp.spmatrix(indices, shape=(N, N))
# Add self-loops. # Add self-loops.
I = dglsp.identity(A.shape, device=dev) I = dglsp.identity(A.shape, device=dev)
......
...@@ -85,9 +85,9 @@ if __name__ == "__main__": ...@@ -85,9 +85,9 @@ if __name__ == "__main__":
X = g.ndata["feat"] X = g.ndata["feat"]
# Create the adjacency matrix of graph. # Create the adjacency matrix of graph.
src, dst = g.edges() indices = torch.stack(g.edges())
N = g.num_nodes() 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 # (HIGHLIGHT) Compute the symmetrically normalized adjacency matrix with
......
...@@ -137,9 +137,9 @@ if __name__ == "__main__": ...@@ -137,9 +137,9 @@ if __name__ == "__main__":
H = g.ndata["feat"] H = g.ndata["feat"]
# Create the adjacency matrix of graph. # Create the adjacency matrix of graph.
src, dst = g.edges() indices = torch.stack(g.edges())
N = g.num_nodes() 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 # (HIGHLIGHT) Compute the symmetrically normalized adjacency matrix with
......
...@@ -98,9 +98,9 @@ class GTModel(nn.Module): ...@@ -98,9 +98,9 @@ class GTModel(nn.Module):
) )
def forward(self, g, X, pos_enc): def forward(self, g, X, pos_enc):
src, dst = g.edges() indices = torch.stack(g.edges())
N = g.num_nodes() 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) h = self.atom_encoder(X) + self.pos_linear(pos_enc)
for layer in self.layers: for layer in self.layers:
h = layer(A, h) h = layer(A, h)
......
...@@ -71,8 +71,8 @@ def load_data(): ...@@ -71,8 +71,8 @@ def load_data():
# self-loops). # self-loops).
# We follow the paper and assume that the rows of the incidence matrix # We follow the paper and assume that the rows of the incidence matrix
# are for nodes and the columns are for edges. # are for nodes and the columns are for edges.
src, dst = graph.edges() indices = torch.stack(graph.edges())
H = dglsp.from_coo(dst, src) H = dglsp.spmatrix(indices)
H = H + dglsp.identity(H.shape) H = H + dglsp.identity(H.shape)
X = graph.ndata["feat"] X = graph.ndata["feat"]
......
...@@ -100,8 +100,8 @@ def load_data(): ...@@ -100,8 +100,8 @@ def load_data():
# self-loops). # self-loops).
# We follow the paper and assume that the rows of the incidence matrix # We follow the paper and assume that the rows of the incidence matrix
# are for nodes and the columns are for edges. # are for nodes and the columns are for edges.
src, dst = graph.edges() indices = torch.stack(graph.edges())
H = dglsp.from_coo(dst, src) H = dglsp.spmatrix(indices)
H = H + dglsp.identity(H.shape) H = H + dglsp.identity(H.shape)
X = graph.ndata["feat"] X = graph.ndata["feat"]
......
...@@ -69,9 +69,9 @@ if __name__ == "__main__": ...@@ -69,9 +69,9 @@ if __name__ == "__main__":
g = dataset[0].to(dev) g = dataset[0].to(dev)
# Create the sparse adjacency matrix A # Create the sparse adjacency matrix A
src, dst = g.edges() indices = torch.stack(g.edges())
N = g.num_nodes() 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. # Calculate the symmetrically normalized adjacency matrix.
I = dglsp.identity(A.shape, device=dev) I = dglsp.identity(A.shape, device=dev)
......
...@@ -102,9 +102,9 @@ if __name__ == "__main__": ...@@ -102,9 +102,9 @@ if __name__ == "__main__":
# Create the sparse adjacency matrix A (note that W was used as the notation # Create the sparse adjacency matrix A (note that W was used as the notation
# for adjacency matrix in the original paper). # for adjacency matrix in the original paper).
src, dst = g.edges() indices = torch.stack(g.edges())
N = g.num_nodes() 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. # Calculate the symmetrically normalized adjacency matrix.
I = dglsp.identity(A.shape, device=dev) I = dglsp.identity(A.shape, device=dev)
......
...@@ -184,9 +184,9 @@ if __name__ == "__main__": ...@@ -184,9 +184,9 @@ if __name__ == "__main__":
X = g.ndata["feat"] X = g.ndata["feat"]
# Create the sparse adjacency matrix A. # Create the sparse adjacency matrix A.
src, dst = g.edges() indices = torch.stack(g.edges())
N = g.num_nodes() N = g.num_nodes()
A = dglsp.from_coo(dst, src, shape=(N, N)) A = dglsp.spmatrix(indices, shape=(N, N))
# Create the TWIRLS model. # Create the TWIRLS model.
in_size = X.shape[1] in_size = X.shape[1]
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment