Commit 6b75d236 authored by rusty1s's avatar rusty1s
Browse files

grid cpu

parent 878e1193
...@@ -2,18 +2,17 @@ ...@@ -2,18 +2,17 @@
at::Tensor grid(at::Tensor pos, at::Tensor size, at::Tensor start, at::Tensor grid(at::Tensor pos, at::Tensor size, at::Tensor start,
at::Tensor end) { at::Tensor end) {
size = size.toType(pos.type());
start = start.toType(pos.type());
end = end.toType(pos.type());
pos = pos - start.view({1, -1}); pos = pos - start.view({1, -1});
auto num_voxels = ((end - start) / size).toType(at::kLong);
num_voxels = (num_voxels + 1).cumsum(0);
num_voxels -= num_voxels.data<int64_t>()[0];
num_voxels.data<int64_t>()[0] = 1;
auto cluster = pos / size.view({1, -1}); auto num_voxels = ((end - start) / size).toType(at::kLong) + 1;
cluster = cluster.toType(at::kLong); num_voxels = num_voxels.cumprod(0);
num_voxels = at::cat({at::ones(1, num_voxels.options()), num_voxels}, 0);
auto index = empty(size.size(0), num_voxels.options());
arange_out(index, size.size(0));
num_voxels = num_voxels.index_select(0, index);
auto cluster = (pos / size.view({1, -1})).toType(at::kLong);
cluster *= num_voxels.view({1, -1}); cluster *= num_voxels.view({1, -1});
cluster = cluster.sum(1); cluster = cluster.sum(1);
......
...@@ -5,4 +5,4 @@ description-file = README.md ...@@ -5,4 +5,4 @@ description-file = README.md
test = pytest test = pytest
[tool:pytest] [tool:pytest]
addopts = --capture=no --cov addopts = --capture=no
...@@ -28,9 +28,7 @@ def grid_cluster(pos, size, start=None, end=None): ...@@ -28,9 +28,7 @@ def grid_cluster(pos, size, start=None, end=None):
start = pos.t().min(dim=1)[0] if start is None else start start = pos.t().min(dim=1)[0] if start is None else start
end = pos.t().max(dim=1)[0] if end is None else end end = pos.t().max(dim=1)[0] if end is None else end
if pos.is_cuda: op = grid_cuda.grid if pos.is_cuda else grid_cpu.grid
cluster = grid_cuda.grid(pos, size, start, end) cluster = op(pos, size, start, end)
else:
cluster = grid_cpu.grid(pos, size, start, end)
return cluster return cluster
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment