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& extents =
context->input(2);
72 context, extents.shape().dims() == 2,
73 absl::InvalidArgumentError(
"extents must be a rank 2 tensor"));
76 extents.shape().dim_size(0) ==
77 out_positions.shape().dim_size(0) ||
78 extents.shape().dim_size(0) == 1,
79 absl::InvalidArgumentError(
"number of extents must match the "
80 "number of out_positions or must "
83 extents.shape().dim_size(1) == 3 ||
84 extents.shape().dim_size(1) == 1,
85 absl::InvalidArgumentError(
86 "number of components for extents must be 3 or 1"));
91 absl::InvalidArgumentError(
"offset must be a rank 1 tensor"));
93 absl::InvalidArgumentError(
"offset length must be 3"));
95 const Tensor& inp_positions =
context->input(4);
97 inp_positions.shape().dim_size(0) <=
98 std::numeric_limits<TIndex>::max(),
99 absl::InvalidArgumentError(
"Too many input points"));
101 const Tensor& inp_features =
context->input(5);
103 const Tensor& inp_importance =
context->input(6);
105 const Tensor& neighbors_index =
context->input(7);
107 const Tensor& neighbors_importance =
context->input(8);
109 const Tensor& neighbors_row_splits =
context->input(9);
111 const Tensor& out_features_gradient =
context->input(10);
114 inp_positions.shape().dim_size(0) ==
115 inp_features.shape().dim_size(0),
116 absl::InvalidArgumentError(
117 "first dim of inp_positions does not "
118 "match the first dim of inp_features"));
122 inp_positions.shape().dim_size(0) ==
123 inp_importance.shape().dim_size(0) ||
124 inp_importance.shape().dim_size(0) == 0,
125 absl::InvalidArgumentError(
"first dim of inp_positions does "
126 "not match the first dim of "
131 neighbors_importance.shape().dim_size(0) ==
132 neighbors_index.shape().dim_size(0) ||
133 neighbors_importance.shape().dim_size(0) == 0,
134 absl::InvalidArgumentError(
"first dim of neighbors_importance "
135 "does not match the first dim of "
140 filter.shape().dim_size(3) == inp_features.shape().dim_size(1),
141 absl::InvalidArgumentError(
"number of input channels in filter "
142 "and inp_features does not match"));
145 out_features_gradient.shape().dim_size(0) ==
146 out_positions.shape().dim_size(0),
147 absl::InvalidArgumentError(
148 std::string(
"first dim of out_positions, does "
149 "not match the first dim of "
150 "out_features_gradient")));
152 TensorShape filter_backprop_shape(filter.shape());
153 Tensor* filter_backprop =
nullptr;
155 context->allocate_output(0, filter_backprop_shape,
158 std::vector<int> filter_dims({
159 int(filter.shape().dim_size(0)),
160 int(filter.shape().dim_size(1)),
161 int(filter.shape().dim_size(2)),
162 int(filter.shape().dim_size(3)),
163 int(filter.shape().dim_size(4)),
166 bool individual_extents = extents.shape().dim_size(0) ==
167 out_positions.shape().dim_size(0) &&
168 extents.shape().dim_size(0) > 1;
170 bool isotropic_extents = extents.shape().dim_size(1) == 1;
172 bool point_importances = inp_importance.shape().dim_size(0) != 0;
174 bool has_neighbors_importances =
175 neighbors_importance.shape().dim_size(0) != 0;
178 inp_features, inp_importance, neighbors_index,
179 neighbors_importance, neighbors_row_splits,
180 out_features_gradient, filter_dims, individual_extents,
181 isotropic_extents, point_importances, has_neighbors_importances,