10 #include "../TensorFlowHelper.h"
12 #include "tensorflow/core/framework/op.h"
13 #include "tensorflow/core/framework/op_kernel.h"
14 #include "tensorflow/core/lib/core/errors.h"
18 namespace knn_search_opkernel {
20 class KnnSearchOpKernel :
public tensorflow::OpKernel {
22 explicit KnnSearchOpKernel(tensorflow::OpKernelConstruction* construction)
23 : OpKernel(construction) {
25 using namespace tensorflow;
26 std::string metric_str;
27 OP_REQUIRES_OK(construction,
28 construction->GetAttr(
"metric", &metric_str));
29 if (metric_str ==
"L1")
34 OP_REQUIRES_OK(construction,
35 construction->GetAttr(
"ignore_query_point",
36 &ignore_query_point));
38 OP_REQUIRES_OK(construction, construction->GetAttr(
"return_distances",
42 void Compute(tensorflow::OpKernelContext*
context)
override {
43 using namespace tensorflow;
44 static_assert(
sizeof(int64) ==
sizeof(int64_t),
45 "int64 type is not compatible");
48 const Tensor& queries =
context->input(1);
49 const Tensor& k_tensor =
context->input(2);
50 const TensorShape k_shape(k_tensor.shape());
51 OP_REQUIRES(
context, k_shape.dims() == 0,
52 errors::InvalidArgument(
"k must be a rank 0 tensor"));
53 const int k = k_tensor.scalar<
int32_t>()();
54 const Tensor& points_row_splits =
context->input(3);
55 const Tensor& queries_row_splits =
context->input(4);
59 Dim num_points(
"num_points");
60 Dim num_queries(
"num_queries");
61 Dim batch_size(
"batch_size");
68 Tensor* query_neighbors_row_splits = 0;
69 TensorShape query_neighbors_row_splits_shape(
70 {queries.shape().dim_size(0) + 1});
72 1, query_neighbors_row_splits_shape,
73 &query_neighbors_row_splits));
76 queries_row_splits, *query_neighbors_row_splits);
79 virtual void Kernel(tensorflow::OpKernelContext*
context,
80 const tensorflow::Tensor&
points,
81 const tensorflow::Tensor& queries,
83 const tensorflow::Tensor& points_row_splits,
84 const tensorflow::Tensor& queries_row_splits,
85 tensorflow::Tensor& query_neighbors_row_splits) = 0;
89 bool ignore_query_point;
90 bool return_distances;
#define CHECK_SHAPE(tensor,...)
Definition: TorchHelper.h:186
ImGuiContext * context
Definition: Window.cpp:76
Class for dimensions for which the value should be inferred.
Definition: ShapeChecking.h:50
Definition: FixedRadiusIndex.cpp:16
Metric
Supported metrics.
Definition: NeighborSearchCommon.h:19
@ L1
Definition: NeighborSearchCommon.h:19
@ L2
Definition: NeighborSearchCommon.h:19
const char const char value recording_handle imu_sample recording_handle uint8_t size_t data_size k4a_record_configuration_t config target_format k4a_capture_t capture_handle k4a_imu_sample_t imu_sample playback_handle k4a_logging_message_cb_t void min_level device_handle k4a_imu_sample_t int32_t
Definition: K4aPlugin.cpp:395
Definition: ShapeChecking.h:16