31 using namespace tensorflow;
35 const Tensor& radius =
context->input(1);
36 OP_REQUIRES(
context, TensorShapeUtils::IsScalar(radius.shape()),
37 absl::InvalidArgumentError(
38 std::string(
"radius must be scalar, got shape ") +
39 radius.shape().DebugString()));
41 const Tensor& points_row_splits =
context->input(2);
43 const Tensor& hash_table_size_factor_tensor =
context->input(3);
46 TensorShapeUtils::IsScalar(
47 hash_table_size_factor_tensor.shape()),
48 absl::InvalidArgumentError(
49 std::string(
"hash_table_size_factor must be scalar, "
51 hash_table_size_factor_tensor.shape().DebugString()));
52 const double hash_table_size_factor =
53 hash_table_size_factor_tensor.scalar<
double>()();
55 Dim num_points(
"num_points");
56 Dim batch_size(
"batch_size");
60 std::vector<uint32_t> hash_table_splits(batch_size.
value() + 1, 0);
61 for (
int i = 0; i < batch_size.
value(); ++i) {
62 int64_t num_points_i = points_row_splits.flat<int64_t>()(i + 1) -
63 points_row_splits.flat<int64_t>()(i);
65 int64_t hash_table_size = std::min<int64_t>(
66 std::max<int64_t>(hash_table_size_factor * num_points_i, 1),
68 hash_table_splits[i + 1] = hash_table_splits[i] + hash_table_size;
71 Tensor* hash_table_index = 0;
72 TensorShape hash_table_index_shape({num_points.
value()});
74 context->allocate_output(0, hash_table_index_shape,
77 Tensor* hash_table_cell_splits = 0;
78 TensorShape hash_table_cell_splits_shape(
79 {hash_table_splits.back() + 1});
81 context->allocate_output(1, hash_table_cell_splits_shape,
82 &hash_table_cell_splits));
84 Tensor* out_hash_table_splits = 0;
85 TensorShape out_hash_table_splits_shape({batch_size.
value() + 1});
87 context->allocate_output(2, out_hash_table_splits_shape,
88 &out_hash_table_splits));
89 for (
size_t i = 0; i < hash_table_splits.size(); ++i) {
90 out_hash_table_splits->flat<uint32_t>()(i) = hash_table_splits[i];
94 *hash_table_index, *hash_table_cell_splits);