mirror of
https://github.com/facebookresearch/pytorch3d.git
synced 2025-12-20 22:30:35 +08:00
remove nearest_neighbors
Summary: knn is more general and faster than the nearest_neighbor code, so remove the latter. Reviewed By: gkioxari Differential Revision: D20816424 fbshipit-source-id: 75d6c44d17180752d0c9859814bbdf7892558158
This commit is contained in:
committed by
Facebook GitHub Bot
parent
790eb8c402
commit
3794f6753f
@@ -7,7 +7,6 @@
|
||||
#include "face_areas_normals/face_areas_normals.h"
|
||||
#include "gather_scatter/gather_scatter.h"
|
||||
#include "knn/knn.h"
|
||||
#include "nearest_neighbor_points/nearest_neighbor_points.h"
|
||||
#include "packed_to_padded_tensor/packed_to_padded_tensor.h"
|
||||
#include "point_mesh/point_mesh_edge.h"
|
||||
#include "point_mesh/point_mesh_face.h"
|
||||
@@ -21,7 +20,6 @@ PYBIND11_MODULE(TORCH_EXTENSION_NAME, m) {
|
||||
m.def("padded_to_packed", &PaddedToPacked);
|
||||
m.def("knn_points_idx", &KNearestNeighborIdx);
|
||||
m.def("knn_points_backward", &KNearestNeighborBackward);
|
||||
m.def("nn_points_idx", &NearestNeighborIdx);
|
||||
m.def("gather_scatter", &gather_scatter);
|
||||
m.def("rasterize_points", &RasterizePoints);
|
||||
m.def("rasterize_points_backward", &RasterizePointsBackward);
|
||||
|
||||
@@ -1,38 +0,0 @@
|
||||
// Copyright (c) Facebook, Inc. and its affiliates. All rights reserved.
|
||||
|
||||
#include <torch/extension.h>
|
||||
|
||||
at::Tensor NearestNeighborIdxCpu(at::Tensor p1, at::Tensor p2) {
|
||||
const int N = p1.size(0);
|
||||
const int P1 = p1.size(1);
|
||||
const int D = p1.size(2);
|
||||
const int P2 = p2.size(1);
|
||||
|
||||
auto long_opts = p1.options().dtype(torch::kInt64);
|
||||
torch::Tensor out = torch::empty({N, P1}, long_opts);
|
||||
|
||||
auto p1_a = p1.accessor<float, 3>();
|
||||
auto p2_a = p2.accessor<float, 3>();
|
||||
auto out_a = out.accessor<int64_t, 2>();
|
||||
|
||||
for (int n = 0; n < N; ++n) {
|
||||
for (int i1 = 0; i1 < P1; ++i1) {
|
||||
// TODO: support other floating-point types?
|
||||
float min_dist = -1;
|
||||
int64_t min_idx = -1;
|
||||
for (int i2 = 0; i2 < P2; ++i2) {
|
||||
float dist = 0;
|
||||
for (int d = 0; d < D; ++d) {
|
||||
float diff = p1_a[n][i1][d] - p2_a[n][i2][d];
|
||||
dist += diff * diff;
|
||||
}
|
||||
if (min_dist == -1 || dist < min_dist) {
|
||||
min_dist = dist;
|
||||
min_idx = i2;
|
||||
}
|
||||
}
|
||||
out_a[n][i1] = min_idx;
|
||||
}
|
||||
}
|
||||
return out;
|
||||
}
|
||||
Reference in New Issue
Block a user