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
torch-sparse
Commits
523e86a3
Commit
523e86a3
authored
Apr 14, 2020
by
bowendeng
Browse files
csrc: partition_cpu supports weighted graph
parent
203d69f2
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
13 additions
and
6 deletions
+13
-6
csrc/cpu/metis_cpu.cpp
csrc/cpu/metis_cpu.cpp
+10
-3
csrc/cpu/metis_cpu.h
csrc/cpu/metis_cpu.h
+1
-1
csrc/metis.cpp
csrc/metis.cpp
+1
-1
torch_sparse/metis.py
torch_sparse/metis.py
+1
-1
No files found.
csrc/cpu/metis_cpu.cpp
View file @
523e86a3
...
...
@@ -7,17 +7,24 @@
#include "utils.h"
torch
::
Tensor
partition_cpu
(
torch
::
Tensor
rowptr
,
torch
::
Tensor
col
,
int64_t
num_parts
,
torch
::
Tensor
edge_wgt
,
bool
recursive
)
{
torch
::
optional
<
torch
::
Tensor
>
edge_wgt
,
bool
recursive
)
{
#ifdef WITH_METIS
CHECK_CPU
(
rowptr
);
CHECK_CPU
(
col
);
int64_t
nvtxs
=
rowptr
.
numel
()
-
1
;
auto
part
=
torch
::
empty
(
nvtxs
,
rowptr
.
options
());
auto
part
=
torch
::
empty
(
nvtxs
,
rowptr
.
options
());
auto
*
xadj
=
rowptr
.
data_ptr
<
int64_t
>
();
auto
*
adjncy
=
col
.
data_ptr
<
int64_t
>
();
auto
*
adjwgt
=
edge_wgt
.
data_ptr
<
int64_t
>
();
int64_t
*
adjwgt
;
if
(
edge_wgt
.
has_value
()){
adjwgt
=
edge_wgt
.
value
().
data_ptr
<
int64_t
>
();
adjwgt
=
(
idx_t
*
)
adjwgt
;
}
else
{
adjwgt
=
nullptr
;
}
int64_t
ncon
=
1
;
int64_t
objval
=
-
1
;
...
...
csrc/cpu/metis_cpu.h
View file @
523e86a3
...
...
@@ -3,5 +3,5 @@
#include <torch/extension.h>
torch
::
Tensor
partition_cpu
(
torch
::
Tensor
rowptr
,
torch
::
Tensor
col
,
int64_t
num_parts
,
torch
::
Tensor
edge_wgt
,
int64_t
num_parts
,
torch
::
optional
<
torch
::
Tensor
>
edge_wgt
,
bool
recursive
);
csrc/metis.cpp
View file @
523e86a3
...
...
@@ -7,7 +7,7 @@ PyMODINIT_FUNC PyInit__metis(void) { return NULL; }
#endif
torch
::
Tensor
partition
(
torch
::
Tensor
rowptr
,
torch
::
Tensor
col
,
int64_t
num_parts
,
torch
::
Tensor
edge_wgt
,
bool
recursive
)
{
torch
::
optional
<
torch
::
Tensor
>
edge_wgt
,
bool
recursive
)
{
if
(
rowptr
.
device
().
is_cuda
())
{
#ifdef WITH_CUDA
AT_ERROR
(
"No CUDA version supported"
);
...
...
torch_sparse/metis.py
View file @
523e86a3
...
...
@@ -11,7 +11,7 @@ def metis_wgt(x):
diff
=
t1
-
t2
diff
=
diff
[
diff
!=
0
]
if
len
(
diff
)
==
0
:
return
torch
.
ones
(
x
.
shape
,
dtype
=
torch
.
long
)
return
None
res
=
diff
.
abs
().
min
()
bod
=
x
.
max
()
-
x
.
min
()
scale
=
(
res
/
bod
).
item
()
...
...
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