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-cluster
Commits
4d72a05e
Commit
4d72a05e
authored
Apr 27, 2018
by
rusty1s
Browse files
randperm
parent
24a770f3
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
15 additions
and
11 deletions
+15
-11
aten/cpu/cluster.cpp
aten/cpu/cluster.cpp
+15
-11
No files found.
aten/cpu/cluster.cpp
View file @
4d72a05e
#include <torch/torch.h>
#include <torch/torch.h>
at
::
Tensor
degree
(
at
::
Tensor
index
,
int64_t
num_nodes
)
{
inline
std
::
tuple
<
at
::
Tensor
,
at
::
Tensor
>
randperm
(
at
::
Tensor
row
,
at
::
Tensor
col
)
{
auto
one
=
at
::
ones_like
(
index
);
auto
zero
=
at
::
zeros
(
torch
::
CPU
(
at
::
kLong
),
{
num_nodes
});
return
zero
.
scatter_add_
(
0
,
index
,
one
);
}
at
::
Tensor
graclus
(
at
::
Tensor
row
,
at
::
Tensor
col
,
int64_t
num_nodes
)
{
auto
cluster
=
at
::
empty
(
torch
::
CPU
(
at
::
kLong
),
{
num_nodes
}).
fill_
(
-
1
);
auto
deg
=
degree
(
row
,
num_nodes
);
/* at::Tensor perm; */
/* at::Tensor perm; */
/* std::tie(row, perm) = row.sort(); */
/* std::tie(row, perm) = row.sort(); */
/* col = col.index_select(0, perm); */
/* col = col.index_select(0, perm); */
/* TODO: randperm */
/* TODO: randperm */
/* TODO: randperm_sort_row */
/* TODO: randperm_sort_row */
return
{
row
,
col
};
}
inline
at
::
Tensor
degree
(
at
::
Tensor
index
,
int64_t
num_nodes
)
{
auto
zero
=
at
::
zeros
(
torch
::
CPU
(
at
::
kLong
),
{
num_nodes
});
return
zero
.
scatter_add_
(
0
,
index
,
at
::
ones_like
(
index
));
}
at
::
Tensor
graclus
(
at
::
Tensor
row
,
at
::
Tensor
col
,
int64_t
num_nodes
)
{
std
::
tie
(
row
,
col
)
=
randperm
(
row
,
col
);
auto
deg
=
degree
(
row
,
num_nodes
);
auto
cluster
=
at
::
empty
(
torch
::
CPU
(
at
::
kLong
),
{
num_nodes
}).
fill_
(
-
1
);
auto
*
row_data
=
row
.
data
<
int64_t
>
();
auto
*
row_data
=
row
.
data
<
int64_t
>
();
auto
*
col_data
=
col
.
data
<
int64_t
>
();
auto
*
col_data
=
col
.
data
<
int64_t
>
();
...
...
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