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
5119a504
"git@developer.sourcefind.cn:renzhc/diffusers_dcu.git" did not exist on "98457580c061a182e2f99cd9fb80f73db386cc59"
Commit
5119a504
authored
Oct 08, 2018
by
GaiYu0
Browse files
sparse line graph
parent
905db292
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
15 additions
and
5 deletions
+15
-5
python/dgl/graph_index.py
python/dgl/graph_index.py
+13
-3
tests/test_lg.py
tests/test_lg.py
+2
-2
No files found.
python/dgl/graph_index.py
View file @
5119a504
...
@@ -519,12 +519,22 @@ class GraphIndex(object):
...
@@ -519,12 +519,22 @@ class GraphIndex(object):
The line graph of this graph.
The line graph of this graph.
"""
"""
m
=
self
.
number_of_edges
()
m
=
self
.
number_of_edges
()
ctx
=
F
.
get_context
(
F
.
ones
(
1
))
# TODO(gaiyu):
ctx
=
F
.
get_context
(
F
.
ones
(
1
))
inc
=
F
.
to_scipy_sparse
(
self
.
incidence_matrix
(
oriented
=
True
).
get
(
ctx
))
inc
=
F
.
to_scipy_sparse
(
self
.
incidence_matrix
(
oriented
=
True
).
get
(
ctx
))
adj
=
inc
.
transpose
().
dot
(
inc
)
adj
=
inc
.
transpose
().
dot
(
inc
)
.
tocoo
()
adj
.
data
[
adj
.
data
!=
-
1
]
=
0
adj
.
data
[
adj
.
data
!=
-
1
]
=
0
adj
.
eliminate_zeros
()
adj
.
eliminate_zeros
()
adj
=
sp
.
triu
(
adj
)
u
,
v
,
_
=
self
.
edges
(
sorted
=
True
)
# TODO(gaiyu): sorted
u
=
u
.
tousertensor
()
v
=
v
.
tousertensor
()
src
=
F
.
gather_row
(
v
,
F
.
tensor
(
adj
.
row
,
dtype
=
F
.
int64
))
dst
=
F
.
gather_row
(
u
,
F
.
tensor
(
adj
.
col
,
dtype
=
F
.
int64
))
dat
=
F
.
tensor
(
adj
.
data
)
dat
[
src
!=
dst
]
=
0
adj
.
data
=
dat
.
numpy
()
adj
.
eliminate_zeros
()
lg
=
create_graph_index
()
lg
=
create_graph_index
()
lg
.
from_scipy_sparse_matrix
(
adj
)
lg
.
from_scipy_sparse_matrix
(
adj
)
return
lg
return
lg
...
...
tests/test_lg.py
View file @
5119a504
...
@@ -17,5 +17,5 @@ assert lg_sparse.number_of_edges() == lg_cpp.number_of_edges()
...
@@ -17,5 +17,5 @@ assert lg_sparse.number_of_edges() == lg_cpp.number_of_edges()
src_sparse
,
dst_sparse
,
_
=
lg_sparse
.
edges
(
sorted
=
True
)
src_sparse
,
dst_sparse
,
_
=
lg_sparse
.
edges
(
sorted
=
True
)
src_cpp
,
dst_cpp
,
_
=
lg_cpp
.
edges
(
sorted
=
True
)
src_cpp
,
dst_cpp
,
_
=
lg_cpp
.
edges
(
sorted
=
True
)
#
assert (src_sparse == src_cpp).all()
assert
(
src_sparse
==
src_cpp
).
all
()
#
assert (dst_sparse == dst_cpp).all()
assert
(
dst_sparse
==
dst_cpp
).
all
()
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