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
74364643
Commit
74364643
authored
Mar 01, 2018
by
rusty1s
Browse files
start and end expect torch tensors
parent
70fe8d5d
Changes
7
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
23 additions
and
16 deletions
+23
-16
setup.py
setup.py
+1
-1
test/dense_grid.json
test/dense_grid.json
+5
-5
test/sparse_grid.json
test/sparse_grid.json
+1
-1
test/test_dense_grid.py
test/test_dense_grid.py
+4
-0
test/test_sparse_grid.py
test/test_sparse_grid.py
+8
-6
torch_cluster/__init__.py
torch_cluster/__init__.py
+1
-1
torch_cluster/functions/grid.py
torch_cluster/functions/grid.py
+3
-2
No files found.
setup.py
View file @
74364643
...
@@ -2,7 +2,7 @@ from os import path as osp
...
@@ -2,7 +2,7 @@ from os import path as osp
from
setuptools
import
setup
,
find_packages
from
setuptools
import
setup
,
find_packages
__version__
=
'0.2.
4
'
__version__
=
'0.2.
5
'
url
=
'https://github.com/rusty1s/pytorch_cluster'
url
=
'https://github.com/rusty1s/pytorch_cluster'
install_requires
=
[
'cffi'
,
'torch-unique'
]
install_requires
=
[
'cffi'
,
'torch-unique'
]
...
...
test/dense_grid.json
View file @
74364643
...
@@ -10,7 +10,7 @@
...
@@ -10,7 +10,7 @@
"name"
:
"Start parameter"
,
"name"
:
"Start parameter"
,
"position"
:
[
2
,
16
],
"position"
:
[
2
,
16
],
"size"
:
[
5
],
"size"
:
[
5
],
"start"
:
-1
,
"start"
:
[
-1
]
,
"expected"
:
[
0
,
3
],
"expected"
:
[
0
,
3
],
"expected_C"
:
4
"expected_C"
:
4
},
},
...
@@ -18,8 +18,8 @@
...
@@ -18,8 +18,8 @@
"name"
:
"End parameter"
,
"name"
:
"End parameter"
,
"position"
:
[
2
,
16
],
"position"
:
[
2
,
16
],
"size"
:
[
5
],
"size"
:
[
5
],
"start"
:
0
,
"start"
:
[
0
]
,
"end"
:
30
,
"end"
:
[
30
]
,
"expected"
:
[
0
,
3
],
"expected"
:
[
0
,
3
],
"expected_C"
:
6
"expected_C"
:
6
},
},
...
@@ -43,8 +43,8 @@
...
@@ -43,8 +43,8 @@
"position"
:
[[
0
,
0
],
[
11
,
9
],
[
2
,
8
],
[
2
,
2
],
[
8
,
3
],
[
1
,
1
],
[
6
,
6
]],
"position"
:
[[
0
,
0
],
[
11
,
9
],
[
2
,
8
],
[
2
,
2
],
[
8
,
3
],
[
1
,
1
],
[
6
,
6
]],
"size"
:
[
5
,
5
],
"size"
:
[
5
,
5
],
"batch"
:
[
0
,
0
,
0
,
0
,
0
,
1
,
1
],
"batch"
:
[
0
,
0
,
0
,
0
,
0
,
1
,
1
],
"start"
:
0
,
"start"
:
[
0
]
,
"end"
:
20
,
"end"
:
[
20
]
,
"expected"
:
[
0
,
9
,
1
,
0
,
4
,
16
,
21
],
"expected"
:
[
0
,
9
,
1
,
0
,
4
,
16
,
21
],
"expected_C"
:
32
"expected_C"
:
32
}
}
...
...
test/sparse_grid.json
View file @
74364643
...
@@ -9,7 +9,7 @@
...
@@ -9,7 +9,7 @@
"name"
:
"Start parameter"
,
"name"
:
"Start parameter"
,
"position"
:
[
2
,
6
],
"position"
:
[
2
,
6
],
"size"
:
[
5
],
"size"
:
[
5
],
"start"
:
0
,
"start"
:
[
0
]
,
"expected"
:
[
0
,
1
]
"expected"
:
[
0
,
1
]
},
},
{
{
...
...
test/test_dense_grid.py
View file @
74364643
...
@@ -20,7 +20,9 @@ def test_dense_grid_cluster_cpu(tensor, i):
...
@@ -20,7 +20,9 @@ def test_dense_grid_cluster_cpu(tensor, i):
batch
=
data
[
i
].
get
(
'batch'
)
batch
=
data
[
i
].
get
(
'batch'
)
batch
=
None
if
batch
is
None
else
torch
.
LongTensor
(
batch
)
batch
=
None
if
batch
is
None
else
torch
.
LongTensor
(
batch
)
start
=
data
[
i
].
get
(
'start'
)
start
=
data
[
i
].
get
(
'start'
)
start
=
None
if
start
is
None
else
torch
.
LongTensor
(
start
)
end
=
data
[
i
].
get
(
'end'
)
end
=
data
[
i
].
get
(
'end'
)
end
=
None
if
end
is
None
else
torch
.
LongTensor
(
end
)
expected
=
torch
.
LongTensor
(
data
[
i
][
'expected'
])
expected
=
torch
.
LongTensor
(
data
[
i
][
'expected'
])
expected_C
=
data
[
i
][
'expected_C'
]
expected_C
=
data
[
i
][
'expected_C'
]
...
@@ -37,7 +39,9 @@ def test_dense_grid_cluster_gpu(tensor, i): # pragma: no cover
...
@@ -37,7 +39,9 @@ def test_dense_grid_cluster_gpu(tensor, i): # pragma: no cover
batch
=
data
[
i
].
get
(
'batch'
)
batch
=
data
[
i
].
get
(
'batch'
)
batch
=
None
if
batch
is
None
else
torch
.
cuda
.
LongTensor
(
batch
)
batch
=
None
if
batch
is
None
else
torch
.
cuda
.
LongTensor
(
batch
)
start
=
data
[
i
].
get
(
'start'
)
start
=
data
[
i
].
get
(
'start'
)
start
=
None
if
start
is
None
else
torch
.
cuda
.
LongTensor
(
start
)
end
=
data
[
i
].
get
(
'end'
)
end
=
data
[
i
].
get
(
'end'
)
end
=
None
if
end
is
None
else
torch
.
cuda
.
LongTensor
(
end
)
expected
=
torch
.
LongTensor
(
data
[
i
][
'expected'
])
expected
=
torch
.
LongTensor
(
data
[
i
][
'expected'
])
expected_C
=
data
[
i
][
'expected_C'
]
expected_C
=
data
[
i
][
'expected_C'
]
...
...
test/test_sparse_grid.py
View file @
74364643
...
@@ -18,16 +18,17 @@ def test_sparse_grid_cluster_cpu(tensor, i):
...
@@ -18,16 +18,17 @@ def test_sparse_grid_cluster_cpu(tensor, i):
position
=
Tensor
(
tensor
,
data
[
i
][
'position'
])
position
=
Tensor
(
tensor
,
data
[
i
][
'position'
])
size
=
torch
.
LongTensor
(
data
[
i
][
'size'
])
size
=
torch
.
LongTensor
(
data
[
i
][
'size'
])
batch
=
data
[
i
].
get
(
'batch'
)
batch
=
data
[
i
].
get
(
'batch'
)
batch
=
None
if
batch
is
None
else
torch
.
LongTensor
(
batch
)
start
=
data
[
i
].
get
(
'start'
)
start
=
data
[
i
].
get
(
'start'
)
start
=
None
if
start
is
None
else
torch
.
LongTensor
(
start
)
expected
=
torch
.
LongTensor
(
data
[
i
][
'expected'
])
expected
=
torch
.
LongTensor
(
data
[
i
][
'expected'
])
if
batch
is
None
:
output
=
sparse_grid_cluster
(
position
,
size
,
batch
,
start
)
output
=
sparse_grid_cluster
(
position
,
size
,
batch
,
start
)
if
batch
is
None
:
assert
output
.
tolist
()
==
expected
.
tolist
()
assert
output
.
tolist
()
==
expected
.
tolist
()
else
:
else
:
batch
=
torch
.
LongTensor
(
batch
)
expected_batch
=
torch
.
LongTensor
(
data
[
i
][
'expected_batch'
])
expected_batch
=
torch
.
LongTensor
(
data
[
i
][
'expected_batch'
])
output
=
sparse_grid_cluster
(
position
,
size
,
batch
,
start
)
assert
output
[
0
].
tolist
()
==
expected
.
tolist
()
assert
output
[
0
].
tolist
()
==
expected
.
tolist
()
assert
output
[
1
].
tolist
()
==
expected_batch
.
tolist
()
assert
output
[
1
].
tolist
()
==
expected_batch
.
tolist
()
...
@@ -38,15 +39,16 @@ def test_sparse_grid_cluster_gpu(tensor, i): # pragma: no cover
...
@@ -38,15 +39,16 @@ def test_sparse_grid_cluster_gpu(tensor, i): # pragma: no cover
position
=
Tensor
(
tensor
,
data
[
i
][
'position'
]).
cuda
()
position
=
Tensor
(
tensor
,
data
[
i
][
'position'
]).
cuda
()
size
=
torch
.
cuda
.
LongTensor
(
data
[
i
][
'size'
])
size
=
torch
.
cuda
.
LongTensor
(
data
[
i
][
'size'
])
batch
=
data
[
i
].
get
(
'batch'
)
batch
=
data
[
i
].
get
(
'batch'
)
batch
=
None
if
batch
is
None
else
torch
.
cuda
.
LongTensor
(
batch
)
start
=
data
[
i
].
get
(
'start'
)
start
=
data
[
i
].
get
(
'start'
)
start
=
None
if
start
is
None
else
torch
.
cuda
.
LongTensor
(
start
)
expected
=
torch
.
LongTensor
(
data
[
i
][
'expected'
])
expected
=
torch
.
LongTensor
(
data
[
i
][
'expected'
])
if
batch
is
None
:
output
=
sparse_grid_cluster
(
position
,
size
,
batch
,
start
)
output
=
sparse_grid_cluster
(
position
,
size
,
batch
,
start
)
if
batch
is
None
:
assert
output
.
cpu
().
tolist
()
==
expected
.
tolist
()
assert
output
.
cpu
().
tolist
()
==
expected
.
tolist
()
else
:
else
:
batch
=
torch
.
cuda
.
LongTensor
(
batch
)
expected_batch
=
torch
.
LongTensor
(
data
[
i
][
'expected_batch'
])
expected_batch
=
torch
.
LongTensor
(
data
[
i
][
'expected_batch'
])
output
=
sparse_grid_cluster
(
position
,
size
,
batch
,
start
)
assert
output
[
0
].
cpu
().
tolist
()
==
expected
.
tolist
()
assert
output
[
0
].
cpu
().
tolist
()
==
expected
.
tolist
()
assert
output
[
1
].
cpu
().
tolist
()
==
expected_batch
.
tolist
()
assert
output
[
1
].
cpu
().
tolist
()
==
expected_batch
.
tolist
()
torch_cluster/__init__.py
View file @
74364643
from
.functions.grid
import
sparse_grid_cluster
,
dense_grid_cluster
from
.functions.grid
import
sparse_grid_cluster
,
dense_grid_cluster
__version__
=
'0.2.
4
'
__version__
=
'0.2.
5
'
__all__
=
[
'sparse_grid_cluster'
,
'dense_grid_cluster'
,
'__version__'
]
__all__
=
[
'sparse_grid_cluster'
,
'dense_grid_cluster'
,
'__version__'
]
torch_cluster/functions/grid.py
View file @
74364643
...
@@ -22,8 +22,8 @@ def _preprocess(position, size, batch=None, start=None):
...
@@ -22,8 +22,8 @@ def _preprocess(position, size, batch=None, start=None):
for
i
in
range
(
position
.
size
(
-
1
)):
for
i
in
range
(
position
.
size
(
-
1
)):
min
.
append
(
position
[:,
i
].
min
())
min
.
append
(
position
[:,
i
].
min
())
position
=
position
-
position
.
new
(
min
)
position
=
position
-
position
.
new
(
min
)
el
if
start
!=
0
:
el
se
:
position
=
position
-
start
position
=
position
-
start
.
type_as
(
position
)
# If given, append batch to position tensor.
# If given, append batch to position tensor.
if
batch
is
not
None
:
if
batch
is
not
None
:
...
@@ -49,6 +49,7 @@ def _fixed_cluster_size(position, size, batch=None, end=None):
...
@@ -49,6 +49,7 @@ def _fixed_cluster_size(position, size, batch=None, end=None):
if
end
is
None
:
if
end
is
None
:
return
_minimal_cluster_size
(
position
,
size
)
return
_minimal_cluster_size
(
position
,
size
)
end
=
end
.
type_as
(
size
)
eps
=
0.000001
# Simulate [start, end) interval.
eps
=
0.000001
# Simulate [start, end) interval.
if
batch
is
None
:
if
batch
is
None
:
cluster_size
=
((
end
/
size
).
float
()
-
eps
).
long
()
+
1
cluster_size
=
((
end
/
size
).
float
()
-
eps
).
long
()
+
1
...
...
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