22 tensorflow::OpKernelConstruction* construction)
23 : OpKernel(construction) {
24 using namespace tensorflow;
26 OP_REQUIRES_OK(construction,
28 OP_REQUIRES_OK(construction,
29 construction->GetAttr(
"normalize", &
normalize));
31 std::string interpolation_str;
32 OP_REQUIRES_OK(construction, construction->GetAttr(
"interpolation",
35 if (interpolation_str ==
"linear")
37 else if (interpolation_str ==
"linear_border")
42 std::string mapping_str;
43 OP_REQUIRES_OK(construction, construction->GetAttr(
"coordinate_mapping",
46 if (mapping_str ==
"ball_to_cube_radial")
48 else if (mapping_str ==
"ball_to_cube_volume_preserving")
50 CoordinateMapping::BALL_TO_CUBE_VOLUME_PRESERVING;
54 OP_REQUIRES_OK(construction, construction->GetAttr(
"max_temp_mem_MB",
59 using namespace tensorflow;
60 static_assert(
sizeof(int64_t) ==
sizeof(int64_t),
61 "int64_t type is not compatible");
62 const Tensor& filter =
context->input(0);
64 const Tensor& out_positions =
context->input(1);
66 out_positions.shape().dim_size(0) <=
67 std::numeric_limits<TIndex>::max(),
68 absl::InvalidArgumentError(
"Too many output points"));
70 const Tensor& out_importance =
context->input(2);
73 out_importance.shape().dim_size(0) == 0 ||
74 out_importance.shape().dim_size(0) ==
75 out_positions.shape().dim_size(0),
76 absl::InvalidArgumentError(
"length of out_importance must "
77 "match the number of output points "
80 const Tensor& extents =
context->input(3);
85 absl::InvalidArgumentError(
"offset must be a rank 1 tensor"));
87 absl::InvalidArgumentError(
"offset length must be 3"));
89 const Tensor& inp_positions =
context->input(5);
91 inp_positions.shape().dim_size(0) <=
92 std::numeric_limits<TIndex>::max(),
93 absl::InvalidArgumentError(
"Too many input points"));
95 const Tensor& inp_features =
context->input(6);
100 const Tensor& inp_neighbors_importance_sum =
context->input(8);
102 const Tensor& inp_neighbors_row_splits =
context->input(9);
104 const Tensor& neighbors_index =
context->input(10);
106 const Tensor& neighbors_importance =
context->input(11);
108 const Tensor& neighbors_row_splits =
context->input(12);
111 context, extents.shape().dims() == 2,
112 absl::InvalidArgumentError(
"extents must be a rank 2 tensor"));
115 extents.shape().dim_size(0) ==
116 inp_positions.shape().dim_size(0) ||
117 extents.shape().dim_size(0) == 1,
118 absl::InvalidArgumentError(
"number of extents must match the "
119 "number of inp_positions or must "
122 extents.shape().dim_size(1) == 3 ||
123 extents.shape().dim_size(1) == 1,
124 absl::InvalidArgumentError(
125 "number of components for extents must be 3 or 1"));
128 inp_positions.shape().dim_size(0) ==
129 inp_features.shape().dim_size(0),
130 absl::InvalidArgumentError(
131 "first dim of inp_positions does not "
132 "match the first dim of inp_features"));
136 inp_neighbors_importance_sum.shape().dim_size(0) ==
137 inp_positions.shape().dim_size(0) ||
138 inp_neighbors_importance_sum.shape().dim_size(0) == 0,
139 absl::InvalidArgumentError(
140 "first dim of inp_neighbors_importance_sum does not "
141 "match the first dim of inp_positions"));
145 out_positions.shape().dim_size(0) ==
146 out_importance.shape().dim_size(0) ||
147 out_importance.shape().dim_size(0) == 0,
148 absl::InvalidArgumentError(
"first dim of out_positions does "
149 "not match the first dim of "
154 neighbors_importance.shape().dim_size(0) ==
155 neighbors_index.shape().dim_size(0) ||
156 neighbors_importance.shape().dim_size(0) == 0,
157 absl::InvalidArgumentError(
"first dim of neighbors_importance "
158 "does not match the first dim of "
163 filter.shape().dim_size(3) == inp_features.shape().dim_size(1),
164 absl::InvalidArgumentError(
"number of input channels in filter "
165 "and inp_features does not match"));
167 TensorShape out_features_shape({out_positions.shape().dim_size(0),
168 filter.shape().dim_size(4)});
169 Tensor* out_features =
nullptr;
170 OP_REQUIRES_OK(
context,
context->allocate_output(0, out_features_shape,
173 std::vector<int> filter_dims({
174 int(filter.shape().dim_size(0)),
175 int(filter.shape().dim_size(1)),
176 int(filter.shape().dim_size(2)),
177 int(filter.shape().dim_size(3)),
178 int(filter.shape().dim_size(4)),
181 bool individual_extents = extents.shape().dim_size(0) ==
182 out_positions.shape().dim_size(0) &&
183 extents.shape().dim_size(0) > 1;
185 bool isotropic_extents = extents.shape().dim_size(1) == 1;
187 bool point_importances = out_importance.shape().dim_size(0) != 0;
189 bool has_neighbors_importances =
190 neighbors_importance.shape().dim_size(0) != 0;
193 inp_positions, inp_features, inp_neighbors_importance_sum,
194 inp_neighbors_row_splits, neighbors_index, neighbors_importance,
195 neighbors_row_splits, filter_dims, individual_extents,
196 isotropic_extents, point_importances, has_neighbors_importances,