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
c6067cc4
Commit
c6067cc4
authored
Sep 06, 2023
by
lisj
Browse files
适配dtk23.04-km
parent
a99e1077
Changes
16
Show whitespace changes
Inline
Side-by-side
Showing
16 changed files
with
41 additions
and
39 deletions
+41
-39
README.md
README.md
+3
-1
examples/pytorch/bgnn/BGNN.py
examples/pytorch/bgnn/BGNN.py
+2
-2
examples/pytorch/ggnn/train_gc.py
examples/pytorch/ggnn/train_gc.py
+2
-2
examples/pytorch/ggnn/train_ns.py
examples/pytorch/ggnn/train_ns.py
+2
-2
examples/pytorch/hilander/utils/evaluate.py
examples/pytorch/hilander/utils/evaluate.py
+1
-1
examples/pytorch/mvgrl/graph/dataset.py
examples/pytorch/mvgrl/graph/dataset.py
+2
-2
examples/pytorch/ogb/deepwalk/reading_data.py
examples/pytorch/ogb/deepwalk/reading_data.py
+1
-1
examples/pytorch/ogb/line/reading_data.py
examples/pytorch/ogb/line/reading_data.py
+1
-1
examples/pytorch/pointcloud/pct/ShapeNet.py
examples/pytorch/pointcloud/pct/ShapeNet.py
+4
-4
examples/pytorch/pointcloud/point_transformer/ShapeNet.py
examples/pytorch/pointcloud/point_transformer/ShapeNet.py
+4
-4
examples/pytorch/pointcloud/pointnet/ShapeNet.py
examples/pytorch/pointcloud/pointnet/ShapeNet.py
+4
-4
python/dgl/contrib/data/knowledge_graph.py
python/dgl/contrib/data/knowledge_graph.py
+1
-1
python/dgl/data/minigc.py
python/dgl/data/minigc.py
+1
-1
python/setup.py
python/setup.py
+1
-1
tests/compute/test_data.py
tests/compute/test_data.py
+10
-10
tests/compute/test_heterograph.py
tests/compute/test_heterograph.py
+2
-2
No files found.
README.md
View file @
c6067cc4
...
...
@@ -77,3 +77,5 @@ hip结构体hipPointerAttribute_t适配
src
\a
rray
\c
uda
\g
ather_mm.cu:103
src
\a
rray
\c
uda
\g
ather_mm.cu:164
```
3.
单元测试及python相关
修改
`np.int`
、
`np.float`
、
`np.asscalar`
为
`int`
、
`float`
、
`np.ndarray.item`
,并将
`setup.py`
中
`numpy`
依赖版本提高至
`1.20.0`
,统一dtype相关类型的代码,以避免单元测试和使用中问题
\ No newline at end of file
examples/pytorch/bgnn/BGNN.py
View file @
c6067cc4
...
...
@@ -287,9 +287,9 @@ class BGNNPredictor:
# initialize for early stopping and metrics
if
metric_name
in
[
'r2'
,
'accuracy'
]:
best_metric
=
[
np
.
float
(
'-inf'
)]
*
3
# for train/val/test
best_metric
=
[
float
(
'-inf'
)]
*
3
# for train/val/test
else
:
best_metric
=
[
np
.
float
(
'inf'
)]
*
3
# for train/val/test
best_metric
=
[
float
(
'inf'
)]
*
3
# for train/val/test
best_val_epoch
=
0
epochs_since_last_best_metric
=
0
...
...
examples/pytorch/ggnn/train_gc.py
View file @
c6067cc4
...
...
@@ -56,7 +56,7 @@ def main(args):
labels
=
labels
.
data
.
numpy
().
tolist
()
dev_preds
+=
preds
dev_labels
+=
labels
acc
=
np
.
equal
(
dev_labels
,
dev_preds
).
astype
(
np
.
float
).
tolist
()
acc
=
np
.
equal
(
dev_labels
,
dev_preds
).
astype
(
float
).
tolist
()
acc
=
sum
(
acc
)
/
len
(
acc
)
print
(
f
"Epoch
{
epoch
}
, Dev acc
{
acc
}
"
)
...
...
@@ -76,7 +76,7 @@ def main(args):
labels
=
labels
.
data
.
numpy
().
tolist
()
test_preds
+=
preds
test_labels
+=
labels
acc
=
np
.
equal
(
test_labels
,
test_preds
).
astype
(
np
.
float
).
tolist
()
acc
=
np
.
equal
(
test_labels
,
test_preds
).
astype
(
float
).
tolist
()
acc
=
sum
(
acc
)
/
len
(
acc
)
test_acc_list
.
append
(
acc
)
...
...
examples/pytorch/ggnn/train_ns.py
View file @
c6067cc4
...
...
@@ -53,7 +53,7 @@ def main(args):
labels
=
labels
.
data
.
numpy
().
tolist
()
dev_preds
+=
preds
dev_labels
+=
labels
acc
=
np
.
equal
(
dev_labels
,
dev_preds
).
astype
(
np
.
float
).
tolist
()
acc
=
np
.
equal
(
dev_labels
,
dev_preds
).
astype
(
float
).
tolist
()
acc
=
sum
(
acc
)
/
len
(
acc
)
print
(
f
"Epoch
{
epoch
}
, Dev acc
{
acc
}
"
)
...
...
@@ -73,7 +73,7 @@ def main(args):
labels
=
labels
.
data
.
numpy
().
tolist
()
test_preds
+=
preds
test_labels
+=
labels
acc
=
np
.
equal
(
test_labels
,
test_preds
).
astype
(
np
.
float
).
tolist
()
acc
=
np
.
equal
(
test_labels
,
test_preds
).
astype
(
float
).
tolist
()
acc
=
sum
(
acc
)
/
len
(
acc
)
test_acc_list
.
append
(
acc
)
...
...
examples/pytorch/hilander/utils/evaluate.py
View file @
c6067cc4
...
...
@@ -36,7 +36,7 @@ def evaluate(gt_labels, pred_labels, metric='pairwise'):
with
Timer
(
'evaluate with {}{}{}'
.
format
(
TextColors
.
FATAL
,
metric
,
TextColors
.
ENDC
)):
result
=
metric_func
(
gt_labels
,
pred_labels
)
if
isinstance
(
result
,
np
.
float
):
if
isinstance
(
result
,
float
):
print
(
'{}{}: {:.4f}{}'
.
format
(
TextColors
.
OKGREEN
,
metric
,
result
,
TextColors
.
ENDC
))
else
:
...
...
examples/pytorch/mvgrl/graph/dataset.py
View file @
c6067cc4
...
...
@@ -53,7 +53,7 @@ def process(dataset):
with
open
(
'{0}_node_attributes.txt'
.
format
(
prefix
),
'r'
)
as
f
:
for
line
in
f
:
node_attrs
.
append
(
np
.
array
([
float
(
attr
)
for
attr
in
re
.
split
(
"[,\s]+"
,
line
.
strip
(
"\s
\n
"
))
if
attr
],
dtype
=
np
.
float
)
np
.
array
([
float
(
attr
)
for
attr
in
re
.
split
(
"[,\s]+"
,
line
.
strip
(
"\s
\n
"
))
if
attr
],
dtype
=
float
)
)
else
:
print
(
'No node attributes'
)
...
...
@@ -113,7 +113,7 @@ def process(dataset):
f
=
np
.
zeros
(
max_deg
+
1
)
f
[
graph
.
degree
[
u
[
0
]]]
=
1.0
if
'label'
in
u
[
1
]:
f
=
np
.
concatenate
((
np
.
array
(
u
[
1
][
'label'
],
dtype
=
np
.
float
),
f
))
f
=
np
.
concatenate
((
np
.
array
(
u
[
1
][
'label'
],
dtype
=
float
),
f
))
graph
.
nodes
[
u
[
0
]][
'feat'
]
=
f
return
graphs
,
pprs
...
...
examples/pytorch/ogb/deepwalk/reading_data.py
View file @
c6067cc4
...
...
@@ -188,7 +188,7 @@ class DeepwalkDataset:
node_degree
=
self
.
G
.
out_degrees
(
self
.
valid_seeds
).
numpy
()
node_degree
=
np
.
power
(
node_degree
,
0.75
)
node_degree
/=
np
.
sum
(
node_degree
)
node_degree
=
np
.
array
(
node_degree
*
1e8
,
dtype
=
np
.
int
)
node_degree
=
np
.
array
(
node_degree
*
1e8
,
dtype
=
int
)
self
.
neg_table
=
[]
for
idx
,
node
in
enumerate
(
self
.
valid_seeds
):
...
...
examples/pytorch/ogb/line/reading_data.py
View file @
c6067cc4
...
...
@@ -184,7 +184,7 @@ class LineDataset:
node_degree
=
self
.
G
.
out_degrees
(
self
.
valid_nodes
).
numpy
()
node_degree
=
np
.
power
(
node_degree
,
0.75
)
node_degree
/=
np
.
sum
(
node_degree
)
node_degree
=
np
.
array
(
node_degree
*
1e8
,
dtype
=
np
.
int
)
node_degree
=
np
.
array
(
node_degree
*
1e8
,
dtype
=
int
)
self
.
neg_table
=
[]
for
idx
,
node
in
enumerate
(
self
.
valid_nodes
):
...
...
examples/pytorch/pointcloud/pct/ShapeNet.py
View file @
c6067cc4
...
...
@@ -98,9 +98,9 @@ class ShapeNetDataset(Dataset):
print
(
'Loading data from split '
+
self
.
mode
)
for
fn
in
tqdm
.
tqdm
(
self
.
file_list
,
ascii
=
True
):
with
open
(
fn
)
as
f
:
data
=
np
.
array
([
t
.
split
(
'
\n
'
)[
0
].
split
(
' '
)
for
t
in
f
.
readlines
()]).
astype
(
np
.
float
)
data
=
np
.
array
([
t
.
split
(
'
\n
'
)[
0
].
split
(
' '
)
for
t
in
f
.
readlines
()]).
astype
(
float
)
data_list
.
append
(
data
[:,
0
:
self
.
dim
])
label_list
.
append
(
data
[:,
6
].
astype
(
np
.
int
))
label_list
.
append
(
data
[:,
6
].
astype
(
int
))
category_list
.
append
(
shapenet
.
synset_dict
[
fn
.
split
(
'/'
)[
-
2
]])
self
.
data
=
data_list
self
.
label
=
label_list
...
...
@@ -122,6 +122,6 @@ class ShapeNetDataset(Dataset):
cat
=
self
.
category
[
i
]
if
self
.
mode
==
'train'
:
x
=
self
.
translate
(
x
,
size
=
self
.
dim
)
x
=
x
.
astype
(
np
.
float
)
y
=
y
.
astype
(
np
.
int
)
x
=
x
.
astype
(
float
)
y
=
y
.
astype
(
int
)
return
x
,
y
,
cat
examples/pytorch/pointcloud/point_transformer/ShapeNet.py
View file @
c6067cc4
...
...
@@ -98,9 +98,9 @@ class ShapeNetDataset(Dataset):
print
(
'Loading data from split '
+
self
.
mode
)
for
fn
in
tqdm
.
tqdm
(
self
.
file_list
,
ascii
=
True
):
with
open
(
fn
)
as
f
:
data
=
np
.
array
([
t
.
split
(
'
\n
'
)[
0
].
split
(
' '
)
for
t
in
f
.
readlines
()]).
astype
(
np
.
float
)
data
=
np
.
array
([
t
.
split
(
'
\n
'
)[
0
].
split
(
' '
)
for
t
in
f
.
readlines
()]).
astype
(
float
)
data_list
.
append
(
data
[:,
0
:
self
.
dim
])
label_list
.
append
(
data
[:,
6
].
astype
(
np
.
int
))
label_list
.
append
(
data
[:,
6
].
astype
(
int
))
category_list
.
append
(
shapenet
.
synset_dict
[
fn
.
split
(
'/'
)[
-
2
]])
self
.
data
=
data_list
self
.
label
=
label_list
...
...
@@ -122,6 +122,6 @@ class ShapeNetDataset(Dataset):
cat
=
self
.
category
[
i
]
if
self
.
mode
==
'train'
:
x
=
self
.
translate
(
x
,
size
=
self
.
dim
)
x
=
x
.
astype
(
np
.
float
)
y
=
y
.
astype
(
np
.
int
)
x
=
x
.
astype
(
float
)
y
=
y
.
astype
(
int
)
return
x
,
y
,
cat
examples/pytorch/pointcloud/pointnet/ShapeNet.py
View file @
c6067cc4
...
...
@@ -98,9 +98,9 @@ class ShapeNetDataset(Dataset):
print
(
'Loading data from split '
+
self
.
mode
)
for
fn
in
tqdm
.
tqdm
(
self
.
file_list
,
ascii
=
True
):
with
open
(
fn
)
as
f
:
data
=
np
.
array
([
t
.
split
(
'
\n
'
)[
0
].
split
(
' '
)
for
t
in
f
.
readlines
()]).
astype
(
np
.
float
)
data
=
np
.
array
([
t
.
split
(
'
\n
'
)[
0
].
split
(
' '
)
for
t
in
f
.
readlines
()]).
astype
(
float
)
data_list
.
append
(
data
[:,
0
:
self
.
dim
])
label_list
.
append
(
data
[:,
6
].
astype
(
np
.
int
))
label_list
.
append
(
data
[:,
6
].
astype
(
int
))
category_list
.
append
(
shapenet
.
synset_dict
[
fn
.
split
(
'/'
)[
-
2
]])
self
.
data
=
data_list
self
.
label
=
label_list
...
...
@@ -122,6 +122,6 @@ class ShapeNetDataset(Dataset):
cat
=
self
.
category
[
i
]
if
self
.
mode
==
'train'
:
x
=
self
.
translate
(
x
,
size
=
self
.
dim
)
x
=
x
.
astype
(
np
.
float
)
y
=
y
.
astype
(
np
.
int
)
x
=
x
.
astype
(
float
)
y
=
y
.
astype
(
int
)
return
x
,
y
,
cat
python/dgl/contrib/data/knowledge_graph.py
View file @
c6067cc4
...
...
@@ -417,7 +417,7 @@ def _load_data(dataset_str='aifb', dataset_path=None):
# sort indices by destination
edge_list
=
sorted
(
edge_list
,
key
=
lambda
x
:
(
x
[
1
],
x
[
0
],
x
[
2
]))
edge_list
=
np
.
asarray
(
edge_list
,
dtype
=
np
.
int
)
edge_list
=
np
.
asarray
(
edge_list
,
dtype
=
int
)
print
(
'Number of edges: '
,
len
(
edge_list
))
np
.
savez
(
edge_file
,
edges
=
edge_list
,
n
=
np
.
asarray
(
num_node
),
nrel
=
np
.
asarray
(
num_rel
))
...
...
python/dgl/data/minigc.py
View file @
c6067cc4
...
...
@@ -156,7 +156,7 @@ class MiniGCDataset(DGLDataset):
for
i
in
range
(
self
.
num_graphs
):
# convert to DGLGraph, and add self loops
self
.
graphs
[
i
]
=
add_self_loop
(
from_networkx
(
self
.
graphs
[
i
]))
self
.
labels
=
F
.
tensor
(
np
.
array
(
self
.
labels
).
astype
(
np
.
int
))
self
.
labels
=
F
.
tensor
(
np
.
array
(
self
.
labels
).
astype
(
int
))
def
_gen_cycle
(
self
,
n
):
for
_
in
range
(
n
):
...
...
python/setup.py
View file @
c6067cc4
...
...
@@ -168,7 +168,7 @@ setup(
maintainer_email
=
'wmjlyjemaine@gmail.com'
,
packages
=
find_packages
(),
install_requires
=
[
'numpy>=1.
14
.0'
,
'numpy>=1.
20
.0'
,
'scipy>=1.1.0'
,
'networkx>=2.1'
,
'requests>=2.19.0'
,
...
...
tests/compute/test_data.py
View file @
c6067cc4
...
...
@@ -510,12 +510,12 @@ def _test_construct_graphs_multiple():
num_edges
=
1000
num_graphs
=
10
num_dims
=
3
node_ids
=
np
.
array
([],
dtype
=
np
.
int
)
src_ids
=
np
.
array
([],
dtype
=
np
.
int
)
dst_ids
=
np
.
array
([],
dtype
=
np
.
int
)
ngraph_ids
=
np
.
array
([],
dtype
=
np
.
int
)
egraph_ids
=
np
.
array
([],
dtype
=
np
.
int
)
u_indices
=
np
.
array
([],
dtype
=
np
.
int
)
node_ids
=
np
.
array
([],
dtype
=
int
)
src_ids
=
np
.
array
([],
dtype
=
int
)
dst_ids
=
np
.
array
([],
dtype
=
int
)
ngraph_ids
=
np
.
array
([],
dtype
=
int
)
egraph_ids
=
np
.
array
([],
dtype
=
int
)
u_indices
=
np
.
array
([],
dtype
=
int
)
for
i
in
range
(
num_graphs
):
l_node_ids
=
np
.
random
.
choice
(
np
.
arange
(
num_nodes
*
2
),
size
=
num_nodes
,
replace
=
False
)
...
...
@@ -1191,7 +1191,7 @@ def _test_NodeEdgeGraphData():
from
dgl.data.csv_dataset_base
import
NodeData
,
EdgeData
,
GraphData
# NodeData basics
num_nodes
=
100
node_ids
=
np
.
arange
(
num_nodes
,
dtype
=
np
.
float
)
node_ids
=
np
.
arange
(
num_nodes
,
dtype
=
float
)
ndata
=
NodeData
(
node_ids
,
{})
assert
np
.
array_equal
(
ndata
.
id
,
node_ids
)
assert
len
(
ndata
.
data
)
==
0
...
...
@@ -1228,8 +1228,8 @@ def _test_NodeEdgeGraphData():
assert
len
(
edata
.
data
)
==
0
assert
np
.
array_equal
(
edata
.
graph_id
,
np
.
full
(
num_edges
,
0
))
# EdageData more
src_ids
=
np
.
random
.
randint
(
num_nodes
,
size
=
num_edges
).
astype
(
np
.
float
)
dst_ids
=
np
.
random
.
randint
(
num_nodes
,
size
=
num_edges
).
astype
(
np
.
float
)
src_ids
=
np
.
random
.
randint
(
num_nodes
,
size
=
num_edges
).
astype
(
float
)
dst_ids
=
np
.
random
.
randint
(
num_nodes
,
size
=
num_edges
).
astype
(
float
)
data
=
{
'feat'
:
np
.
random
.
rand
(
num_edges
,
3
)}
etype
=
(
'user'
,
'like'
,
'item'
)
graph_ids
=
np
.
arange
(
num_edges
)
...
...
@@ -1259,7 +1259,7 @@ def _test_NodeEdgeGraphData():
assert
np
.
array_equal
(
gdata
.
graph_id
,
graph_ids
)
assert
len
(
gdata
.
data
)
==
0
# GraphData more
graph_ids
=
np
.
arange
(
num_graphs
).
astype
(
np
.
float
)
graph_ids
=
np
.
arange
(
num_graphs
).
astype
(
float
)
data
=
{
'feat'
:
np
.
random
.
rand
(
num_graphs
,
3
)}
gdata
=
GraphData
(
graph_ids
,
data
)
assert
np
.
array_equal
(
gdata
.
graph_id
,
graph_ids
)
...
...
tests/compute/test_heterograph.py
View file @
c6067cc4
...
...
@@ -1125,8 +1125,8 @@ def test_convert(idtype):
dsttype
=
hg
.
ntypes
[
ntype_id
[
dst
[
i
]]]
etype
=
hg
.
etypes
[
etype_id
[
i
]]
src_i
,
dst_i
=
hg
.
find_edges
([
eid
[
i
]],
(
srctype
,
etype
,
dsttype
))
assert
np
.
asscalar
(
F
.
asnumpy
(
src_i
))
==
nid
[
src
[
i
]]
assert
np
.
asscalar
(
F
.
asnumpy
(
dst_i
))
==
nid
[
dst
[
i
]]
assert
np
.
ndarray
.
item
(
F
.
asnumpy
(
src_i
))
==
nid
[
src
[
i
]]
assert
np
.
ndarray
.
item
(
F
.
asnumpy
(
dst_i
))
==
nid
[
dst
[
i
]]
mg
=
nx
.
MultiDiGraph
([
(
'user'
,
'user'
,
'follows'
),
...
...
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