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
1750d110
Commit
1750d110
authored
Jan 15, 2018
by
rusty1s
Browse files
first consecutive impl
parent
43fde05a
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
15 additions
and
1 deletion
+15
-1
torch_cluster/functions/grid.py
torch_cluster/functions/grid.py
+3
-1
torch_cluster/functions/utils.py
torch_cluster/functions/utils.py
+12
-0
No files found.
torch_cluster/functions/grid.py
View file @
1750d110
import
torch
import
torch
from
.utils
import
get_func
from
.utils
import
get_func
,
consecutive
def
grid_cluster
(
position
,
size
,
batch
=
None
):
def
grid_cluster
(
position
,
size
,
batch
=
None
):
...
@@ -44,4 +44,6 @@ def grid_cluster(position, size, batch=None):
...
@@ -44,4 +44,6 @@ def grid_cluster(position, size, batch=None):
func
(
C
,
cluster
,
position
,
size
,
c_max
)
func
(
C
,
cluster
,
position
,
size
,
c_max
)
cluster
=
cluster
.
squeeze
(
dim
=-
1
)
cluster
=
cluster
.
squeeze
(
dim
=-
1
)
cluster
=
consecutive
(
cluster
)
return
cluster
return
cluster
torch_cluster/functions/utils.py
View file @
1750d110
import
torch
from
torch_unique
import
unique
from
.._ext
import
ffi
from
.._ext
import
ffi
...
@@ -6,3 +9,12 @@ def get_func(name, tensor):
...
@@ -6,3 +9,12 @@ def get_func(name, tensor):
cuda
=
'cuda_'
if
tensor
.
is_cuda
else
''
cuda
=
'cuda_'
if
tensor
.
is_cuda
else
''
func
=
getattr
(
ffi
,
'cluster_{}_{}{}'
.
format
(
name
,
cuda
,
typename
))
func
=
getattr
(
ffi
,
'cluster_{}_{}{}'
.
format
(
name
,
cuda
,
typename
))
return
func
return
func
def
consecutive
(
tensor
):
size
=
tensor
.
size
()
u
=
unique
(
tensor
.
view
(
-
1
))
arg
=
torch
.
ByteTensor
(
u
[
-
1
])
arg
[
u
]
=
torch
.
arange
(
0
,
u
.
size
(
0
),
out
=
torch
.
ByteTensor
())
tensor
=
arg
[
tensor
.
view
(
-
1
)]
return
tensor
.
view
(
size
).
long
()
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