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
03f251ce
Unverified
Commit
03f251ce
authored
Jul 31, 2020
by
Zihao Ye
Committed by
GitHub
Jul 31, 2020
Browse files
upd (#1905)
parent
a28bfa9f
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
7 additions
and
18 deletions
+7
-18
python/dgl/transform.py
python/dgl/transform.py
+3
-3
tests/compute/test_graph.py
tests/compute/test_graph.py
+4
-15
No files found.
python/dgl/transform.py
View file @
03f251ce
...
...
@@ -386,7 +386,7 @@ def khop_adj(g, k):
[1., 3., 3., 1., 0.],
[0., 1., 3., 3., 1.]])
"""
adj_k
=
g
.
adj
acency_matrix_scipy
(
return_edge_ids
=
False
)
**
k
adj_k
=
g
.
adj
(
scipy_fmt
=
g
.
formats
()[
'created'
][
0
]
)
**
k
return
F
.
tensor
(
adj_k
.
todense
().
astype
(
np
.
float32
))
def
khop_graph
(
g
,
k
):
...
...
@@ -435,7 +435,7 @@ def khop_graph(g, k):
edata_schemes={})
"""
n
=
g
.
number_of_nodes
()
adj_k
=
g
.
adj
acency_matrix_scipy
(
transpose
=
True
,
return_edge_ids
=
False
)
**
k
adj_k
=
g
.
adj
(
transpose
=
True
,
scipy_fmt
=
g
.
formats
()[
'created'
][
0
]
)
**
k
adj_k
=
adj_k
.
tocoo
()
multiplicity
=
adj_k
.
data
row
=
np
.
repeat
(
adj_k
.
row
,
multiplicity
)
...
...
@@ -687,7 +687,7 @@ def laplacian_lambda_max(g):
rst
=
[]
for
g_i
in
g_arr
:
n
=
g_i
.
number_of_nodes
()
adj
=
g_i
.
adj
acency_matrix_scipy
(
return_edge_ids
=
False
).
astype
(
float
)
adj
=
g_i
.
adj
(
scipy_fmt
=
g_i
.
formats
()[
'created'
][
0
]
).
astype
(
float
)
norm
=
sparse
.
diags
(
F
.
asnumpy
(
g_i
.
in_degrees
()).
clip
(
1
)
**
-
0.5
,
dtype
=
float
)
laplacian
=
sparse
.
eye
(
n
)
-
norm
*
adj
*
norm
rst
.
append
(
sparse
.
linalg
.
eigs
(
laplacian
,
1
,
which
=
'LM'
,
...
...
tests/compute/test_graph.py
View file @
03f251ce
...
...
@@ -253,25 +253,14 @@ def test_scipy_adjmat():
g
.
add_nodes
(
10
)
g
.
add_edges
(
range
(
9
),
range
(
1
,
10
))
adj_0
=
g
.
adj
acency_matrix_scipy
(
)
adj_1
=
g
.
adj
acency_matrix_
scipy
(
fmt
=
'coo'
)
adj_0
=
g
.
adj
(
scipy_fmt
=
'csr'
)
adj_1
=
g
.
adj
(
scipy
_
fmt
=
'coo'
)
assert
np
.
array_equal
(
adj_0
.
toarray
(),
adj_1
.
toarray
())
adj_t0
=
g
.
adj
acency_matrix_scipy
(
transpose
=
True
)
adj_t_1
=
g
.
adj
acency_matrix_scipy
(
transpose
=
True
,
fmt
=
'coo'
)
adj_t0
=
g
.
adj
(
transpose
=
True
,
scipy_fmt
=
'csr'
)
adj_t_1
=
g
.
adj
(
transpose
=
True
,
scipy_
fmt
=
'coo'
)
assert
np
.
array_equal
(
adj_0
.
toarray
(),
adj_1
.
toarray
())
g
.
readonly
()
adj_2
=
g
.
adjacency_matrix_scipy
()
adj_3
=
g
.
adjacency_matrix_scipy
(
fmt
=
'coo'
)
assert
np
.
array_equal
(
adj_2
.
toarray
(),
adj_3
.
toarray
())
assert
np
.
array_equal
(
adj_0
.
toarray
(),
adj_2
.
toarray
())
adj_t2
=
g
.
adjacency_matrix_scipy
(
transpose
=
True
)
adj_t3
=
g
.
adjacency_matrix_scipy
(
transpose
=
True
,
fmt
=
'coo'
)
assert
np
.
array_equal
(
adj_t2
.
toarray
(),
adj_t3
.
toarray
())
assert
np
.
array_equal
(
adj_t0
.
toarray
(),
adj_t2
.
toarray
())
def
test_incmat
():
g
=
dgl
.
DGLGraph
()
g
.
add_nodes
(
4
)
...
...
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