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
d2ccd218
Unverified
Commit
d2ccd218
authored
Aug 04, 2020
by
Zihao Ye
Committed by
GitHub
Aug 04, 2020
Browse files
[hotfix] Allow creating graph from edges with restrict formats excluding coo. (#1926)
* upd * upd * upd * upd
parent
ca5a13fe
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
13 additions
and
9 deletions
+13
-9
python/dgl/convert.py
python/dgl/convert.py
+6
-2
tests/compute/test_heterograph.py
tests/compute/test_heterograph.py
+7
-7
No files found.
python/dgl/convert.py
View file @
d2ccd218
...
...
@@ -1016,8 +1016,12 @@ def create_from_edges(u, v,
else
:
num_ntypes
=
2
if
'coo'
in
formats
:
hgidx
=
heterograph_index
.
create_unitgraph_from_coo
(
num_ntypes
,
urange
,
vrange
,
u
,
v
,
formats
)
else
:
hgidx
=
heterograph_index
.
create_unitgraph_from_coo
(
num_ntypes
,
urange
,
vrange
,
u
,
v
,
[
'coo'
]).
formats
(
formats
)
if
utype
==
vtype
:
return
DGLHeteroGraph
(
hgidx
,
[
utype
],
[
etype
])
else
:
...
...
tests/compute/test_heterograph.py
View file @
d2ccd218
...
...
@@ -82,13 +82,13 @@ def create_test_heterograph3(idtype):
wishes_nx
.
add_edge
(
'u2'
,
'g0'
,
id
=
1
)
follows_g
=
dgl
.
graph
([(
0
,
1
),
(
1
,
2
)],
'user'
,
'follows'
,
idtype
=
idtype
,
device
=
device
).
formats
(
'coo'
)
idtype
=
idtype
,
device
=
device
,
formats
=
'coo'
)
plays_g
=
dgl
.
bipartite
([(
0
,
0
),
(
1
,
0
),
(
2
,
1
),
(
1
,
1
)],
'user'
,
'plays'
,
'game'
,
idtype
=
idtype
,
device
=
device
).
formats
(
'coo'
)
idtype
=
idtype
,
device
=
device
,
formats
=
'coo'
)
wishes_g
=
dgl
.
bipartite
([(
0
,
1
),
(
2
,
0
)],
'user'
,
'wishes'
,
'game'
,
idtype
=
idtype
,
device
=
device
).
formats
(
'coo'
)
idtype
=
idtype
,
device
=
device
,
formats
=
'coo'
)
develops_g
=
dgl
.
bipartite
([(
0
,
0
),
(
1
,
1
)],
'developer'
,
'develops'
,
'game'
,
idtype
=
idtype
,
device
=
device
).
formats
(
'coo'
)
idtype
=
idtype
,
device
=
device
,
formats
=
'coo'
)
g
=
dgl
.
hetero_from_relations
([
follows_g
,
plays_g
,
wishes_g
,
develops_g
])
assert
g
.
idtype
==
idtype
assert
g
.
device
==
device
...
...
@@ -1332,7 +1332,7 @@ def test_subgraph(idtype):
if
F
.
_default_context_str
!=
'gpu'
:
# TODO(minjie): enable this later
for
fmt
in
[
'csr'
,
'csc'
,
'coo'
]:
g
=
dgl
.
graph
([(
0
,
1
),
(
1
,
2
)]
).
formats
(
fmt
)
g
=
dgl
.
graph
([(
0
,
1
),
(
1
,
2
)]
,
formats
=
fmt
)
sg
=
g
.
subgraph
({
g
.
ntypes
[
0
]:
[
1
,
0
]})
nids
=
F
.
asnumpy
(
sg
.
ndata
[
dgl
.
NID
])
assert
np
.
array_equal
(
nids
,
np
.
array
([
1
,
0
]))
...
...
@@ -1866,7 +1866,7 @@ def test_dtype_cast(idtype):
@
parametrize_dtype
def
test_format
(
idtype
):
# single relation
g
=
dgl
.
graph
([(
0
,
0
),
(
1
,
1
),
(
0
,
1
),
(
2
,
0
)],
idtype
=
idtype
,
device
=
F
.
ctx
()
).
formats
(
'coo'
)
g
=
dgl
.
graph
([(
0
,
0
),
(
1
,
1
),
(
0
,
1
),
(
2
,
0
)],
idtype
=
idtype
,
device
=
F
.
ctx
()
,
formats
=
'coo'
)
assert
g
.
formats
()[
'created'
]
==
[
'coo'
]
assert
len
(
g
.
formats
()[
'not created'
])
==
0
try
:
...
...
@@ -1886,7 +1886,7 @@ def test_format(idtype):
(
'user'
,
'follows'
,
'user'
):
[(
0
,
1
),
(
1
,
2
)],
(
'user'
,
'plays'
,
'game'
):
[(
0
,
0
),
(
1
,
0
),
(
1
,
1
),
(
2
,
1
)],
(
'developer'
,
'develops'
,
'game'
):
[(
0
,
0
),
(
1
,
1
)],
},
idtype
=
idtype
,
device
=
F
.
ctx
()
).
formats
(
'csr'
)
},
idtype
=
idtype
,
device
=
F
.
ctx
()
,
formats
=
'csr'
)
user_feat
=
F
.
randn
((
g
[
'follows'
].
number_of_src_nodes
(),
5
))
g
[
'follows'
].
srcdata
[
'h'
]
=
user_feat
assert
g
.
formats
()[
'created'
]
==
[
'csr'
]
...
...
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