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
e7389d7c
Unverified
Commit
e7389d7c
authored
Jun 07, 2019
by
Da Zheng
Committed by
GitHub
Jun 07, 2019
Browse files
[BUGFIX] fix the order of the seed nodes in NodeFlow (#626)
* fix. * add comments.
parent
8bf97719
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
22 additions
and
13 deletions
+22
-13
src/graph/sampler.cc
src/graph/sampler.cc
+20
-12
tests/compute/test_nodeflow.py
tests/compute/test_nodeflow.py
+2
-1
No files found.
src/graph/sampler.cc
View file @
e7389d7c
...
@@ -276,13 +276,17 @@ NodeFlow ConstructNodeFlow(std::vector<dgl_id_t> neighbor_list,
...
@@ -276,13 +276,17 @@ NodeFlow ConstructNodeFlow(std::vector<dgl_id_t> neighbor_list,
size_t
out_node_idx
=
0
;
size_t
out_node_idx
=
0
;
for
(
int
layer_id
=
num_hops
-
1
;
layer_id
>=
0
;
layer_id
--
)
{
for
(
int
layer_id
=
num_hops
-
1
;
layer_id
>=
0
;
layer_id
--
)
{
// We sort the vertices in a layer so that we don't need to sort the neighbor Ids
// We sort the vertices in a layer so that we don't need to sort the neighbor Ids
// after remap to a subgraph.
// after remap to a subgraph. However, we don't need to sort the first layer
std
::
sort
(
sub_vers
->
begin
()
+
layer_offsets
[
layer_id
],
// because we want the order of the nodes in the first layer is the same as
sub_vers
->
begin
()
+
layer_offsets
[
layer_id
+
1
],
// the input seed nodes.
[](
const
std
::
pair
<
dgl_id_t
,
dgl_id_t
>
&
a1
,
if
(
layer_id
>
0
)
{
const
std
::
pair
<
dgl_id_t
,
dgl_id_t
>
&
a2
)
{
std
::
sort
(
sub_vers
->
begin
()
+
layer_offsets
[
layer_id
],
return
a1
.
first
<
a2
.
first
;
sub_vers
->
begin
()
+
layer_offsets
[
layer_id
+
1
],
});
[](
const
std
::
pair
<
dgl_id_t
,
dgl_id_t
>
&
a1
,
const
std
::
pair
<
dgl_id_t
,
dgl_id_t
>
&
a2
)
{
return
a1
.
first
<
a2
.
first
;
});
}
// Save the sampled vertices and its layer Id.
// Save the sampled vertices and its layer Id.
for
(
size_t
i
=
layer_offsets
[
layer_id
];
i
<
layer_offsets
[
layer_id
+
1
];
i
++
)
{
for
(
size_t
i
=
layer_offsets
[
layer_id
];
i
<
layer_offsets
[
layer_id
+
1
];
i
++
)
{
...
@@ -305,11 +309,15 @@ NodeFlow ConstructNodeFlow(std::vector<dgl_id_t> neighbor_list,
...
@@ -305,11 +309,15 @@ NodeFlow ConstructNodeFlow(std::vector<dgl_id_t> neighbor_list,
layer_off_data
[
1
]
=
layer_offsets
[
num_hops
]
-
layer_offsets
[
num_hops
-
1
];
layer_off_data
[
1
]
=
layer_offsets
[
num_hops
]
-
layer_offsets
[
num_hops
-
1
];
int
out_layer_idx
=
1
;
int
out_layer_idx
=
1
;
for
(
int
layer_id
=
num_hops
-
2
;
layer_id
>=
0
;
layer_id
--
)
{
for
(
int
layer_id
=
num_hops
-
2
;
layer_id
>=
0
;
layer_id
--
)
{
std
::
sort
(
neigh_pos
->
begin
()
+
layer_offsets
[
layer_id
],
// Because we don't sort the vertices in the first layer above, we can't sort
neigh_pos
->
begin
()
+
layer_offsets
[
layer_id
+
1
],
// the neighbor positions of the vertices in the first layer either.
[](
const
neighbor_info
&
a1
,
const
neighbor_info
&
a2
)
{
if
(
layer_id
>
0
)
{
return
a1
.
id
<
a2
.
id
;
std
::
sort
(
neigh_pos
->
begin
()
+
layer_offsets
[
layer_id
],
});
neigh_pos
->
begin
()
+
layer_offsets
[
layer_id
+
1
],
[](
const
neighbor_info
&
a1
,
const
neighbor_info
&
a2
)
{
return
a1
.
id
<
a2
.
id
;
});
}
for
(
size_t
i
=
layer_offsets
[
layer_id
];
i
<
layer_offsets
[
layer_id
+
1
];
i
++
)
{
for
(
size_t
i
=
layer_offsets
[
layer_id
];
i
<
layer_offsets
[
layer_id
+
1
];
i
++
)
{
dgl_id_t
dst_id
=
sub_vers
->
at
(
i
).
first
;
dgl_id_t
dst_id
=
sub_vers
->
at
(
i
).
first
;
...
...
tests/compute/test_nodeflow.py
View file @
e7389d7c
...
@@ -39,11 +39,12 @@ def test_self_loop():
...
@@ -39,11 +39,12 @@ def test_self_loop():
assert
F
.
array_equal
(
in_deg
,
deg
)
assert
F
.
array_equal
(
in_deg
,
deg
)
def
create_mini_batch
(
g
,
num_hops
,
add_self_loop
=
False
):
def
create_mini_batch
(
g
,
num_hops
,
add_self_loop
=
False
):
seed_ids
=
np
.
array
([
0
,
1
,
2
,
3
])
seed_ids
=
np
.
array
([
1
,
2
,
0
,
3
])
sampler
=
NeighborSampler
(
g
,
batch_size
=
4
,
expand_factor
=
g
.
number_of_nodes
(),
sampler
=
NeighborSampler
(
g
,
batch_size
=
4
,
expand_factor
=
g
.
number_of_nodes
(),
num_hops
=
num_hops
,
seed_nodes
=
seed_ids
,
add_self_loop
=
add_self_loop
)
num_hops
=
num_hops
,
seed_nodes
=
seed_ids
,
add_self_loop
=
add_self_loop
)
nfs
=
list
(
sampler
)
nfs
=
list
(
sampler
)
assert
len
(
nfs
)
==
1
assert
len
(
nfs
)
==
1
assert
np
.
array_equal
(
F
.
asnumpy
(
nfs
[
0
].
layer_parent_nid
(
-
1
)),
seed_ids
)
return
nfs
[
0
]
return
nfs
[
0
]
def
check_basic
(
g
,
nf
):
def
check_basic
(
g
,
nf
):
...
...
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