MCPcopy Create free account
hub / github.com/apple/ml-pointersect / gather_points

Function gather_points

pointersect/pr/cpp/pr.cpp:160–197  ·  view source on GitHub ↗

Gather the points belonging to each grid cell. Args: grid_idxs: (b, n), grid index of each point total_cells: (b,) total grid cells valid_mask: (b, n), whether to record the point Returns: vector of idxmap, b -> (total_cells[bidx] -> n_idx of points in the cell)

Source from the content-addressed store, hash-verified

158// vector of idxmap, b -> (total_cells[bidx] -> n_idx of points in the cell)
159//
160std::vector<idxmap> gather_points(
161 // input
162 const torch::Tensor & grid_idxs, // (b, n), int64_t
163 const torch::Tensor & total_cells, // (b,) int64_t
164 const torch::Tensor & valid_mask // (b, n), bool
165 // // output
166 // std::vector<idxmap> & all_cell2pidx // b -> gidx -> pidx
167) {
168
169 assert(grid_idxs.dtype() == torch::kLong);
170 assert(total_cells.dtype() == torch::kLong);
171 assert(valid_mask.dtype() == torch::kBool);
172
173 auto batch_size = grid_idxs.size(0);
174 auto n_points = grid_idxs.size(1);
175
176 // accessor
177 auto a_grid_idxs = grid_idxs.accessor<int64_t, 2>();
178 auto a_total_cells = total_cells.accessor<int64_t, 1>();
179 auto a_valid_mask = valid_mask.accessor<bool, 2>();
180
181 std::vector<idxmap> all_cell2pidx;
182 all_cell2pidx.reserve(batch_size);
183
184 // loop through each batch element
185 for (auto b = 0; b < batch_size; ++b) {
186 all_cell2pidx.push_back(idxmap(a_total_cells[b]));
187 idxmap& cell2pidx = all_cell2pidx[b];
188
189 // loop through each point
190 for (auto i = 0; i < n_points; ++i) {
191 if (a_valid_mask[b][i]) {
192 cell2pidx.insert(a_grid_idxs[b][i], i);
193 }
194 }
195 }
196 return all_cell2pidx;
197}
198
199
200

Callers 1

Calls 4

idxmapClass · 0.85
dtypeMethod · 0.80
sizeMethod · 0.80
insertMethod · 0.80

Tested by

no test coverage detected