33 const Dtype& index_dtype) {
34 int64_t num_dataset_points = dataset_points.
GetShape(0);
35 Tensor points_row_splits = Tensor::Init<int64_t>({0, num_dataset_points});
36 return SetTensorData(dataset_points, points_row_splits, index_dtype);
40 const Tensor& points_row_splits,
41 const Dtype& index_dtype) {
43 assert(index_dtype ==
Int32 || index_dtype ==
Int64);
47 if (dataset_points.
NumDims() != 2) {
49 "dataset_points must be 2D matrix with shape "
50 "{n_dataset_points, d}.");
55 if (dataset_points.
GetShape(0) != points_row_splits[-1].
Item<int64_t>()) {
57 "dataset_points and points_row_splits have incompatible "
61 if (dataset_points.
IsCUDA()) {
62 #ifdef BUILD_CUDA_MODULE
69 "GPU Tensor is not supported when -DBUILD_CUDA_MODULE=OFF. "
70 "Please recompile Open3d With -DBUILD_CUDA_MODULE=ON.");
74 "CPU Tensor is not supported in KnnIndex. Please use "
75 "NanoFlannIndex instead.");
82 int64_t num_query_points = query_points.
GetShape(0);
83 Tensor queries_row_splits = Tensor::Init<int64_t>({0, num_query_points});
84 return SearchKnn(query_points, queries_row_splits, knn);
88 const Tensor& queries_row_splits,
100 if (query_points.
GetShape(0) != queries_row_splits[-1].
Item<int64_t>()) {
102 "query_points and queries_row_splits have incompatible "
112 Tensor neighbors_index, neighbors_distance;
113 Tensor neighbors_row_splits =
116 #define KNN_PARAMETERS \
117 dataset_points_, points_row_splits_, query_points_, queries_row_splits_, \
118 knn, neighbors_index, neighbors_row_splits, neighbors_distance
121 #ifdef BUILD_CUDA_MODULE
128 "-DBUILD_CUDA_MODULE=OFF. Please compile Open3d with "
129 "-DBUILD_CUDA_MODULE=ON.");
133 "-DBUILD_CUDA_MODULE=OFF. Please compile Open3d with "
134 "-DBUILD_CUDA_MODULE=ON.");
#define DISPATCH_FLOAT_INT_DTYPE_TO_TEMPLATE(FDTYPE, IDTYPE,...)
#define AssertTensorDevice(tensor,...)
#define AssertTensorDtype(tensor,...)
#define AssertTensorDtypes(tensor,...)
#define AssertTensorShape(tensor,...)
bool IsCUDA() const
Returns true iff device type is CUDA.
Tensor Contiguous() const
static Tensor Empty(const SizeVector &shape, Dtype dtype, const Device &device=Device("CPU:0"))
Create a tensor with uninitialized values.
SizeVector GetShape() const
bool SetTensorData(const Tensor &dataset_points, const Dtype &index_dtype=core::Int64) override
Tensor points_row_splits_
std::pair< Tensor, Tensor > SearchKnn(const Tensor &query_points, int knn) const override
Dtype GetIndexDtype() const
CLOUDVIEWER_HOST_DEVICE Pair< First, Second > make_pair(const First &_first, const Second &_second)
constexpr nullopt_t nullopt
Generic file read and write utility for python interface.