Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
OpenDAS
dgl
Commits
f41934df
Unverified
Commit
f41934df
authored
Apr 20, 2023
by
czkkkkkk
Committed by
GitHub
Apr 20, 2023
Browse files
[Sparse] Add conversion between DGLGraph and SparseMatrix. (#5553)
parent
e6226e82
Changes
22
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
7 additions
and
7 deletions
+7
-7
tests/python/pytorch/nn/test_nn.py
tests/python/pytorch/nn/test_nn.py
+5
-5
tests/python/tensorflow/test_nn.py
tests/python/tensorflow/test_nn.py
+2
-2
No files found.
tests/python/pytorch/nn/test_nn.py
View file @
f41934df
...
...
@@ -35,7 +35,7 @@ def _AXWb(A, X, W, b):
def
test_graph_conv0
(
out_dim
):
g
=
dgl
.
DGLGraph
(
nx
.
path_graph
(
3
)).
to
(
F
.
ctx
())
ctx
=
F
.
ctx
()
adj
=
g
.
adj
acency_matrix
(
transpose
=
True
,
ctx
=
ctx
)
adj
=
g
.
adj
_external
(
transpose
=
True
,
ctx
=
ctx
)
conv
=
nn
.
GraphConv
(
5
,
out_dim
,
norm
=
"none"
,
bias
=
True
)
conv
=
conv
.
to
(
ctx
)
...
...
@@ -220,7 +220,7 @@ def test_tagconv(out_dim):
g
=
dgl
.
DGLGraph
(
nx
.
path_graph
(
3
))
g
=
g
.
to
(
F
.
ctx
())
ctx
=
F
.
ctx
()
adj
=
g
.
adj
acency_matrix
(
transpose
=
True
,
ctx
=
ctx
)
adj
=
g
.
adj
_external
(
transpose
=
True
,
ctx
=
ctx
)
norm
=
th
.
pow
(
g
.
in_degrees
().
float
(),
-
0.5
)
conv
=
nn
.
TAGConv
(
5
,
out_dim
,
bias
=
True
)
...
...
@@ -1140,7 +1140,7 @@ def test_dense_graph_conv(norm_type, g, idtype, out_dim):
g
=
g
.
astype
(
idtype
).
to
(
F
.
ctx
())
ctx
=
F
.
ctx
()
# TODO(minjie): enable the following option after #1385
adj
=
g
.
adj
acency_matrix
(
transpose
=
True
,
ctx
=
ctx
).
to_dense
()
adj
=
g
.
adj
_external
(
transpose
=
True
,
ctx
=
ctx
).
to_dense
()
conv
=
nn
.
GraphConv
(
5
,
out_dim
,
norm
=
norm_type
,
bias
=
True
)
dense_conv
=
nn
.
DenseGraphConv
(
5
,
out_dim
,
norm
=
norm_type
,
bias
=
True
)
dense_conv
.
weight
.
data
=
conv
.
weight
.
data
...
...
@@ -1159,7 +1159,7 @@ def test_dense_graph_conv(norm_type, g, idtype, out_dim):
def
test_dense_sage_conv
(
g
,
idtype
,
out_dim
):
g
=
g
.
astype
(
idtype
).
to
(
F
.
ctx
())
ctx
=
F
.
ctx
()
adj
=
g
.
adj
acency_matrix
(
transpose
=
True
,
ctx
=
ctx
).
to_dense
()
adj
=
g
.
adj
_external
(
transpose
=
True
,
ctx
=
ctx
).
to_dense
()
sage
=
nn
.
SAGEConv
(
5
,
out_dim
,
"gcn"
)
dense_sage
=
nn
.
DenseSAGEConv
(
5
,
out_dim
)
dense_sage
.
fc
.
weight
.
data
=
sage
.
fc_neigh
.
weight
.
data
...
...
@@ -1258,7 +1258,7 @@ def test_dense_cheb_conv(out_dim):
ctx
=
F
.
ctx
()
g
=
dgl
.
DGLGraph
(
sp
.
sparse
.
random
(
100
,
100
,
density
=
0.1
),
readonly
=
True
)
g
=
g
.
to
(
F
.
ctx
())
adj
=
g
.
adj
acency_matrix
(
transpose
=
True
,
ctx
=
ctx
).
to_dense
()
adj
=
g
.
adj
_external
(
transpose
=
True
,
ctx
=
ctx
).
to_dense
()
cheb
=
nn
.
ChebConv
(
5
,
out_dim
,
k
,
None
)
dense_cheb
=
nn
.
DenseChebConv
(
5
,
out_dim
,
k
)
# for i in range(len(cheb.fc)):
...
...
tests/python/tensorflow/test_nn.py
View file @
f41934df
...
...
@@ -31,7 +31,7 @@ def test_graph_conv(out_dim):
g
=
dgl
.
DGLGraph
(
nx
.
path_graph
(
3
)).
to
(
F
.
ctx
())
ctx
=
F
.
ctx
()
adj
=
tf
.
sparse
.
to_dense
(
tf
.
sparse
.
reorder
(
g
.
adj
acency_matrix
(
transpose
=
True
,
ctx
=
ctx
))
tf
.
sparse
.
reorder
(
g
.
adj
_external
(
transpose
=
True
,
ctx
=
ctx
))
)
conv
=
nn
.
GraphConv
(
5
,
out_dim
,
norm
=
"none"
,
bias
=
True
)
...
...
@@ -610,7 +610,7 @@ def test_dense_cheb_conv(out_dim):
g
=
g
.
to
(
ctx
)
adj
=
tf
.
sparse
.
to_dense
(
tf
.
sparse
.
reorder
(
g
.
adj
acency_matrix
(
transpose
=
True
,
ctx
=
ctx
))
tf
.
sparse
.
reorder
(
g
.
adj
_external
(
transpose
=
True
,
ctx
=
ctx
))
)
cheb
=
nn
.
ChebConv
(
5
,
out_dim
,
k
,
None
,
bias
=
True
)
dense_cheb
=
nn
.
DenseChebConv
(
5
,
out_dim
,
k
,
bias
=
True
)
...
...
Prev
1
2
Next
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment